-
Notifications
You must be signed in to change notification settings - Fork 175
/
cleanup.js
61 lines (52 loc) · 1.5 KB
/
cleanup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const core = require('@actions/core');
const exec = require('@actions/exec');
/**
* When the GitHub Actions job is done, logout of ECR Private/Public.
*/
const STATES = {
registries: 'registries'
};
async function cleanup() {
try {
const registriesState = core.getState(STATES.registries);
if (registriesState) {
const registries = registriesState.split(',');
const failedLogouts = [];
// Logout of each registry
for (const registry of registries) {
core.info(`Logging out of registry ${registry}`);
// Execute the docker logout command
let doLogoutStdout = '';
let doLogoutStderr = '';
const exitCode = await exec.exec('docker', ['logout', registry], {
silent: true,
ignoreReturnCode: true,
listeners: {
stdout: (data) => {
doLogoutStdout += data.toString();
},
stderr: (data) => {
doLogoutStderr += data.toString();
}
}
});
if (exitCode !== 0) {
core.debug(doLogoutStdout);
core.error(`Could not logout of registry ${registry}: ${doLogoutStderr}`);
failedLogouts.push(registry);
}
}
if (failedLogouts.length) {
throw new Error(`Failed to logout: ${failedLogouts.join(',')}`);
}
}
}
catch (error) {
core.setFailed(error.message);
}
}
module.exports = cleanup;
/* istanbul ignore next */
if (require.main === module) {
cleanup();
}