Skip to content

Commit 84516b9

Browse files
Copilotrcoh
andcommitted
Fix deploy preview: add pull-requests:write permission, keep_files for main deploy, PR cleanup job
PR #7 failed because the workflow only had `contents: write` permission but the PR comment step requires `pull-requests: write`. Additional fixes: - Add `keep_files: true` to main deploy so PR preview subdirectories are not deleted when main is deployed - Add `cleanup-preview` job to remove PR preview directories when PRs are closed/merged - Add `?trace=URL` auto-load parameter to trace_viewer.html - Add demo/index.html redirect for the deployed demo Co-authored-by: rcoh <492903+rcoh@users.noreply.github.com>
1 parent d5adf45 commit 84516b9

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

.github/workflows/pages.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Deploy Trace Viewer Demo
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened, closed]
8+
branches: [main]
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
concurrency:
15+
group: pages-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
deploy:
20+
runs-on: ubuntu-latest
21+
if: >-
22+
github.event_name == 'push'
23+
|| (github.event_name == 'pull_request' && github.event.action != 'closed')
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: dtolnay/rust-toolchain@stable
28+
29+
- uses: Swatinem/rust-cache@v2
30+
31+
- name: Build demo trace
32+
run: cargo run --example realistic_workload
33+
timeout-minutes: 5
34+
35+
- name: Assemble site
36+
run: |
37+
mkdir -p _site
38+
cp dial9-tokio-telemetry/trace_viewer.html _site/trace_viewer.html
39+
cp realistic_trace.bin _site/demo.bin
40+
cp demo/index.html _site/index.html
41+
42+
- name: Deploy (main)
43+
if: github.ref == 'refs/heads/main'
44+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
45+
with:
46+
github_token: ${{ secrets.GITHUB_TOKEN }}
47+
publish_dir: ./_site
48+
keep_files: true
49+
50+
- name: Deploy (PR preview)
51+
if: github.event_name == 'pull_request'
52+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
53+
with:
54+
github_token: ${{ secrets.GITHUB_TOKEN }}
55+
publish_dir: ./_site
56+
destination_dir: pr/${{ github.event.number }}
57+
58+
- name: Comment PR with preview link
59+
if: github.event_name == 'pull_request'
60+
uses: actions/github-script@v7
61+
with:
62+
script: |
63+
const url = `https://${context.repo.owner}.github.io/${context.repo.repo}/pr/${context.issue.number}/`;
64+
const body = `🔍 **Trace Viewer Preview:** ${url}`;
65+
const { data: comments } = await github.rest.issues.listComments({
66+
...context.repo, issue_number: context.issue.number
67+
});
68+
const existing = comments.find(c => c.body.includes('Trace Viewer Preview'));
69+
if (existing) {
70+
await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body });
71+
} else {
72+
await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body });
73+
}
74+
75+
cleanup-preview:
76+
runs-on: ubuntu-latest
77+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
78+
permissions:
79+
contents: write
80+
steps:
81+
- uses: actions/checkout@v4
82+
with:
83+
ref: gh-pages
84+
85+
- name: Remove PR preview
86+
run: |
87+
if [ -d "pr/${{ github.event.number }}" ]; then
88+
git config user.name "github-actions[bot]"
89+
git config user.email "github-actions[bot]@users.noreply.github.com"
90+
git rm -rf "pr/${{ github.event.number }}"
91+
git commit -m "Clean up PR #${{ github.event.number }} preview"
92+
git push
93+
fi

demo/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!doctype html>
2+
<meta http-equiv="refresh" content="0;url=trace_viewer.html?trace=demo.bin">
3+
<a href="trace_viewer.html?trace=demo.bin">Open Trace Viewer Demo</a>

dial9-tokio-telemetry/trace_viewer.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,21 @@
19791979
if (trace) renderAll();
19801980
});
19811981

1982+
// ── Auto-load trace from ?trace=URL parameter ──
1983+
(function autoLoadFromUrl() {
1984+
const traceUrl = new URLSearchParams(location.search).get("trace");
1985+
if (!traceUrl) return;
1986+
dropZone.innerHTML = "Loading trace…";
1987+
fetch(traceUrl)
1988+
.then(r => { if (!r.ok) throw new Error(r.status); return r.arrayBuffer(); })
1989+
.then(buf => {
1990+
trace = parseTrace(buf);
1991+
processTrace();
1992+
showViewer(traceUrl.split("/").pop());
1993+
})
1994+
.catch(err => { dropZone.innerHTML = "Failed to load trace: " + err.message; });
1995+
})();
1996+
19821997
// ── Legend (inline in toolbar area) ──
19831998
(function addLegend() {
19841999
const tb = document.getElementById("toolbar");

0 commit comments

Comments
 (0)