-
Notifications
You must be signed in to change notification settings - Fork 1
35 lines (31 loc) · 1.18 KB
/
delete_PR_images.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
name: Remove obsolete PR images from registry
on:
pull_request:
types: [closed]
env:
PACKAGE_NAME: docker-event-monitor
jobs:
Delete_PR_image:
if: |
github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Get image ID of PR
id: version
run: |
curl -sSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/users/${{ github.repository_owner }}/packages/container/${{ env.PACKAGE_NAME }}/versions >> containerMeta.json ;
echo "VERSION_ID=$(jq -r '.[] | select(.metadata.container.tags[] == "pr-${{ github.event.pull_request.number }}").id' containerMeta.json)" >> "$GITHUB_ENV" ;
- name: Delete PR image
uses: actions/delete-package-versions@v5.0.0
if: ${{ env.VERSION_ID != '' }}
with:
package-version-ids: ${{ env.VERSION_ID }}
package-type: container
package-name: ${{ env.PACKAGE_NAME }}