mirror of
https://github.com/redhat-actions/podman-login.git
synced 2025-05-21 17:59:55 +02:00
First commit 🚀
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
commit
565d575198
20 changed files with 6476 additions and 0 deletions
src
16
src/context.ts
Normal file
16
src/context.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import * as core from "@actions/core";
|
||||
import { Inputs } from "./generated/inputs-outputs";
|
||||
|
||||
export interface ActionInputs {
|
||||
registry: string;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export function getInputs(): ActionInputs {
|
||||
return {
|
||||
registry: core.getInput(Inputs.REGISTRY),
|
||||
username: core.getInput(Inputs.USERNAME),
|
||||
password: core.getInput(Inputs.PASSWORD),
|
||||
};
|
||||
}
|
24
src/generated/inputs-outputs.ts
Normal file
24
src/generated/inputs-outputs.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
// This file was auto-generated by action-io-generator. Do not edit by hand!
|
||||
export enum Inputs {
|
||||
/**
|
||||
* Password or personal access token used to log against the Docker registry
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
PASSWORD = "password",
|
||||
/**
|
||||
* Server address of Docker registry. If not set then will default to Docker Hub
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
REGISTRY = "registry",
|
||||
/**
|
||||
* Username used to log against the Docker registry
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
USERNAME = "username",
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
}
|
47
src/index.ts
Normal file
47
src/index.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
/***************************************************************************************************
|
||||
* 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";
|
||||
|
||||
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") {
|
||||
throw new Error("Only supported on linux platform");
|
||||
}
|
||||
|
||||
const { registry, username, password } = getInputs();
|
||||
|
||||
const args = [
|
||||
"login",
|
||||
registry,
|
||||
"-u",
|
||||
username,
|
||||
"-p",
|
||||
password,
|
||||
];
|
||||
try {
|
||||
await execute(await getPodmanPath(), args);
|
||||
core.info(`✅ Successfully logged in to ${registry}`);
|
||||
}
|
||||
catch (err) {
|
||||
core.error(`Failed to login to ${registry}`);
|
||||
}
|
||||
}
|
||||
|
||||
run().catch(core.setFailed);
|
66
src/utils.ts
Normal file
66
src/utils.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
/***************************************************************************************************
|
||||
* 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 exec from "@actions/exec";
|
||||
import * as path from "path";
|
||||
|
||||
interface ExecResult {
|
||||
exitCode: number;
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}
|
||||
|
||||
export async function execute(
|
||||
executable: string,
|
||||
args: string[],
|
||||
execOptions: exec.ExecOptions & { group?: boolean } = {},
|
||||
): Promise<ExecResult> {
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
|
||||
const finalExecOptions = { ...execOptions };
|
||||
finalExecOptions.ignoreReturnCode = true; // the return code is processed below
|
||||
|
||||
finalExecOptions.listeners = {
|
||||
stdline: (line): void => {
|
||||
stdout += `${line}\n`;
|
||||
},
|
||||
errline: (line): void => {
|
||||
stderr += `${line}\n`;
|
||||
},
|
||||
};
|
||||
|
||||
if (execOptions.group) {
|
||||
const groupName = [ executable, ...args ].join(" ");
|
||||
core.startGroup(groupName);
|
||||
}
|
||||
|
||||
try {
|
||||
const exitCode = await exec.exec(executable, args, finalExecOptions);
|
||||
|
||||
if (execOptions.ignoreReturnCode !== true && exitCode !== 0) {
|
||||
// Throwing the stderr as part of the Error makes the stderr show up in the action outline,
|
||||
// which saves some clicking when debugging.
|
||||
let error = `${path.basename(executable)} exited with code ${exitCode}`;
|
||||
if (stderr) {
|
||||
error += `\n${stderr}`;
|
||||
}
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
return {
|
||||
exitCode,
|
||||
stdout,
|
||||
stderr,
|
||||
};
|
||||
}
|
||||
|
||||
finally {
|
||||
if (execOptions.group) {
|
||||
core.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue