Skip to content

Commit b0972d4

Browse files
committed
feat: add cleanup workflow
1 parent 910ea61 commit b0972d4

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/cleanup.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: cleanup tags
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- .github/workflows/cleanup.yml
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
cleanup:
15+
if: ${{ github.repository_owner == 'CubeCoders' && github.ref == 'refs/heads/master' }}
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
steps:
20+
- name: Delete named tags if they exist
21+
shell: bash
22+
env:
23+
ORG: cubecoders
24+
REPO: ampbase
25+
TAGS: 'debian-13'
26+
run: |
27+
set -u
28+
29+
TOKEN=$(
30+
curl -s -H "Content-Type: application/json" -X POST \
31+
-d "{\"username\":\"${{ vars.DOCKERHUB_USERNAME }}\",\"password\":\"${{ secrets.DOCKERHUB_TOKEN }}\"}" \
32+
https://hub.docker.com/v2/users/login/ | jq -r .token
33+
)
34+
35+
for tag in $TAGS; do
36+
echo "Processing tag: $tag"
37+
38+
check_code=$(curl -s -o /dev/null -w "%{http_code}" \
39+
-H "Authorization: JWT $TOKEN" \
40+
"https://hub.docker.com/v2/repositories/$ORG/$REPO/tags/$tag/")
41+
42+
if [[ "$check_code" == "200" ]]; then
43+
echo "Tag exists. Deleting…"
44+
del_code=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
45+
-H "Authorization: JWT $TOKEN" \
46+
"https://hub.docker.com/v2/repositories/$ORG/$REPO/tags/$tag/")
47+
48+
if [[ "$del_code" == "204" || "$del_code" == "202" ]]; then
49+
echo "Deleted: $tag"
50+
else
51+
echo "WARNING: Failed to delete $tag (HTTP $del_code). Continuing."
52+
fi
53+
54+
elif [[ "$check_code" == "404" ]]; then
55+
echo "Tag not found: $tag — skipping."
56+
57+
else
58+
echo "WARNING: Could not verify tag $tag (HTTP $check_code). Skipping."
59+
fi
60+
done
61+
62+
concurrency:
63+
group: ${{ github.workflow }}-${{ github.ref }}
64+
cancel-in-progress: false

0 commit comments

Comments
 (0)