From 48eb82ebe1b935676b7579b48475a4b838e63739 Mon Sep 17 00:00:00 2001 From: MYSOREZ <69631925+MYSOREZ@users.noreply.github.com> Date: Wed, 22 Jul 2026 22:44:11 +0300 Subject: [PATCH] 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). --- .github/workflows/cleanup-artifacts.yml | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/cleanup-artifacts.yml diff --git a/.github/workflows/cleanup-artifacts.yml b/.github/workflows/cleanup-artifacts.yml new file mode 100644 index 0000000..832b3e0 --- /dev/null +++ b/.github/workflows/cleanup-artifacts.yml @@ -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