-
Notifications
You must be signed in to change notification settings - Fork 157
32 lines (28 loc) · 1.09 KB
/
delete-pr-image.yml
File metadata and controls
32 lines (28 loc) · 1.09 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
name: "Delete Docker image on PR close"
on:
pull_request:
types: [closed]
jobs:
delete-pr-image:
# Only run for PRs that had the docker_image_artifacts label
if: contains(github.event.pull_request.labels.*.name, 'docker_image_artifacts')
runs-on: ubuntu-latest
permissions:
packages: write # required to delete GHCR container versions
contents: read
steps:
- name: Sanitize branch name to match image tag
id: sanitize
env:
PR_REF: ${{ github.event.pull_request.head.ref }}
run: |
TAG="${PR_REF//\//_}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Delete image by tag from GHCR
env:
TAG: ${{ steps.sanitize.outputs.tag }}
run: |
gh api "orgs/DataDog/packages/container/dd-trace-dotnet%2Fdd-trace-dotnet/versions" \
--jq ".[] | select(.metadata.container.tags[]? == \"${TAG}\") | .id" \
| xargs -r -I {} gh api "orgs/DataDog/packages/container/dd-trace-dotnet%2Fdd-trace-dotnet/versions/{}" -X DELETE
echo "Deleted version with tag: ${TAG}"