Skip to content

Commit 5aafae8

Browse files
committed
ci: clean up PR OCIs after PR close
1 parent d32ec48 commit 5aafae8

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

.github/workflows/dev.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- "docs/**"
1313
jobs:
1414
set_version:
15+
if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }}
1516
runs-on: ubuntu-latest
1617
outputs:
1718
VERSION: ${{ steps.version.outputs.VERSION }}
@@ -32,6 +33,7 @@ jobs:
3233
3334
build:
3435
needs: [set_version]
36+
if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }}
3537
uses: gardenlinux/gardenlinux/.github/workflows/build.yml@3b5ec77e4873462d56658c4ecd56caa0ff63542b
3638
with:
3739
version: ${{ needs.set_version.outputs.VERSION }}
@@ -82,6 +84,28 @@ jobs:
8284
with:
8385
image_tag: "${{ needs.meta.outputs.UPLOAD_VERSION }}-metal-sci-usi-amd64-${{ needs.meta.outputs.COMMIT_SHA }}-amd64"
8486

85-
# TODO on PR close, clean up everything in form of
86-
# oras repo tags ghcr.io/gardenlinux/gardenlinux-ccloud | grep -v -E '^[0-9]{4}\.[0-9]+.*$'
87-
# oras repo tags ghcr.io/gardenlinux/gardenlinux-ccloud | grep -E '^PREFIX$'
87+
cleanup_images:
88+
name: Cleanup PR images
89+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: oras
93+
uses: oras-project/setup-oras@v1
94+
with:
95+
version: 1.2.2
96+
- name: Cleanup OCI images
97+
run: |
98+
PR_NUMBER=${{ github.event.pull_request.number }}
99+
UPLOAD_VERSION="pr-${PR_NUMBER}"
100+
oras logout ghcr.io
101+
echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u "${{ github.actor }}" --password-stdin
102+
tags=$(oras repo tags ghcr.io/gardenlinux/gardenlinux-ccloud | grep -E "^${UPLOAD_VERSION}(-.*)?$" || true)
103+
if [ -n "$tags" ]; then
104+
for tag in $tags; do
105+
echo "Deleting tag: $tag"
106+
# oras manifest delete ghcr.io/gardenlinux/gardenlinux-ccloud:$tag
107+
done
108+
echo "Cleanup completed for PR ${PR_NUMBER}"
109+
else
110+
echo "No images found to cleanup for PR ${PR_NUMBER}"
111+
fi

0 commit comments

Comments
 (0)