Skip to content

Stop ACP tool spinners after completed turns #1028

Stop ACP tool spinners after completed turns

Stop ACP tool spinners after completed turns #1028

name: Demo preview cleanup
# When a PR closes (merged or not), remove its demo preview from the
# machine-managed demo-previews branch and redeploy Pages so /demo/pr-<n>/ and
# /demo/pr-<n>-preview/ stop serving. Same-repo PRs only: fork PRs never had a
# preview, and their closed-event token is read-only anyway. Like pull_request
# generally, the workflow definition is read from the base branch, so a fork
# head cannot alter this cleanup.
on:
pull_request:
types: [closed]
permissions:
contents: write
pages: write
id-token: write
jobs:
cleanup:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ${{ vars.SELF_HOSTED_CHECKS || 'ubuntu-latest' }}
outputs:
removed: ${{ steps.remove.outputs.removed }}
steps:
- id: remove
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
remote="https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"
if ! git clone --depth=1 --branch demo-previews "$remote" previews-branch 2>/dev/null; then
echo "No demo-previews branch — nothing to clean."
echo "removed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git -C previews-branch config user.name "github-actions[bot]"
git -C previews-branch config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ ! -d "previews-branch/pr-${PR}" ] && [ ! -d "previews-branch/pr-${PR}-preview" ]; then
echo "No preview for PR #${PR}."
echo "removed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
for target in "pr-${PR}" "pr-${PR}-preview"; do
if [ -d "previews-branch/${target}" ]; then
git -C previews-branch rm -r "$target"
fi
done
git -C previews-branch commit -m "demo preview: remove PR #${PR} (closed)"
git -C previews-branch push origin demo-previews
echo "removed=true" >> "$GITHUB_OUTPUT"
deploy:
needs: cleanup
if: needs.cleanup.outputs.removed == 'true'
uses: ./.github/workflows/pages.yml
with:
# The preview is already removed from demo-previews by this point; a failed
# deploy only delays it disappearing from the site, so don't fail the run.
tolerate-deploy-failure: true
secrets: inherit