Add IO generator and CI checks (#21)

* Add IO generator and CI checks
* Update Buildah build action to use v2 tag

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
Divyanshu Agrawal 2021-02-09 00:00:15 +05:30 committed by GitHub
parent 870f44bc9b
commit 4757eb3399
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 160 additions and 35 deletions

48
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,48 @@
name: CI checks
on:
push:
pull_request:
jobs:
lint:
name: Run ESLint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm run lint
check-dist:
name: Check Distribution
runs-on: ubuntu-20.04
env:
BUNDLE_FILE: "dist/index.js"
BUNDLE_COMMAND: "npm run bundle"
steps:
- uses: actions/checkout@v2
- name: Install
run: npm ci
- name: Verify Latest Bundle
uses: redhat-actions/common/bundle-verifier@v1
with:
bundle_file: ${{ env.BUNDLE_FILE }}
bundle_command: ${{ env.BUNDLE_COMMAND }}
check-inputs-outputs:
name: Check Input and Output enums
runs-on: ubuntu-20.04
env:
IO_FILE: ./src/generated/inputs-outputs.ts
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm ci
- name: Verify Input and Output enums
uses: redhat-actions/common/action-io-generator@v1
with:
io_file: ${{ env.IO_FILE }}

View file

@ -1,22 +0,0 @@
name: Verify Bundle
on: [ push, pull_request ]
jobs:
verify-bundle:
name: Verify Distribution Bundle
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: npm ci
- name: Check Distribution
uses: tetchel/bundle-verifier-action@v0.0.2
with:
bundle_file: dist/index.js
bundle_command: "npm run bundle"

View file

@ -67,7 +67,7 @@ jobs:
# Build image using Buildah action
- name: Build Image
id: build_image
uses: redhat-actions/buildah-build@main
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: ${{ env.IMAGE_TAGS }}

View file

@ -1,6 +1,9 @@
# push-to-registry
[![Verify Bundle](https://github.com/redhat-actions/push-to-registry/workflows/Verify%20Bundle/badge.svg)](https://github.com/redhat-actions/push-to-registry/actions?query=workflow%3A%22Verify+Bundle%22)
[![CI checks](https://github.com/redhat-actions/push-to-registry/workflows/CI%20checks/badge.svg)](https://github.com/redhat-actions/push-to-registry/actions?query=workflow%3A%22CI+checks%22)
[![Test Build and Push](https://github.com/redhat-actions/push-to-registry/workflows/Test%20Build%20and%20Push/badge.svg)](https://github.com/redhat-actions/push-to-registry/actions?query=workflow%3A%22Test+Build+and+Push%22)
[![Multiple container CLI build tests](https://github.com/redhat-actions/push-to-registry/workflows/Multiple%20container%20CLI%20build%20tests/badge.svg)](https://github.com/redhat-actions/push-to-registry/actions?query=workflow%3A%22Multiple+container+CLI+build+tests%22)
<br><br>
[![tag badge](https://img.shields.io/github/v/tag/redhat-actions/push-to-registry)](https://github.com/redhat-actions/push-to-registry/tags)
[![license badge](https://img.shields.io/github/license/redhat-actions/push-to-registry)](./LICENSE)
[![size badge](https://img.shields.io/github/size/redhat-actions/push-to-registry/dist/index.js)](./dist)

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

15
git-hooks/pre-commit Normal file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
### Copy this into .git/hooks and overwrite the empty one.
### This will ensure the bundle and ins-outs verification checks won't fail for you.
echo "----- Pre-commit -----"
set -ex
npx action-io-generator -o src/generated/inputs-outputs.ts
npm run lint
npm run bundle
git add -v dist/ src/generated
set +x
echo "Success"

10
package-lock.json generated
View file

@ -113,6 +113,16 @@
"fastq": "^1.6.0"
}
},
"@redhat-actions/action-io-generator": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@redhat-actions/action-io-generator/-/action-io-generator-1.5.0.tgz",
"integrity": "sha512-zaBZyP0ev5c36j0h8EyvqbD+fhUjDOeme2qzVa+CSWjeGVAsgdZREzE8smE3QA6xXpMHPU5keT+q2iN8/hq5uA==",
"dev": true,
"requires": {
"js-yaml": "^3.14.1",
"minimist": "^1.2.5"
}
},
"@redhat-actions/eslint-config": {
"version": "1.2.11",
"resolved": "https://registry.npmjs.org/@redhat-actions/eslint-config/-/eslint-config-1.2.11.tgz",

View file

@ -18,6 +18,7 @@
"@actions/io": "^1.0.2"
},
"devDependencies": {
"@redhat-actions/action-io-generator": "^1.5.0",
"@redhat-actions/eslint-config": "^1.2.11",
"@redhat-actions/tsconfig": "^1.1.0",
"@types/node": "^12.12.7",

View file

@ -0,0 +1,69 @@
// This file was auto-generated by action-io-generator. Do not edit by hand!
export enum Inputs {
/**
* After copying the image, write the digest of the resulting image to the file.
* By default, the filename will be determined from the image and tag.
* The contents of this file are the digest output.
* Required: false
* Default: None.
*/
DIGESTFILE = "digestfile",
/**
* Extra args to be passed to podman push.
* Separate arguments by newline. Do not use quotes - @actions/exec will do the quoting for you.
* Required: false
* Default: None.
*/
EXTRA_ARGS = "extra-args",
/**
* Name of the image to push
* Required: true
* Default: None.
*/
IMAGE = "image",
/**
* Password to use as credential to authenticate to the registry
* Required: true
* Default: None.
*/
PASSWORD = "password",
/**
* Registry where to push the image (eg. quay.io/username)
* Required: true
* Default: None.
*/
REGISTRY = "registry",
/**
* The tag or tags of the image to push. For multiple tags, seperate by a space. For example, "latest v1"
* Required: false
* Default: "latest"
*/
TAGS = "tags",
/**
* Verify TLS certificates when contacting the registry
* Required: false
* Default: "true"
*/
TLS_VERIFY = "tls-verify",
/**
* Username to use as credential to authenticate to the registry
* Required: true
* Default: None.
*/
USERNAME = "username",
}
export enum Outputs {
/**
* The pushed image digest, as written to the "digestfile"
* Required: false
* Default: None.
*/
DIGEST = "digest",
/**
* A JSON array of registry paths to which the tag(s) were pushed
* Required: false
* Default: None.
*/
REGISTRY_PATHS = "registry-paths",
}

View file

@ -4,6 +4,7 @@ import * as io from "@actions/io";
import * as fs from "fs";
import * as path from "path";
import { splitByNewline } from "./util";
import { Inputs, Outputs } from "./generated/inputs-outputs";
interface ExecResult {
exitCode: number;
@ -35,15 +36,15 @@ async function getPodmanPath(): Promise<string> {
const dockerBaseUrl = "docker.io/library";
async function run(): Promise<void> {
const imageInput = core.getInput("image", { required: true });
const tags = core.getInput("tags") || "latest";
const imageInput = core.getInput(Inputs.IMAGE, { required: true });
const tags = core.getInput(Inputs.TAGS) || "latest";
// split tags
tagsList = tags.split(" ");
const registry = core.getInput("registry", { required: true });
const username = core.getInput("username", { required: true });
const password = core.getInput("password", { required: true });
const tlsVerify = core.getInput("tls-verify");
const digestFileInput = core.getInput("digestfile");
const registry = core.getInput(Inputs.REGISTRY, { required: true });
const username = core.getInput(Inputs.USERNAME, { required: true });
const password = core.getInput(Inputs.PASSWORD, { required: true });
const tlsVerify = core.getInput(Inputs.TLS_VERIFY);
const digestFileInput = core.getInput(Inputs.DIGESTFILE);
const inputExtraArgsStr = core.getInput("extra-args");
let podmanExtraArgs: string[] = [];
@ -187,13 +188,13 @@ async function run(): Promise<void> {
try {
const digest = (await fs.promises.readFile(digestFile)).toString();
core.info(digest);
core.setOutput("digest", digest);
core.setOutput(Outputs.DIGEST, digest);
}
catch (err) {
core.warning(`Failed to read digest file "${digestFile}": ${err}`);
}
core.setOutput("registry-paths", JSON.stringify(registryPathList));
core.setOutput(Outputs.REGISTRY_PATHS, JSON.stringify(registryPathList));
}
async function pullImageFromDocker(): Promise<ImageStorageCheckResult> {