mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-04-29 18:19:53 +02:00
first implementation push to quay action
Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
This commit is contained in:
commit
9a0a0927cd
11 changed files with 4046 additions and 0 deletions
39
src/index.ts
Normal file
39
src/index.ts
Normal 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
11
src/types.ts
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue