mirror of
https://github.com/redhat-actions/podman-login.git
synced 2025-05-07 12:39:53 +02:00
Add example workflow
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
565d575198
commit
1b6468c894
10 changed files with 68 additions and 196 deletions
|
@ -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),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
35
src/index.ts
35
src/index.ts
|
@ -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
17
src/state-helper.ts
Normal 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');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue