2021-03-30 18:57:12 +05:30
|
|
|
/***************************************************************************************************
|
|
|
|
* Copyright (c) Red Hat, Inc. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
|
|
|
import * as core from "@actions/core";
|
|
|
|
import * as io from "@actions/io";
|
|
|
|
import * as os from "os";
|
|
|
|
import { getInputs } from "./context";
|
|
|
|
import { execute } from "./utils";
|
2021-03-31 14:31:58 +05:30
|
|
|
import * as stateHelper from "./state-helper";
|
2021-03-30 18:57:12 +05:30
|
|
|
|
|
|
|
let podmanPath: string | undefined;
|
|
|
|
|
|
|
|
async function getPodmanPath(): Promise<string> {
|
|
|
|
if (podmanPath == null) {
|
|
|
|
podmanPath = await io.which("podman", true);
|
|
|
|
await execute(podmanPath, [ "version" ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return podmanPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
if (os.platform() !== "linux") {
|
2021-03-31 14:31:58 +05:30
|
|
|
throw new Error("❌ Only supported on linux platform");
|
2021-03-30 18:57:12 +05:30
|
|
|
}
|
|
|
|
|
2021-03-30 22:45:50 +05:30
|
|
|
const {
|
2021-03-31 14:31:58 +05:30
|
|
|
registry, username, password, logout, // eslint-disable-line @typescript-eslint/no-shadow
|
2021-03-30 22:45:50 +05:30
|
|
|
} = getInputs();
|
|
|
|
|
2021-03-31 14:31:58 +05:30
|
|
|
stateHelper.setRegistry(registry);
|
2021-03-30 22:45:50 +05:30
|
|
|
stateHelper.setLogout(logout);
|
2021-03-30 18:57:12 +05:30
|
|
|
|
|
|
|
const args = [
|
|
|
|
"login",
|
|
|
|
registry,
|
|
|
|
"-u",
|
|
|
|
username,
|
|
|
|
"-p",
|
|
|
|
password,
|
|
|
|
];
|
2021-03-30 22:45:50 +05:30
|
|
|
|
|
|
|
await execute(await getPodmanPath(), args);
|
|
|
|
core.info(`✅ Successfully logged in to ${registry}`);
|
2021-03-30 18:57:12 +05:30
|
|
|
}
|
|
|
|
|
2021-03-30 22:45:50 +05:30
|
|
|
async function logout(): Promise<void> {
|
|
|
|
if (!stateHelper.logout) {
|
|
|
|
return;
|
2021-03-31 14:31:58 +05:30
|
|
|
}
|
|
|
|
await execute(await getPodmanPath(), [ "logout", stateHelper.registry ]);
|
2021-03-30 22:45:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (!stateHelper.IsPost) {
|
2021-03-31 14:31:58 +05:30
|
|
|
run().catch(core.setFailed);
|
2021-03-30 22:45:50 +05:30
|
|
|
}
|
|
|
|
else {
|
2021-03-31 14:31:58 +05:30
|
|
|
logout().catch(core.setFailed);
|
2021-03-30 22:45:50 +05:30
|
|
|
}
|