Fix deploy preview workflow: permissions, keep_files, cleanup #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Trace Viewer Demo | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: pages-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: >- | |
| github.event_name == 'push' | |
| || (github.event_name == 'pull_request' && github.event.action != 'closed') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Build demo trace | |
| run: cargo run --example realistic_workload | |
| timeout-minutes: 5 | |
| - name: Assemble site | |
| run: | | |
| mkdir -p _site | |
| cp dial9-tokio-telemetry/trace_viewer.html _site/trace_viewer.html | |
| cp realistic_trace.bin _site/demo.bin | |
| cp demo/index.html _site/index.html | |
| - name: Deploy (main) | |
| if: github.ref == 'refs/heads/main' | |
| uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./_site | |
| keep_files: true | |
| - name: Deploy (PR preview) | |
| if: github.event_name == 'pull_request' | |
| uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./_site | |
| destination_dir: pr/${{ github.event.number }} | |
| - name: Comment PR with preview link | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const url = `https://${context.repo.owner}.github.io/${context.repo.repo}/pr/${context.issue.number}/`; | |
| const body = `🔍 **Trace Viewer Preview:** ${url}`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| ...context.repo, issue_number: context.issue.number | |
| }); | |
| const existing = comments.find(c => c.body.includes('Trace Viewer Preview')); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body }); | |
| } else { | |
| await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body }); | |
| } | |
| cleanup-preview: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' && github.event.action == 'closed' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: gh-pages | |
| - name: Remove PR preview | |
| run: | | |
| if [ -d "pr/${{ github.event.number }}" ]; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git rm -rf "pr/${{ github.event.number }}" | |
| git commit -m "Clean up PR #${{ github.event.number }} preview" | |
| git push | |
| fi |