-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (77 loc) · 2.85 KB
/
cleanup-staging-packages.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
name: 👋 staging ⬢🗑️
on:
pull_request:
types:
- closed
workflow_dispatch:
inputs:
pr-number:
description: 'Target PR number'
required: true
type: number
defaults:
run:
# https://pubs.opengroup.org/onlinepubs/009695399/utilities/set.html
shell: bash -Ceuxo pipefail {0}
jobs:
get-meta:
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
pr-number: ${{ steps.get-meta.outputs.pr-number }}
steps:
- name: Get metadata
id: get-meta
run: |
if [ '${{ github.event_name }}' == 'pull_request' ]; then
echo 'pr-number=${{ github.event.pull_request.number }}' | tee -a "$GITHUB_OUTPUT"
else
echo 'pr-number=${{ inputs.pr-number }}' | tee -a "$GITHUB_OUTPUT"
fi
minimize-old-comments:
needs: [get-meta]
uses: ./.github/workflows/minimize-staging-deploy-comments.yml
with:
pr-number: ${{ fromJSON(needs.get-meta.outputs.pr-number) }}
ghcr:
needs: [get-meta]
runs-on: ubuntu-24.04
if: (github.event_name != 'pull_request') || (github.event.pull_request.merged == true)
timeout-minutes: 15
steps:
- name: Inspect the PR published package
id: inspect-package
run: |
gh api --paginate \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/users/kachick/packages/container/home/versions \
--jq '.[] | select(.metadata.container.tags[] | match("^pr-${{ needs.get-meta.outputs.pr-number }}-")).id' | \
ruby -e 'puts STDIN.each_line.map(&:chomp).join(",")' | \
xargs --no-run-if-empty --replace='{joined_ids}' echo -n 'package-version-ids={joined_ids}' | tee -a "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0
if: ${{ steps.inspect-package.outputs.package-version-ids }}
with:
owner: ${{ github.repository_owner }}
package-name: 'home'
package-type: 'container'
token: ${{ github.token }}
package-version-ids: ${{ steps.inspect-package.outputs.package-version-ids }}
- name: Prepare git to run gh commands
if: ${{ steps.inspect-package.outputs.package-version-ids }}
uses: actions/checkout@v4
- name: Post comments to the PR
if: ${{ steps.inspect-package.outputs.package-version-ids }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
(
cat <<'EOF'
🤖 removed 🗑️ staging ⬢ from ghcr.io
```plaintext
${{ steps.inspect-package.outputs.package-version-ids }}
```
EOF
) | gh pr comment '${{ needs.get-meta.outputs.pr-number }}' --body-file -