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