Skip to content

Commit

Permalink
Add verify bundle action and make inputs 'required'
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Etchells <[email protected]>
  • Loading branch information
tetchel committed Nov 17, 2020
1 parent 05f033c commit 6109531
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 18 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/verify-bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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/[email protected]
with:
bundle_file: dist/index.js
bundle_command: "npm run bundle"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 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)
[![tag badge](https://img.shields.io/github/v/tag/redhat-actions/push-to-registry?sort=semver)](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)
Expand All @@ -18,7 +19,7 @@ Push-to-registry is a GitHub Action for pushing an OCI-compatible image to an im
</thead>

<tr>
<td>image-to-push</td>
<td>image</td>
<td>Yes</td>
<td>
Name of the image you want to push. Most likely the name you used to create the image in the previous step.
Expand Down Expand Up @@ -92,7 +93,7 @@ jobs:
- name: Push To Quay
uses: redhat-actions/[email protected]
with:
image-to-push: ${{ env.IMAGE_NAME }}
image: ${{ env.IMAGE_NAME }}
registry: ${{ secrets.QUAY_REPO }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
Expand Down
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ branding:
icon: circle
color: red
inputs:
image-to-push:
description: 'Name of the new image that will be pushed'
image:
description: 'Name of the image to push'
required: true
tag:
description: 'Tag of the new image'
description: 'Tag of the image to push'
required: false
default: 'latest'
registry:
description: 'Registry where to push the image (e.g quay.io/username)'
description: 'Registry where to push the image (eg. quay.io/username)'
required: true
username:
description: 'Username to use as credential to authenticate to the registry'
Expand All @@ -23,4 +23,4 @@ inputs:
required: true
runs:
using: 'node12'
main: 'dist/index.js'
main: 'dist/index.js'
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"devDependencies": {
"@types/node": "^12.12.7",
"@vercel/ncc": "^0.25.1",
"typescript": "^4.0.5"
}
}
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import * as io from '@actions/io';
import { CommandResult } from './types';

export async function run(): Promise<void> {
let imageToPush = core.getInput('image-to-push');
let imageToPush = core.getInput('image', { required: true });
const tag = core.getInput('tag') || 'latest';
const registry = core.getInput('registry');
const username = core.getInput('username');
const password = core.getInput('password');
const registry = core.getInput('registry', { required: true });
const username = core.getInput('username', { required: true });
const password = core.getInput('password', { required: true });

// get podman cli
const podman = await io.which('podman', true);
Expand All @@ -18,9 +18,9 @@ export async function run(): Promise<void> {
const checkImages: CommandResult = await execute(podman, ['images', '--format', 'json']);
if (checkImages.succeeded === false) {
return Promise.reject(new Error(checkImages.reason));
}
}
const parsedCheckImages = JSON.parse(checkImages.output);
// this is to temporarily solve an issue with the case-sensitive of the property field name. i.e it is Names or names??
// this is to temporarily solve an issue with the case-sensitive of the property field name. i.e it is Names or names??
const nameKeyMixedCase = parsedCheckImages[0] && Object.keys(parsedCheckImages[0]).find(key => 'names' === key.toLowerCase());
const imagesFound = parsedCheckImages.
filter(image => image[nameKeyMixedCase] && image[nameKeyMixedCase].find(name => name.includes(`${imageToPush}`))).
Expand All @@ -44,7 +44,7 @@ export async function run(): Promise<void> {
async function execute(executable: string, args: string[]): Promise<CommandResult> {
let output = '';
let error = '';

const options: exec.ExecOptions = {};
options.listeners = {
stdout: (data: Buffer): void => {
Expand All @@ -57,8 +57,8 @@ async function execute(executable: string, args: string[]): Promise<CommandResul
const exitCode = await exec.exec(executable, args, options);
if (exitCode === 1) {
return Promise.resolve({ succeeded: false, error });
}
}
return Promise.resolve({ succeeded: true, output });
}

run().catch(core.setFailed);
run().catch(core.setFailed);

0 comments on commit 6109531

Please sign in to comment.