2025-09-05 16:43:09 +00:00
|
|
|
import * as core from '@actions/core';
|
2023-02-21 09:06:17 +00:00
|
|
|
import * as actionsToolkit from '@docker/actions-toolkit';
|
|
|
|
|
|
2021-04-27 22:34:26 +00:00
|
|
|
import * as context from './context';
|
2020-08-20 14:40:33 +00:00
|
|
|
import * as docker from './docker';
|
2020-08-15 12:45:36 +00:00
|
|
|
import * as stateHelper from './state-helper';
|
|
|
|
|
|
2023-02-21 09:06:17 +00:00
|
|
|
export async function main(): Promise<void> {
|
2025-09-05 16:43:09 +00:00
|
|
|
const inputs: context.Inputs = context.getInputs();
|
|
|
|
|
stateHelper.setLogout(inputs.logout);
|
|
|
|
|
|
2026-01-06 12:51:25 +00:00
|
|
|
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 16:43:09 +00:00
|
|
|
|
2026-01-06 12:51:25 +00:00
|
|
|
if (auths.length === 1) {
|
|
|
|
|
await docker.login(auths[0]);
|
2025-09-05 16:43:09 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auth of auths) {
|
2026-01-06 12:51:25 +00:00
|
|
|
await core.group(`Login to ${auth.registry}`, async () => {
|
|
|
|
|
await docker.login(auth);
|
2025-09-05 16:43:09 +00:00
|
|
|
});
|
|
|
|
|
}
|
2020-08-15 12:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-21 09:06:17 +00:00
|
|
|
async function post(): Promise<void> {
|
2020-08-15 12:45:36 +00:00
|
|
|
if (!stateHelper.logout) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-06 12:51:25 +00:00
|
|
|
for (const registryState of stateHelper.registries) {
|
|
|
|
|
await core.group(`Logout from ${registryState.registry}`, async () => {
|
|
|
|
|
await docker.logout(registryState.registry, registryState.configDir);
|
|
|
|
|
});
|
2025-09-05 16:43:09 +00:00
|
|
|
}
|
2020-08-15 12:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-21 09:06:17 +00:00
|
|
|
actionsToolkit.run(main, post);
|