fix(ci): no 404 window when a test build is replaced; merged PRs keep their build until Preview has it (#2635)

* fix(ci): a test build's files outlive the catalog that names them, and a merged PR's build lasts until Preview carries it

- A new push's PR release keeps the previous push's files until the catalog names the new
  ones, then five minutes more, so a download started from the old catalog still finds its APK.
  The app also reloads the catalog and retries once when a test build's download fails.
- Closing a PR without merging still deletes its test build. A merged PR's build stays, and
  stays listed, until the newest Preview build was built from a main holding the merge, or
  three days pass (docs-only merges build no Preview). Main's build, the PR cleanup and the
  sweep share one script for this.

* fix(ci): name the current push's APK in the catalog and prune nothing it still names

* fix(ci): only a Preview with every APK carries a merge or is offered

* fix(ci): publish no preview while none has every APK

* test(ci): build_catalog publishes no preview while its APKs are uploading
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-14 23:40:08 -05:00
1 parent 059711cfe1
commit 6f7d7f827f
9 files changed
+336 -72

No files matched your search

+42 -6
View File
@@ -226,6 +226,8 @@ jobs:
publish:
needs: [authorize, sign]
runs-on: ubuntu-24.04
outputs:
keep: ${{ steps.publish.outputs.keep }}
permissions:
actions: read
contents: read
@@ -322,12 +324,8 @@ jobs:
cp pr-packs/* signed/ 2>/dev/null || true
gh release upload "$tag" signed/* -R "$repo" --clobber
gh release edit "$tag" -R "$repo" --title "PR #$PR_NUMBER" --notes "$notes" --prerelease
keep=$(cd signed && ls | jq -R . | jq -sc .)
gh api "repos/$repo/releases/tags/$tag" |
jq -r --argjson keep "$keep" '.assets[] | select(.name as $n | $keep | index($n) | not) | .id' |
while IFS= read -r id; do
gh api --method DELETE "repos/$repo/releases/assets/$id" >/dev/null
done
# The previous push's files stay until the catalog names these (the prune job), so a download started from the old catalog still finds its APK.
echo "keep=$(cd signed && ls | jq -R . | jq -sc .)" >> "$GITHUB_OUTPUT"
published=$(gh release view "$tag" -R "$repo" --json tagName,assets)
jq -e --arg tag "$tag" '.tagName == $tag and (.assets | length) > 0' <<<"$published" >/dev/null
@@ -417,3 +415,41 @@ jobs:
if: ${{ always() && needs.publish.result != 'skipped' }}
uses: ./.github/workflows/update-catalog.yml
secrets: inherit
prune:
needs: [authorize, publish, catalog]
if: ${{ always() && needs.publish.result == 'success' && needs.catalog.result == 'success' }}
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/create-github-app-token@v2
id: ci-token
with:
app-id: ${{ vars.DROIDDECK_CI_APP_ID }}
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
owner: Droid-Deck
repositories: DroidDeck-CI
- name: Remove the previous push's files
env:
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
PR_NUMBER: ${{ needs.authorize.outputs.pr_number }}
KEEP: ${{ needs.publish.outputs.keep }}
run: |
set -euo pipefail
repo=Droid-Deck/DroidDeck-CI
tag="pr-$PR_NUMBER"
# An app that read the catalog just before it changed may still be starting that download.
sleep 300
# Delete nothing the published catalog still names.
named=$(gh api -H "Accept: application/vnd.github.raw+json" "repos/$repo/contents/catalog.json?ref=main" |
jq -c --argjson pr "$PR_NUMBER" '[.tests[] | select(.pr == $pr) | .apks[].name]')
stale=$(jq -nr --argjson named "$named" --argjson keep "$KEEP" '$named - $keep | join(" ")')
if [ -n "$stale" ]; then
echo "::warning::The catalog still names $stale; keeping every file of $tag"
exit 0
fi
gh api "repos/$repo/releases/tags/$tag" |
jq -r --argjson keep "$KEEP" '.assets[] | select(.name as $n | $keep | index($n) | not) | .id' |
while IFS= read -r id; do
gh api --method DELETE "repos/$repo/releases/assets/$id" >/dev/null
done