login-action/src/main.ts

29 lines
669 B
TypeScript
Raw Normal View History

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