Add example workflow

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-03-30 22:45:50 +05:30
parent 565d575198
commit 1b6468c894
10 changed files with 68 additions and 196 deletions

View file

@ -5,6 +5,7 @@ export interface ActionInputs {
registry: string;
username: string;
password: string;
logout: string;
}
export function getInputs(): ActionInputs {
@ -12,5 +13,6 @@ export function getInputs(): ActionInputs {
registry: core.getInput(Inputs.REGISTRY),
username: core.getInput(Inputs.USERNAME),
password: core.getInput(Inputs.PASSWORD),
logout: core.getInput(Inputs.LOGOUT),
};
}

View file

@ -1,5 +1,11 @@
// This file was auto-generated by action-io-generator. Do not edit by hand!
export enum Inputs {
/**
* Set to true if you want to logout once the workflows completes
* Required: false
* Default: "false"
*/
LOGOUT = "logout",
/**
* Password or personal access token used to log against the Docker registry
* Required: false

View file

@ -8,6 +8,7 @@ import * as io from "@actions/io";
import * as os from "os";
import { getInputs } from "./context";
import { execute } from "./utils";
import * as stateHelper from './state-helper';
let podmanPath: string | undefined;
@ -25,7 +26,11 @@ async function run(): Promise<void> {
throw new Error("Only supported on linux platform");
}
const { registry, username, password } = getInputs();
const {
registry, username, password, logout,
} = getInputs();
stateHelper.setLogout(logout);
const args = [
"login",
@ -35,13 +40,25 @@ async function run(): Promise<void> {
"-p",
password,
];
try {
await execute(await getPodmanPath(), args);
core.info(`✅ Successfully logged in to ${registry}`);
}
catch (err) {
core.error(`Failed to login to ${registry}`);
}
await execute(await getPodmanPath(), args);
core.info(`✅ Successfully logged in to ${registry}`);
// if (logout) {
// await execute(await getPodmanPath(), [ "logout", registry ]);
// }
}
run().catch(core.setFailed);
async function logout(): Promise<void> {
if (!stateHelper.logout) {
return;
}
await execute(await getPodmanPath(), [ "logout", "quay.io" ]);
}
if (!stateHelper.IsPost) {
run().catch(core.setFailed);;
}
else {
logout().catch(core.setFailed);;
}

17
src/state-helper.ts Normal file
View file

@ -0,0 +1,17 @@
import * as core from '@actions/core';
export const IsPost = !!process.env['STATE_isPost'];
// export const registry = process.env['STATE_registry'] || '';
export const logout = /true/i.test(process.env['STATE_logout'] || '');
// export function setRegistry(registry: string) {
// core.saveState('registry', registry);
// }
export function setLogout(logout: string) {
core.saveState('logout', logout);
}
if (!IsPost) {
core.saveState('isPost', 'true');
}