3
0
Fork 0
mirror of https://gitea.com/docker/login-action.git synced 2024-11-23 01:49:36 +01:00
docker-login/src/main.ts
2020-08-20 16:40:33 +02:00

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();
}