1
0
Files
login-action/src/main.ts
T

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-09-05 18:43:09 +02:00
import * as core from '@actions/core';
2023-02-21 10:06:17 +01:00
import * as actionsToolkit from '@docker/actions-toolkit';
2026-03-01 11:26:40 +01:00
import * as context from './context.js';
import * as docker from './docker.js';
import * as stateHelper from './state-helper.js';
2020-08-15 14:45:36 +02:00
2023-02-21 10:06:17 +01:00
export async function main(): Promise<void> {
2025-09-05 18:43:09 +02:00
const inputs: context.Inputs = context.getInputs();
stateHelper.setLogout(inputs.logout);
const auths = context.getAuthList(inputs);
stateHelper.setRegistries(Array.from(new Map(auths.map(auth => [`${auth.registry}|${auth.configDir}`, {registry: auth.registry, configDir: auth.configDir} as stateHelper.RegistryState])).values()));
2025-09-05 18:43:09 +02:00
if (auths.length === 1) {
await docker.login(auths[0]);
2025-09-05 18:43:09 +02:00
return;
}
for (const auth of auths) {
await core.group(`Login to ${auth.registry}`, async () => {
await docker.login(auth);
2025-09-05 18:43:09 +02:00
});
}
2020-08-15 14:45:36 +02:00
}
2023-02-21 10:06:17 +01:00
async function post(): Promise<void> {
2020-08-15 14:45:36 +02:00
if (!stateHelper.logout) {
return;
}
for (const registryState of stateHelper.registries) {
await core.group(`Logout from ${registryState.registry}`, async () => {
await docker.logout(registryState.registry, registryState.configDir);
});
2025-09-05 18:43:09 +02:00
}
2020-08-15 14:45:36 +02:00
}
2023-02-21 10:06:17 +01:00
actionsToolkit.run(main, post);