Add IO generator and CI checks

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-02-08 11:35:57 +05:30
parent 46cc120d66
commit f6079a53f7
9 changed files with 188 additions and 34 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,18 +0,0 @@
name: Verify Bundle
on: [ push, pull_request ]
jobs:
verify-bundle:
name: Verify Distribution Bundle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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

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

@ -0,0 +1,10 @@
#!/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 bundle
git add -v dist/ src/generated

22
package-lock.json generated
View file

@ -128,6 +128,28 @@
"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"
},
"dependencies": {
"js-yaml": {
"version": "3.14.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
"integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
}
}
},
"@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

@ -26,6 +26,7 @@
"language-recognizer": "0.0.1" "language-recognizer": "0.0.1"
}, },
"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.1", "@redhat-actions/tsconfig": "^1.1.1",
"@types/node": "^12", "@types/node": "^12",

View file

@ -0,0 +1,90 @@
// This file was auto-generated by action-io-generator. Do not edit by hand!
export enum Inputs {
/**
* The base image to use to create a new container image
* Required: true
* Default: None.
*/
BASE_IMAGE = "base-image",
/**
* List of --build-args to pass to buildah
* Required: false
* Default: None.
*/
BUILD_ARGS = "build-args",
/**
* List of files/directories to copy inside the base image
* Required: false
* Default: None.
*/
CONTENT = "content",
/**
* Path of the directory to use as context (default: .)
* Required: false
* Default: "."
*/
CONTEXT = "context",
/**
* List of Dockerfile paths (eg: ./Dockerfile)
* Required: false
* Default: None.
*/
DOCKERFILES = "dockerfiles",
/**
* The entry point to set for containers based on image
* Required: false
* Default: None.
*/
ENTRYPOINT = "entrypoint",
/**
* List of environment variables to be set when running containers based on image
* Required: false
* Default: None.
*/
ENVS = "envs",
/**
* The name (reference) of the image to build
* Required: true
* Default: None.
*/
IMAGE = "image",
/**
* Set to true to build using the OCI image format instead of the Docker image format
* Required: false
* Default: "false"
*/
OCI = "oci",
/**
* The port to expose when running containers based on image
* Required: false
* Default: None.
*/
PORT = "port",
/**
* The tags of the image to build. For multiple tags, seperate by a space. For example, "latest v1".
* Required: false
* Default: "latest"
*/
TAGS = "tags",
/**
* The working directory to use within the container
* Required: false
* Default: None.
*/
WORKDIR = "workdir",
}
export enum Outputs {
/**
* Name of the image built
* Required: false
* Default: None.
*/
IMAGE = "image",
/**
* List of the tags that were created, separated by spaces
* Required: false
* Default: None.
*/
TAGS = "tags",
}

View file

@ -1,6 +1,7 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as io from "@actions/io"; import * as io from "@actions/io";
import * as path from "path"; import * as path from "path";
import { Inputs, Outputs } from "./generated/inputs-outputs";
import { BuildahCli, BuildahConfigSettings } from "./buildah"; import { BuildahCli, BuildahConfigSettings } from "./buildah";
export async function run(): Promise<void> { export async function run(): Promise<void> {
@ -13,12 +14,12 @@ export async function run(): Promise<void> {
const cli: BuildahCli = new BuildahCli(buildahPath); const cli: BuildahCli = new BuildahCli(buildahPath);
const workspace = process.env.GITHUB_WORKSPACE || process.cwd(); const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
const dockerFiles = getInputList("dockerfiles"); const dockerFiles = getInputList(Inputs.DOCKERFILES);
const image = core.getInput("image", { required: true }); const image = core.getInput(Inputs.IMAGE, { required: true });
const tags = core.getInput("tags") || "latest"; const tags = core.getInput(Inputs.TAGS) || "latest";
const tagsList: string[] = tags.split(" "); const tagsList: string[] = tags.split(" ");
const newImage = `${image}:${tagsList[0]}`; const newImage = `${image}:${tagsList[0]}`;
const useOCI = core.getInput("oci") === "true"; const useOCI = core.getInput(Inputs.OCI) === "true";
if (dockerFiles.length !== 0) { if (dockerFiles.length !== 0) {
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI); await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
@ -30,8 +31,8 @@ export async function run(): Promise<void> {
if (tagsList.length > 1) { if (tagsList.length > 1) {
await cli.tag(image, tagsList); await cli.tag(image, tagsList);
} }
core.setOutput("image", image); core.setOutput(Outputs.IMAGE, image);
core.setOutput("tags", tags); core.setOutput(Outputs.TAGS, tags);
} }
async function doBuildUsingDockerFiles( async function doBuildUsingDockerFiles(
@ -44,8 +45,8 @@ async function doBuildUsingDockerFiles(
core.info(`Performing build from ${dockerFiles.length} Dockerfiles`); core.info(`Performing build from ${dockerFiles.length} Dockerfiles`);
} }
const context = path.join(workspace, core.getInput("context")); const context = path.join(workspace, core.getInput(Inputs.CONTEXT));
const buildArgs = getInputList("build-args"); const buildArgs = getInputList(Inputs.BUILD_ARGS);
const dockerFileAbsPaths = dockerFiles.map((file) => path.join(workspace, file)); const dockerFileAbsPaths = dockerFiles.map((file) => path.join(workspace, file));
await cli.buildUsingDocker(newImage, context, dockerFileAbsPaths, buildArgs, useOCI); await cli.buildUsingDocker(newImage, context, dockerFileAbsPaths, buildArgs, useOCI);
} }
@ -55,12 +56,12 @@ async function doBuildFromScratch(
): Promise<void> { ): Promise<void> {
core.info(`Performing build from scratch`); core.info(`Performing build from scratch`);
const baseImage = core.getInput("base-image", { required: true }); const baseImage = core.getInput(Inputs.BASE_IMAGE, { required: true });
const content = getInputList("content"); const content = getInputList(Inputs.CONTENT);
const entrypoint = getInputList("entrypoint"); const entrypoint = getInputList(Inputs.ENTRYPOINT);
const port = core.getInput("port"); const port = core.getInput(Inputs.PORT);
const workingDir = core.getInput("workdir"); const workingDir = core.getInput(Inputs.WORKDIR);
const envs = getInputList("envs"); const envs = getInputList(Inputs.ENVS);
const container = await cli.from(baseImage); const container = await cli.from(baseImage);
const containerId = container.output.replace("\n", ""); const containerId = container.output.replace("\n", "");