Skip to content

Commit 8dcb4f0

Browse files
authored
Create a simple GHA that cleanup untagged devx-container daily (#137)
1 parent be992af commit 8dcb4f0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.github/workflows/cleanup.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Delete Untagged GHCR Containers
2+
3+
on:
4+
schedule:
5+
# Runs at 00:00 UTC every day
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
cleanup-untagged-containers:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up GitHub CLI
20+
uses: actions/setup-cli@v2
21+
22+
- name: Authenticate with GitHub Container Registry
23+
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
24+
25+
- name: List and Delete Untagged Containers
26+
env:
27+
GHCR_PACKAGE_NAME: devx-devcontainer
28+
OWNER: input-output-hk
29+
run: |
30+
untagged_images=$(gh api -X GET /user/packages/container/$GHCR_PACKAGE_NAME/versions --paginate --jq '.[] | select(.metadata.container.tags | length == 0) | .id')
31+
for image_id in $untagged_images; do
32+
echo "Deleting untagged container image with ID: $image_id"
33+
gh api -X DELETE /user/packages/container/$GHCR_PACKAGE_NAME/versions/$image_id
34+
done

0 commit comments

Comments
 (0)