mirror of
https://github.com/JasonN3/build-container-installer.git
synced 2025-12-25 02:47:56 +01:00
Clean repo of old packages (#92)
This commit is contained in:
parent
5d818dc7f1
commit
7311a1d4c8
2 changed files with 135 additions and 11 deletions
134
.github/workflows/clean_repo.yml
vendored
134
.github/workflows/clean_repo.yml
vendored
|
|
@ -1,15 +1,16 @@
|
||||||
|
name: Clean Container Registry
|
||||||
on:
|
on:
|
||||||
#schedule:
|
schedule:
|
||||||
# - cron: '39 21 * * *'
|
- cron: '0 21 * * 0'
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-container:
|
delete_untagged:
|
||||||
name: Delete untagged packages
|
name: Delete Untagged Packages
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Dlete Untagged packages
|
- name: Delete Untagged Packages
|
||||||
uses: Chizkiyahu/delete-untagged-ghcr-action@v3
|
uses: Chizkiyahu/delete-untagged-ghcr-action@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.PACKAGE_DELETER }}
|
token: ${{ secrets.PACKAGE_DELETER }}
|
||||||
|
|
@ -17,3 +18,126 @@ jobs:
|
||||||
repository: ${{ github.repository }}
|
repository: ${{ github.repository }}
|
||||||
untagged_only: true
|
untagged_only: true
|
||||||
owner_type: user
|
owner_type: user
|
||||||
|
|
||||||
|
delete_old_pr:
|
||||||
|
name: Delete Old PR Packages
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: read
|
||||||
|
steps:
|
||||||
|
- name: Delete Old PR Packages
|
||||||
|
id: all_tags
|
||||||
|
run: |
|
||||||
|
curl -L \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${{ github.token }}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"https://api.github.com/user/packages/container/build-container-installer/versions" > all_packages.json
|
||||||
|
curl -L \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${{ github.token }}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/pulls | \
|
||||||
|
jq -r '.[] | select(.state == "open") | .number' | \
|
||||||
|
sed 's/^/pr-/g' > open_prs
|
||||||
|
cat << EOF | python
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
prs = open("open_prs", "r")
|
||||||
|
open_prs = prs.readlines()
|
||||||
|
open_prs = [x.strip() for x in open_prs]
|
||||||
|
|
||||||
|
all_packages = open('all_packages.json')
|
||||||
|
data = json.load(all_packages)
|
||||||
|
|
||||||
|
delete_versions = open("delete_versions", "w")
|
||||||
|
|
||||||
|
for i in data:
|
||||||
|
delete = True
|
||||||
|
for tag in i['metadata']['container']['tags']:
|
||||||
|
if not re.match('pr-.*', tag):
|
||||||
|
delete = False
|
||||||
|
continue
|
||||||
|
if tag in open_prs:
|
||||||
|
delete = False
|
||||||
|
if delete:
|
||||||
|
print("delete", i['id'])
|
||||||
|
delete_versions.write(str(i['id']))
|
||||||
|
delete_versions.write("\n")
|
||||||
|
print(i['metadata']['container']['tags'])
|
||||||
|
EOF
|
||||||
|
|
||||||
|
for id in $(cat delete_versions)
|
||||||
|
do
|
||||||
|
curl -L \
|
||||||
|
-X DELETE \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${{ secrets.PACKAGE_DELETER }}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
https://api.github.com/user/packages/container/build-container-installer/versions/${id}
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
delete_old_branches:
|
||||||
|
name: Delete Old Branch Packages
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: read
|
||||||
|
steps:
|
||||||
|
- name: Delete Old Branch Packages
|
||||||
|
run: |
|
||||||
|
curl -L \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${{ github.token }}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"https://api.github.com/user/packages/container/build-container-installer/versions" > all_packages.json
|
||||||
|
curl -L \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${{ github.token }}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/branches | jq -r '.[].name' > branches
|
||||||
|
|
||||||
|
cat << EOF | python
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
branches_f = open("branches", "r")
|
||||||
|
branches = branches_f.readlines()
|
||||||
|
branches = [x.strip() for x in branches]
|
||||||
|
|
||||||
|
all_packages_f = open('all_packages.json')
|
||||||
|
data = json.load(all_packages_f)
|
||||||
|
|
||||||
|
delete_versions = open("delete_versions", "w")
|
||||||
|
|
||||||
|
for i in data:
|
||||||
|
delete = True
|
||||||
|
for tag in i['metadata']['container']['tags']:
|
||||||
|
if re.match('v[0-9]+\\\.[0-9]+\\\.[0-9]+', tag):
|
||||||
|
delete = False
|
||||||
|
continue
|
||||||
|
if re.match('pr-.*', tag):
|
||||||
|
delete = False
|
||||||
|
continue
|
||||||
|
if tag in branches:
|
||||||
|
delete = False
|
||||||
|
continue
|
||||||
|
if tag == "latest":
|
||||||
|
delete = False
|
||||||
|
if delete:
|
||||||
|
print("delete", i['id'])
|
||||||
|
delete_versions.write(str(i['id']))
|
||||||
|
delete_versions.write("\n")
|
||||||
|
print(i['metadata']['container']['tags'])
|
||||||
|
EOF
|
||||||
|
|
||||||
|
for id in $(cat delete_versions)
|
||||||
|
do
|
||||||
|
curl -L \
|
||||||
|
-X DELETE \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${{ secrets.PACKAGE_DELETER }}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
https://api.github.com/user/packages/container/build-container-installer/versions/${id}
|
||||||
|
done
|
||||||
|
|
|
||||||
2
.github/workflows/stale.yml
vendored
2
.github/workflows/stale.yml
vendored
|
|
@ -7,7 +7,7 @@ name: Mark stale issues and pull requests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '39 21 * * *'
|
- cron: '0 21 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue