Update code

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-03-31 14:31:58 +05:30
parent 1b6468c894
commit 6c4ab503eb
8 changed files with 38 additions and 46 deletions

View file

@ -1,25 +1,25 @@
// 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
* Set to true if you want to logout at the end of the job
* Required: false
* Default: "false"
*/
LOGOUT = "logout",
/**
* Password or personal access token used to log against the Docker registry
* Password to login against the container image registry
* Required: false
* Default: None.
*/
PASSWORD = "password",
/**
* Server address of Docker registry. If not set then will default to Docker Hub
* Required: false
* Server URL of the container image registry
* Required: true
* Default: None.
*/
REGISTRY = "registry",
/**
* Username used to log against the Docker registry
* Username to login against the container image registry
* Required: false
* Default: None.
*/

View file

@ -8,7 +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';
import * as stateHelper from "./state-helper";
let podmanPath: string | undefined;
@ -23,13 +23,14 @@ async function getPodmanPath(): Promise<string> {
async function run(): Promise<void> {
if (os.platform() !== "linux") {
throw new Error("Only supported on linux platform");
throw new Error("Only supported on linux platform");
}
const {
registry, username, password, logout,
registry, username, password, logout, // eslint-disable-line @typescript-eslint/no-shadow
} = getInputs();
stateHelper.setRegistry(registry);
stateHelper.setLogout(logout);
const args = [
@ -43,22 +44,18 @@ async function run(): Promise<void> {
await execute(await getPodmanPath(), args);
core.info(`✅ Successfully logged in to ${registry}`);
// if (logout) {
// await execute(await getPodmanPath(), [ "logout", registry ]);
// }
}
async function logout(): Promise<void> {
if (!stateHelper.logout) {
return;
}
await execute(await getPodmanPath(), [ "logout", "quay.io" ]);
}
await execute(await getPodmanPath(), [ "logout", stateHelper.registry ]);
}
if (!stateHelper.IsPost) {
run().catch(core.setFailed);;
run().catch(core.setFailed);
}
else {
logout().catch(core.setFailed);;
logout().catch(core.setFailed);
}

View file

@ -1,17 +1,21 @@
import * as core from '@actions/core';
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'] || '');
/* eslint-disable dot-notation */
export const IsPost = !!process.env["STATE_isPost"];
export const registry = process.env["STATE_registry"] || "";
export const logout = /true/i.test(process.env["STATE_logout"] || "");
/* eslint-enable dot-notation */
// export function setRegistry(registry: string) {
// core.saveState('registry', registry);
// }
// eslint-disable-next-line @typescript-eslint/no-shadow
export function setRegistry(registry: string): void {
core.saveState("registry", registry);
}
export function setLogout(logout: string) {
core.saveState('logout', logout);
// eslint-disable-next-line @typescript-eslint/no-shadow
export function setLogout(logout: string): void {
core.saveState("logout", logout);
}
if (!IsPost) {
core.saveState('isPost', 'true');
core.saveState("isPost", "true");
}