mirror of
https://github.com/docker/login-action.git
synced 2024-11-10 06:05:39 +01:00
4b15841c41
* Create docker.test.ts * Add context tests * test main
34 lines
797 B
TypeScript
34 lines
797 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';
|
|
|
|
export async function run(): Promise<void> {
|
|
try {
|
|
if (os.platform() !== 'linux') {
|
|
throw new Error('Only supported on linux platform');
|
|
}
|
|
|
|
const {registry, username, password, logout} = getInputs();
|
|
stateHelper.setRegistry(registry);
|
|
stateHelper.setLogout(logout);
|
|
await docker.login(registry, username, 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();
|
|
}
|