Add IO generator and CI checks

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-02-08 13:30:18 +05:30
parent 870f44bc9b
commit 57f7d3e6d9
9 changed files with 148 additions and 33 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@main
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"

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" "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": { "@redhat-actions/eslint-config": {
"version": "1.2.11", "version": "1.2.11",
"resolved": "https://registry.npmjs.org/@redhat-actions/eslint-config/-/eslint-config-1.2.11.tgz", "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" "@actions/io": "^1.0.2"
}, },
"devDependencies": { "devDependencies": {
"@redhat-actions/action-io-generator": "^1.5.0",
"@redhat-actions/eslint-config": "^1.2.11", "@redhat-actions/eslint-config": "^1.2.11",
"@redhat-actions/tsconfig": "^1.1.0", "@redhat-actions/tsconfig": "^1.1.0",
"@types/node": "^12.12.7", "@types/node": "^12.12.7",

View file

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