-
Notifications
You must be signed in to change notification settings - Fork 8
83 lines (69 loc) · 2.6 KB
/
delete-release.yml
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Delete-Release
on:
release:
types: [deleted] # should be deleted
jobs:
purge-image:
name: Delete image from ghcr.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set output
id: vars
run: echo "tag"="{${GITHUB_REF#refs/*/}}" >> $GITHUB_OUTPUT
- name: Check output
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}
echo ${{github.event.pull_request.number}}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# Unfortunately accessing the repo with personal access token is not possible
# Workaround: disable 2FA and user password instead of TOKEN
- name: Delete docker tag
run: |
ORGANIZATION="encointer"
IMAGE="encointer-client-notee"
TAG="${{ steps.vars.outputs.tag }}"
login_data() {
cat <<EOF
{
"username": "${{ secrets.DOCKER_HUB_USERNAME }}",
"password": "${{ secrets.DOCKERHUB_PASSWORD }}"
}
EOF
}
TOKEN=`curl -s -H "Content-Type: application/json" -X POST -d "$(login_data)" "https://hub.docker.com/v2/users/login/" | jq -r .token`
curl "https://hub.docker.com/v2/repositories/${ORGANIZATION}/${IMAGE}/tags/${TAG}/" \
-X DELETE \
-H "Authorization: JWT ${TOKEN}"
- name: Delete docker tag node
run: |
ORGANIZATION="encointer"
IMAGE="encointer-node-notee"
TAG="${{ steps.vars.outputs.tag }}"
login_data() {
cat <<EOF
{
"username": "${{ secrets.DOCKER_HUB_USERNAME }}",
"password": "${{ secrets.DOCKERHUB_PASSWORD }}"
}
EOF
}
TOKEN=`curl -s -H "Content-Type: application/json" -X POST -d "$(login_data)" "https://hub.docker.com/v2/users/login/" | jq -r .token`
curl "https://hub.docker.com/v2/repositories/${ORGANIZATION}/${IMAGE}/tags/${TAG}/" \
-X DELETE \
-H "Authorization: JWT ${TOKEN}"
- name: Delete tag as well
uses: dev-drprasad/[email protected]
with:
delete_release: false # it is triggered by release deletion
tag_name: ${{ steps.vars.outputs.tag }} # tag name to delete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}