name: PR Release Cleanup run-name: remove PR #${{ github.event.pull_request.number }}'s test build # A merged or closed PR's test build leaves DroidDeck-CI, so the app's Updates page stops offering it # (a merged fix is in the next Preview). pull_request_target for the publisher app's secrets; nothing # from the PR is checked out or run. on: pull_request_target: types: [ closed ] branches: [ main ] permissions: contents: read pull-requests: read concurrency: group: pr-release-${{ github.event.pull_request.number }} cancel-in-progress: false queue: max jobs: cleanup: runs-on: ubuntu-24.04 timeout-minutes: 5 steps: - name: Check the current PR state id: state env: GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | set -euo pipefail state=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" --jq .state) echo "closed=$([ "$state" = closed ] && echo true || echo false)" >> "$GITHUB_OUTPUT" # A token of the org's "DroidDeck CI Publisher" app, as build.yml's announce job uses. - uses: actions/create-github-app-token@v2 if: ${{ steps.state.outputs.closed == 'true' }} 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: Delete the test build if: ${{ steps.state.outputs.closed == 'true' }} env: GH_TOKEN: ${{ steps.ci-token.outputs.token }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | set -euo pipefail found=0 for tag in "pr-$PR_NUMBER" "pr-$PR_NUMBER.0"; do if gh release view "$tag" -R Droid-Deck/DroidDeck-CI >/dev/null 2>&1; then gh release delete "$tag" -R Droid-Deck/DroidDeck-CI --yes --cleanup-tag echo "Deleted $tag" found=1 fi done [ "$found" = 1 ] || echo "No test build for PR #$PR_NUMBER" - uses: actions/checkout@v4 if: ${{ steps.state.outputs.closed == 'true' }} with: ref: main persist-credentials: false - name: Retire the Discord PR announcement if: ${{ steps.state.outputs.closed == 'true' }} env: WEBHOOK: ${{ secrets.DISCORD_PR_BUILDS_WEBHOOK }} GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} run: python3 tools/release/pr_discord.py retire catalog: needs: cleanup if: ${{ always() }} uses: ./.github/workflows/update-catalog.yml secrets: inherit