2020-08-15 12:45:36 +00:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as core from '@actions/core';
|
2020-08-20 14:40:33 +00:00
|
|
|
import {getInputs, Inputs} from './context';
|
|
|
|
import * as docker from './docker';
|
2020-08-15 12:45:36 +00:00
|
|
|
import * as stateHelper from './state-helper';
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
|
|
|
if (os.platform() !== 'linux') {
|
|
|
|
core.setFailed('Only supported on linux platform');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-20 14:40:33 +00:00
|
|
|
let inputs: Inputs = await getInputs();
|
|
|
|
stateHelper.setRegistry(inputs.registry);
|
|
|
|
stateHelper.setLogout(inputs.logout);
|
|
|
|
await docker.login(inputs.registry, inputs.username, inputs.password);
|
2020-08-15 12:45:36 +00:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function logout(): Promise<void> {
|
|
|
|
if (!stateHelper.logout) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-20 14:40:33 +00:00
|
|
|
await docker.logout(stateHelper.registry);
|
2020-08-15 12:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!stateHelper.IsPost) {
|
|
|
|
run();
|
|
|
|
} else {
|
|
|
|
logout();
|
|
|
|
}
|