This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
forked from iamseth/oracledb_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (89 loc) · 3.28 KB
/
pull-request-cleanup-manual.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: "[Manual] Pull Request Cleanup"
on:
workflow_dispatch:
inputs:
pattern:
description: |
Tags pattern filter
required: true
type: string
default: "rc.pr-"
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: write
packages: write
env:
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
PULL_REQUEST_BRANCH: ${{ github.head_ref }}
IMAGE_NAME: "ghcr.io/${{ github.repository }}"
PACKAGE_NAME: oracledb_exporter
PACKAGE_TYPE: container
USERNAME: ${{ github.repository_owner }}
jobs:
cleanup-ghcr:
runs-on: ubuntu-latest
name: "cleanup ghcr / ${{ github.event.inputs.pattern }}"
steps:
- name: Cleanup versions
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER: ${{ github.event.inputs.pattern }}
run: |
gh api \
-H "Accept: application/vnd.github+json" \
"/users/${{ env.USERNAME }}/packages/${{ env.PACKAGE_TYPE }}/${{ env.PACKAGE_NAME }}/versions" > versions.json
VERSIONS=$(jq -r '.[] | select(.metadata.container.tags[] | test("${{ env.FILTER }}")) | .id' versions.json)
for VERSION in $(echo -n "$VERSIONS")
do
TAG=$(jq -r \
--arg VERSION "$VERSION" \
'.[] | select(.id | tostring | test($VERSION)) | .metadata.container.tags | join(",")' \
versions.json
)
DIGEST=$(jq -r \
--arg VERSION "$VERSION" \
'.[] | select(.id | tostring | test($VERSION)) | .name' \
versions.json
)
echo "deleting ${IMAGE_NAME}:${TAG} with digest=${DIGEST}"
echo "deleting package PACKAGE_VERSION_ID=${VERSION}"
# https://github.com/cli/cli/issues/3937
echo -n | gh api \
--silent \
--method DELETE \
-H "Accept: application/vnd.github+json" \
"/users/${{ env.USERNAME }}/packages/${{ env.PACKAGE_TYPE }}/${{ env.PACKAGE_NAME }}/versions/$VERSION" \
--input -
done
cleanup-pre-releases:
runs-on: ubuntu-latest
name: "cleanup pre-releases / ${{ github.event.inputs.pattern }}"
steps:
- name: Cleanup releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER: ${{ github.event.inputs.pattern }}
run: |
gh api \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/releases" \
--jq='.[] | select(.prerelease=false) | select(.tag_name | test("${{ env.FILTER }}"))' > versions.json
VERSIONS=$(jq -r '.id' versions.json)
for VERSION in $(echo -n "$VERSIONS")
do
RELEASE=$(jq -r \
--arg VERSION "$VERSION" \
'select(.id | tostring | test($VERSION)) | .name' \
versions.json
)
echo "deleting release \"$RELEASE\" with RELEASE_ID=${VERSION}"
# https://github.com/cli/cli/issues/3937
echo -n | gh api \
--silent \
--method DELETE \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/releases/$VERSION" \
--input -
done