mirror of
https://github.com/docker/login-action
synced 2024-11-22 21:11:41 +00:00
34 lines
818 B
TypeScript
34 lines
818 B
TypeScript
import * as os from 'os';
|
|
import * as core from '@actions/core';
|
|
import {getInputs, Inputs} from './context';
|
|
import * as docker from './docker';
|
|
import * as stateHelper from './state-helper';
|
|
|
|
async function run(): Promise<void> {
|
|
try {
|
|
if (os.platform() !== 'linux') {
|
|
core.setFailed('Only supported on linux platform');
|
|
return;
|
|
}
|
|
|
|
let inputs: Inputs = await getInputs();
|
|
stateHelper.setRegistry(inputs.registry);
|
|
stateHelper.setLogout(inputs.logout);
|
|
await docker.login(inputs.registry, inputs.username, inputs.password);
|
|
} catch (error) {
|
|
core.setFailed(error.message);
|
|
}
|
|
}
|
|
|
|
async function logout(): Promise<void> {
|
|
if (!stateHelper.logout) {
|
|
return;
|
|
}
|
|
await docker.logout(stateHelper.registry);
|
|
}
|
|
|
|
if (!stateHelper.IsPost) {
|
|
run();
|
|
} else {
|
|
logout();
|
|
}
|