-
Notifications
You must be signed in to change notification settings - Fork 1
49 lines (39 loc) · 1.54 KB
/
delete-image.yml
File metadata and controls
49 lines (39 loc) · 1.54 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
name: Delete Docker Images
concurrency: ${{ github.event.inputs.ref_name || github.event.ref }}
on:
workflow_dispatch:
inputs:
ref_name:
description: Deleted ref
type: string
required: true
delete:
env:
DOCKER_REGISTRY_URL: registry.digitalocean.com
DOCKER_REPOSITORY: redberry
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set environment variables
run: |
echo "REPOSITORY_NAME=$(cut -d '/' -f 2 <<< $GITHUB_REPOSITORY)" >> $GITHUB_ENV
if [ -n "${{ github.event.inputs.ref_name }}" ]
then
REF_NAME="${{ github.event.inputs.ref_name }}"
else
REF_NAME="${{ github.event.ref }}"
fi
echo "REF_NAME=$REF_NAME" >> $GITHUB_ENV
echo "REF_SLUG=$(sed 's/[^0-9a-zA-Z]/-/g' <<< $REF_NAME)" >> $GITHUB_ENV
- uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DO_API_KEY }}
- name: Delete run images
run: |
manifests_to_delete=$(doctl registry repository list-tags $REPOSITORY_NAME-run | grep $REF_SLUG | rev | cut -d ' ' -f 1 | rev | tr '\n' ' ')
doctl registry repository delete-manifest -f $REPOSITORY_NAME-run $manifests_to_delete || true
- name: Delete build images
run: |
manifests_to_delete=$(doctl registry repository list-tags $REPOSITORY_NAME-build | grep $REF_SLUG | rev | cut -d ' ' -f 1 | rev | tr '\n' ' ')
doctl registry repository delete-manifest -f $REPOSITORY_NAME-build $manifests_to_delete || true