-
Notifications
You must be signed in to change notification settings - Fork 16
64 lines (55 loc) · 1.92 KB
/
cleanup.yml
File metadata and controls
64 lines (55 loc) · 1.92 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: cleanup tags
on:
workflow_dispatch:
push:
branches:
- master
paths:
- .github/workflows/cleanup.yml
permissions:
contents: read
packages: write
jobs:
cleanup:
if: ${{ github.repository_owner == 'CubeCoders' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Delete named tags if they exist
shell: bash
env:
ORG: cubecoders
REPO: ampbase
TAGS: 'debian-13'
run: |
set -u
TOKEN=$(
curl -s -H "Content-Type: application/json" -X POST \
-d "{\"username\":\"${{ vars.DOCKERHUB_USERNAME }}\",\"password\":\"${{ secrets.DOCKERHUB_TOKEN }}\"}" \
https://hub.docker.com/v2/users/login/ | jq -r .token
)
for tag in $TAGS; do
echo "Processing tag: $tag"
check_code=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: JWT $TOKEN" \
"https://hub.docker.com/v2/repositories/$ORG/$REPO/tags/$tag/")
if [[ "$check_code" == "200" ]]; then
echo "Tag exists. Deleting…"
del_code=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
-H "Authorization: JWT $TOKEN" \
"https://hub.docker.com/v2/repositories/$ORG/$REPO/tags/$tag/")
if [[ "$del_code" == "204" || "$del_code" == "202" ]]; then
echo "Deleted: $tag"
else
echo "WARNING: Failed to delete $tag (HTTP $del_code). Continuing."
fi
elif [[ "$check_code" == "404" ]]; then
echo "Tag not found: $tag — skipping."
else
echo "WARNING: Could not verify tag $tag (HTTP $check_code). Skipping."
fi
done
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false