Skip to content

Commit 1036fb6

Browse files
Danielius1922Daniel Adam
authored andcommitted
Add retry to clean-up packages GitHub action
1 parent 85df815 commit 1036fb6

File tree

2 files changed

+100
-11
lines changed

2 files changed

+100
-11
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Delete stale images
2+
3+
description: Delete stale images
4+
5+
inputs:
6+
delay:
7+
description: Delay before running the action (in seconds)
8+
required: false
9+
default: "0" # seconds
10+
token:
11+
description: A Github PAT token to fetch repository and delete packages (needs delete:packages permissions).
12+
required: true
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Delay # needed in case of retry to avoid triggering the rate limit of the Github API
18+
if: ${{ inputs.delay != '0' }}
19+
shell: bash
20+
run: |
21+
sleep ${{ inputs.delay }}
22+
23+
- name: Delete older than a month vnext and vnext-pr images
24+
uses: snok/container-retention-policy@v2
25+
with:
26+
image-names: client-application
27+
cut-off: One month ago UTC
28+
account-type: org
29+
org-name: plgd-dev
30+
# matches both vnext-* and vnext-pr-* tags
31+
filter-tags: vnext-*
32+
skip-tags: main
33+
token: ${{ inputs.token }}
34+
35+
- name: Set up Docker Buildx for delete untagged images action
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Login to GitHub Container Registry for delete untagged images action
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ inputs.token }}
44+
45+
- name: Delete untagged images with no dependency
46+
uses: Chizkiyahu/delete-untagged-ghcr-action@v3
47+
with:
48+
repository: ${{ github.repository }}
49+
repository_owner: ${{ github.repository_owner }}
50+
token: ${{ inputs.token }}
51+
owner_type: org
52+
untagged_only: true
53+
except_untagged_multiplatform: true

.github/workflows/ghcr-cleanup.yaml

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ jobs:
1111
name: Delete images related to closed PR
1212
runs-on: ubuntu-latest
1313
steps:
14-
- name: Delete images related to closed PR
14+
- name: Delete images related to closed PR (1)
15+
id: run-1
16+
continue-on-error: true
1517
uses: snok/container-retention-policy@v2
1618
with:
1719
image-names: client-application
@@ -20,18 +22,52 @@ jobs:
2022
org-name: plgd-dev
2123
filter-tags: vnext-pr${{ github.event.pull_request.number }}*
2224
token: ${{ secrets.GHCR_CLEANUP_PAT }}
23-
nightly-ghcr-cleanup:
24-
if: ${{ github.event_name == 'schedule' }}
25-
name: Delete old vnext images
26-
runs-on: ubuntu-latest
27-
steps:
28-
- name: Delete older than a month vnext images
25+
- name: Delete images related to closed PR (2)
26+
id: run-2
27+
if: ${{ steps.run-1.outcome == 'failure' }}
28+
continue-on-error: true
29+
uses: snok/container-retention-policy@v2
30+
with:
31+
image-names: client-application
32+
cut-off: now UTC
33+
account-type: org
34+
org-name: plgd-dev
35+
filter-tags: vnext-pr${{ github.event.pull_request.number }}*
36+
token: ${{ secrets.GHCR_CLEANUP_PAT }}
37+
- name: Delete images related to closed PR (3)
38+
if: ${{ steps.run-2.outcome == 'failure' }}
2939
uses: snok/container-retention-policy@v2
3040
with:
3141
image-names: client-application
32-
cut-off: One month ago UTC
42+
cut-off: now UTC
3343
account-type: org
3444
org-name: plgd-dev
35-
filter-tags: vnext-*
36-
skip-tags: vnext-pr*, main
37-
token: ${{ secrets.GHCR_CLEANUP_PAT }}
45+
filter-tags: vnext-pr${{ github.event.pull_request.number }}*
46+
token: ${{ secrets.GHCR_CLEANUP_PAT }}
47+
nightly-ghcr-cleanup:
48+
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
49+
name: Delete stale or untagged images
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout local actions
53+
uses: actions/checkout@v4
54+
- name: Delete stale or untagged images (1)
55+
id: run-1
56+
continue-on-error: true
57+
uses: ./.github/actions/cleanup-stale
58+
with:
59+
token: ${{ secrets.GHCR_CLEANUP_PAT }}
60+
- name: Delete stale or untagged images (2)
61+
id: run-2
62+
if: ${{ steps.run-1.outcome == 'failure' }}
63+
with:
64+
token: ${{ secrets.GHCR_CLEANUP_PAT }}
65+
delay: 60
66+
continue-on-error: true
67+
uses: ./.github/actions/cleanup-stale
68+
- name: Delete stale or untagged images (3)
69+
if: ${{ steps.run-2.outcome == 'failure' }}
70+
uses: ./.github/actions/cleanup-stale
71+
with:
72+
token: ${{ secrets.GHCR_CLEANUP_PAT }}
73+
delay: 60

0 commit comments

Comments
 (0)