mirror of
https://gitee.com/actions-mirror/docker-login-action
synced 2024-11-27 21:50:42 +08: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();
|
|
}
|