first implementation push to quay action

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
This commit is contained in:
Luca Stocchi 2020-11-07 13:04:04 +01:00
commit 9a0a0927cd
No known key found for this signature in database
GPG key ID: 930BB00F3FCF30A4
11 changed files with 4046 additions and 0 deletions

39
src/index.ts Normal file
View file

@ -0,0 +1,39 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import { CommandResult } from './types';
export async function run(): Promise<void> {
const imageToPush = core.getInput('image-to-push');
const quayRegistry = core.getInput('quay-registry');
const username = core.getInput('username');
const password = core.getInput('password');
// get podman cli
const podman = await io.which('podman', true);
// push image
const push: CommandResult = await execute(podman, ['push', '--creds', `${username}:${password}`, `${imageToPush}`, `${quayRegistry}`]);
if (push.succeeded === false) {
return Promise.reject(new Error(push.reason));
}
}
async function execute(executable: string, args: string[]): Promise<CommandResult> {
let error = '';
const options: exec.ExecOptions = {};
options.listeners = {
stderr: (data: Buffer): void => {
error += data.toString();
}
};
const exitCode = await exec.exec(this.executable, args, options);
if (exitCode === 1) {
return Promise.resolve({ succeeded: false, error: error });
}
return Promise.resolve({ succeeded: true });
}
run().catch(core.setFailed);

11
src/types.ts Normal file
View file

@ -0,0 +1,11 @@
export interface CommandSucceeeded {
readonly succeeded: true;
readonly output?: string;
}
export interface CommandFailed {
readonly succeeded: false;
readonly reason?: string;
}
export type CommandResult = CommandFailed | CommandSucceeeded;