Fix workflow YAML syntax, use jq instead of inline Python
build / build-and-push (push) Successful in 6s
build / build-and-push (push) Successful in 6s
This commit is contained in:
@@ -41,17 +41,14 @@ jobs:
|
|||||||
# sha256: 開頭的 digest 記錄不主動處理,避免誤刪或刪掉
|
# sha256: 開頭的 digest 記錄不主動處理,避免誤刪或刪掉
|
||||||
# 還在被引用的 manifest。
|
# 還在被引用的 manifest。
|
||||||
run: |
|
run: |
|
||||||
VERSIONS=$(curl -s -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
|
curl -s -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
|
||||||
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing" \
|
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing" \
|
||||||
| python3 -c "
|
| jq -r '[.[] | select(.version | test("^[0-9a-f]{40}$"))] | sort_by(.created_at) | reverse | .[5:] | .[].id' \
|
||||||
import json, sys, re
|
> /tmp/prune-ids.txt
|
||||||
data = json.load(sys.stdin)
|
|
||||||
sha_versions = [v for v in data if re.fullmatch(r'[0-9a-f]{40}', v['version'])]
|
while read -r id; do
|
||||||
sha_versions.sort(key=lambda v: v['created_at'], reverse=True)
|
[ -z "$id" ] && continue
|
||||||
print('\n'.join(str(v['id']) for v in sha_versions[5:]))
|
|
||||||
")
|
|
||||||
for id in $VERSIONS; do
|
|
||||||
echo "Deleting package version id=$id"
|
echo "Deleting package version id=$id"
|
||||||
curl -s -X DELETE -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
|
curl -s -X DELETE -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
|
||||||
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing/$id"
|
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing/$id"
|
||||||
done
|
done < /tmp/prune-ids.txt
|
||||||
|
|||||||
Reference in New Issue
Block a user