-
Notifications
You must be signed in to change notification settings - Fork 766
56 lines (48 loc) · 1.48 KB
/
ghcr_purge.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
name: Purge PR images
on:
pull_request_target:
types:
- closed
paths:
- "**/*"
- "!.github/**" # Important: Exclude PRs related to .github from auto-run
- "!.github/workflows/**" # Important: Exclude PRs related to .github from auto-run
permissions:
contents: read
packages: write
jobs:
check_paths:
runs-on: ubuntu-latest
outputs:
githubfolder: ${{ steps.filter.outputs.githubfolder }}
steps:
- uses: actions/checkout@v4
- uses: dorny/[email protected]
id: filter
with:
filters: |
githubfolder:
- '.github/**'
purge-pr-package:
name: Delete images from ghcr.io when PR is closed
needs: check_paths
if: needs.check_paths.outputs.githubfolder == 'false'
runs-on: ubuntu-latest
steps:
- uses: chipkent/[email protected]
id: cleanup
continue-on-error: true
with:
package-name: ${{ github.event.repository.name }}
tag: pr-${{ github.event.pull_request.number }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/delete-package-versions@v5
if: job.steps.cleanup.status == success()
name: Delete untagged images from ghcr.io
continue-on-error: true
with:
package-name: "teslamate"
package-type: "container"
min-versions-to-keep: 0
delete-only-untagged-versions: "true"
token: ${{ secrets.GITHUB_TOKEN }}