-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (45 loc) · 1.5 KB
/
delete-untagged-images.yml
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
name: "Delete untagged images."
on:
schedule:
- cron: "15 16 * * *" # 16:15 UTC
workflow_dispatch:
push:
jobs:
delete-untagged-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
images:
- image: al2023
- image: alpine
- image: debian
steps:
- name: "Delete untagged images."
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.rest.packages.getAllPackageVersionsForAPackageOwnedByTheAuthenticatedUser({
package_type: "container",
package_name: ${{ env.PACKAGE_NAME }},
per_page: ${{ env.PER_PAGE }}
});
for(version of response.data) {
if (version.metadata.container.tags.length == 0) {
console.log("Removing: " + version.id)
const deleteResponse = await github.rest.packages.deletePackageVersionForTheAuthenticatedUser({
package_type: "container",
package_name: ${{ env.PACKAGE_NAME }},
package_version_id: version.id
});
console.log("Status: " + deleteResponse.status)
}
}
env:
OWNER: ${{ github.repository_owner }}
PACKAGE_NAME: ${{ matrix.images.image }}
PER_PAGE: 100