Add a standalone artifact-cleanup workflow (no build needed)
Seven "TurnProxy-apk" artifacts from July 4th (defaulted to 90-day retention, see the build-apk.yml fix) were still consuming ~261 MB of the account's shared 0.5 GB Actions storage quota, and manually deleting them one at a time isn't practical from here. This workflow does nothing but the cleanup itself -- no checkout, no Gradle, no APK build -- so it can be run on demand (workflow_dispatch) purely to free storage: for every branch this repo has ever built from, it keeps only the most recent run's artifacts and deletes every other run's, the same policy already in place on the GeneralsZH-Android-Port workflow. Best-effort per delete (a failure there must not fail the job).
This commit is contained in:
1 parent
b60925d6da
commit
48eb82ebe1
1 file changed
+36
@@ -0,0 +1,36 @@
|
||||
name: Cleanup Old Artifacts
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
cleanup:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Delete superseded artifacts across all branches
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
declare -A latest_run
|
||||
|
||||
while IFS=$'\t' read -r branch run_id; do
|
||||
[ -z "${branch}" ] && continue
|
||||
if [ -z "${latest_run[$branch]:-}" ] || [ "${run_id}" -gt "${latest_run[$branch]}" ]; then
|
||||
latest_run[$branch]="${run_id}"
|
||||
fi
|
||||
done < <(gh api "repos/${{ github.repository }}/actions/artifacts" --paginate \
|
||||
--jq '.artifacts[] | [(.workflow_run.head_branch // ""), .workflow_run.id] | @tsv')
|
||||
|
||||
gh api "repos/${{ github.repository }}/actions/artifacts" --paginate \
|
||||
--jq '.artifacts[] | [(.workflow_run.head_branch // ""), .workflow_run.id, .id] | @tsv' \
|
||||
| while IFS=$'\t' read -r branch run_id artifact_id; do
|
||||
[ -z "${branch}" ] && continue
|
||||
if [ "${run_id}" != "${latest_run[$branch]:-}" ]; then
|
||||
echo "Deleting old artifact ${artifact_id} (branch ${branch}, run ${run_id}, latest for that branch is ${latest_run[$branch]})"
|
||||
gh api -X DELETE "repos/${{ github.repository }}/actions/artifacts/${artifact_id}" || true
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user