backfill-release.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. name: Backfill Release Assets
  2. # One-off repair: upload artifacts from an existing run that the release
  3. # job missed (e.g. r20, where download-artifact truncation dropped 96
  4. # AnyKernel3 zips). Delete this file once no longer needed.
  5. on:
  6. workflow_dispatch:
  7. inputs:
  8. run_id:
  9. description: "Source run ID holding the artifacts"
  10. required: true
  11. type: string
  12. tag:
  13. description: "Existing release tag to upload into"
  14. required: true
  15. type: string
  16. permissions:
  17. contents: write
  18. actions: read
  19. jobs:
  20. backfill:
  21. runs-on: ubuntu-latest
  22. env:
  23. GH_TOKEN: ${{ github.token }}
  24. steps:
  25. - name: Upload missing AnyKernel3 zips to release
  26. run: |
  27. set -euo pipefail
  28. REPO="${{ github.repository }}"
  29. RUN_ID="${{ inputs.run_id }}"
  30. TAG="${{ inputs.tag }}"
  31. gh api "repos/$REPO/actions/runs/$RUN_ID/artifacts?per_page=100" --paginate --jq '.artifacts[] | select(.name | endswith("-AnyKernel3")) | "\(.id) \(.name)"' > /tmp/all.txt
  32. echo "AnyKernel3 artifacts in run: $(wc -l < /tmp/all.txt)"
  33. RID=$(gh api "repos/$REPO/releases/tags/$TAG" --jq '.id')
  34. gh api "repos/$REPO/releases/$RID/assets?per_page=100" --paginate --jq '.[].name' | sed 's/\.zip$//' | sort -u > /tmp/have.txt
  35. : > /tmp/missing.txt
  36. while read -r id name; do
  37. grep -qx "$name" /tmp/have.txt || echo "$id $name" >> /tmp/missing.txt
  38. done < /tmp/all.txt
  39. echo "Missing from $TAG: $(wc -l < /tmp/missing.txt)"
  40. [ -s /tmp/missing.txt ] || { echo "Nothing to backfill."; exit 0; }
  41. mkdir -p backfill
  42. failed=0
  43. while read -r id name; do
  44. echo "=== $name ==="
  45. rm -rf "backfill/$name" "backfill/$name.zip"
  46. ok=false
  47. for attempt in 1 2 3; do
  48. if gh api "repos/$REPO/actions/artifacts/$id/zip" > "backfill/dl.zip" && \
  49. unzip -q -o "backfill/dl.zip" -d "backfill/$name" && \
  50. ( cd "backfill/$name" && zip -r -q -9 "../$name.zip" . ) && \
  51. gh release upload "$TAG" "backfill/$name.zip" --clobber --repo "$REPO"; then
  52. ok=true
  53. break
  54. fi
  55. echo "Attempt $attempt/3 failed for: $name" >&2
  56. sleep 10
  57. done
  58. if [ "$ok" = false ]; then
  59. echo "ERROR: giving up on $name" >&2
  60. failed=1
  61. fi
  62. rm -rf "backfill/$name" "backfill/$name.zip" backfill/dl.zip
  63. done < /tmp/missing.txt
  64. have_kernels=$(gh api "repos/$REPO/releases/$RID/assets?per_page=100" --paginate --jq '.[].name' | grep -c 'AnyKernel3\.zip$')
  65. echo "AnyKernel3 zips now on $TAG: $have_kernels (run holds $(wc -l < /tmp/all.txt))"
  66. exit "$failed"