mirror of
https://github.com/JasonN3/build-container-installer.git
synced 2025-12-25 10:57:55 +01:00
delete old pr versions
This commit is contained in:
parent
68b73b71f8
commit
63df9f3f2d
1 changed files with 45 additions and 36 deletions
81
.github/workflows/clean_repo.yml
vendored
81
.github/workflows/clean_repo.yml
vendored
|
|
@ -27,46 +27,55 @@ jobs:
|
||||||
- name: Get list of packages
|
- name: Get list of packages
|
||||||
id: all_tags
|
id: all_tags
|
||||||
run: |
|
run: |
|
||||||
all_tags=$(curl -L \
|
curl -L \
|
||||||
-H "Accept: application/vnd.github+json" \
|
-H "Accept: application/vnd.github+json" \
|
||||||
-H "Authorization: Bearer ${{ github.token }}" \
|
-H "Authorization: Bearer ${{ github.token }}" \
|
||||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
"https://api.github.com/user/packages/container/build-container-installer/versions" | \
|
"https://api.github.com/user/packages/container/build-container-installer/versions" > all_packages.json
|
||||||
jq -r '.[] | .metadata.container.tags | .[]' | \
|
curl -L \
|
||||||
tr '\n' ' ')
|
-H "Accept: application/vnd.github+json" \
|
||||||
echo "tag_list=${all_tags}" >> $GITHUB_OUTPUT
|
-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
|
||||||
|
|
||||||
- name: Find Open PRs
|
prs = open("open_prs", "r")
|
||||||
id: open_prs
|
open_prs = prs.readlines()
|
||||||
run: |
|
open_prs = [x.strip() for x in open_prs]
|
||||||
open_prs=$(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' | \
|
|
||||||
tr '\n' ' ')
|
|
||||||
echo "open_prs=${open_prs}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Delete old PR packages
|
all_packages = open('all_packages.json')
|
||||||
run: |
|
data = json.load(all_packages)
|
||||||
echo "${{ steps.open_prs.outputs.open_prs }}" | tr ' ' '\n' > open_prs
|
|
||||||
for tag in ${{ steps.all_tags.outputs.tag_list }}
|
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
|
do
|
||||||
if [[ ${tag} =~ pr-.* ]]
|
curl -L \
|
||||||
then
|
-X DELETE \
|
||||||
if (grep -w ${tag} open_prs > /dev/null)
|
-H "Accept: application/vnd.github+json" \
|
||||||
then
|
-H "Authorization: Bearer ${{ secrets.PACKAGE_DELETER }}" \
|
||||||
echo "PR is still open"
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
else
|
https://api.github.com/user/packages/container/${{ github.repository }}/versions/${id}
|
||||||
echo "${tag}" >> delete_tags
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Tags to delete:"
|
|
||||||
cat delete_tags
|
|
||||||
|
|
||||||
|
|
||||||
#delete_old_branches:
|
#delete_old_branches:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue