-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (29 loc) · 1.02 KB
/
index.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
const core = require('@actions/core');
const AWS = require('aws-sdk');
(async () => {
try {
const ecr = new AWS.ECR({
apiVersion: '2015-09-21',
region: core.getInput('region'),
accessKeyId: core.getInput('access_key'),
secretAccessKey: core.getInput('secret_key')
});
const repository = core.getInput('repository');
const images = await ecr.listImages({
repositoryName: repository,
maxResults: 100,
filter: { tagStatus: 'UNTAGGED' },
}).promise();
if (images.imageIds.length) {
const imagesDeleted = await ecr.batchDeleteImage({
imageIds: images.imageIds,
repositoryName: repository
}).promise();
imagesDeleted.imageIds.forEach(i => console.log(`deleted images ${i.imageDigest}`))
} else {
console.log('No images found to delete.');
}
} catch (error) {
core.setFailed(error.message);
}
})()