mirror of
https://github.com/docker/login-action.git
synced 2024-11-18 01:55:40 +01:00
35 lines
818 B
TypeScript
35 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();
|
|
}
|