Skip to content

Commit 9ba1910

Browse files
committed
ci(observability-map): scan head vs merge base and upsert a sticky PR comment
1 parent 82fac3e commit 9ba1910

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: 🗺️ Observability Map
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
paths:
7+
- "apps/webapp/app/routes/**"
8+
- "internal-packages/observability-map/**"
9+
10+
concurrency:
11+
group: observability-map-${{ github.event.pull_request.number }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
pull-requests: write
17+
18+
jobs:
19+
report:
20+
runs-on: warp-ubuntu-latest-x64-4x
21+
# Fork PRs get a read-only token, so the comment cannot post. Skipping the job beats a red x.
22+
if: github.event.pull_request.head.repo.full_name == github.repository
23+
steps:
24+
- name: ⬇️ Checkout repo
25+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
26+
with:
27+
fetch-depth: 0
28+
persist-credentials: false
29+
30+
- name: ⎔ Setup pnpm
31+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
32+
with:
33+
version: 10.33.2
34+
35+
- name: ⎔ Setup node
36+
uses: WarpBuilds/setup-node@bc639b444d583175926b588962199c247d23e8d3 # v6
37+
with:
38+
node-version: 24.18.0
39+
cache: "pnpm"
40+
41+
- name: 📥 Download deps
42+
run: pnpm install --frozen-lockfile
43+
44+
- name: 🔎 Scan head
45+
run: |
46+
pnpm --filter @internal/observability-map exec tsx src/cli.ts --json --no-write > /tmp/head.json
47+
48+
- name: 🔎 Scan base with the head's scanner
49+
run: |
50+
if git worktree add /tmp/base-tree ${{ github.event.pull_request.base.sha }} \
51+
&& pnpm --filter @internal/observability-map exec tsx src/cli.ts --json --no-write \
52+
--routes=/tmp/base-tree/apps/webapp/app/routes > /tmp/base.json; then
53+
:
54+
else
55+
echo "-" > /tmp/base.json || true
56+
echo "base scan failed or the worktree could not be added; falling back to no base" >&2
57+
fi
58+
59+
- name: 📝 Render comment
60+
run: |
61+
if [ "$(cat /tmp/base.json)" = "-" ]; then
62+
pnpm --filter @internal/observability-map exec tsx src/report/prCommentCli.ts /tmp/head.json - > /tmp/comment.md
63+
else
64+
pnpm --filter @internal/observability-map exec tsx src/report/prCommentCli.ts /tmp/head.json /tmp/base.json > /tmp/comment.md
65+
fi
66+
67+
- name: 💬 Upsert PR comment
68+
env:
69+
GH_TOKEN: ${{ github.token }}
70+
PR_NUMBER: ${{ github.event.pull_request.number }}
71+
run: |
72+
existing=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
73+
--jq '[.[] | select(.body | startswith("<!-- observability-map-report -->"))][0].id // empty')
74+
if [ -n "$existing" ]; then
75+
gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${existing}" -F body=@/tmp/comment.md
76+
else
77+
gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -F body=@/tmp/comment.md
78+
fi

0 commit comments

Comments
 (0)