Skip to content

Commit 92cb8bb

Browse files
authored
ci: comment a run-anywhere command to try the PR template artifact (#491)
* ci: comment a run-anywhere command to try the PR template artifact The PR Template Artifact job builds a scaffold with this PR's SDK tarballs but leaves it in the artifacts UI with no obvious way to consume it. Add a sticky PR comment that prints a self-contained command — gh run download of this run's artifact, unzip, then databricks apps init --template — with the run id, repo, artifact name, and output dir all baked in, so it can be pasted into any folder without a repo checkout. Reuses the existing github-script + marker-based upsert pattern (bundle-size, breaking-change). Adds job-level pull-requests: write for the comment. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> * ci: restore id-token permission on pr-template-artifact job Job-level permissions replace the top-level set rather than merging, so adding pull-requests: write dropped the top-level id-token: write that setup-jfrog-npm needs for its OIDC token (ACTIONS_ID_TOKEN_REQUEST_TOKEN unbound). List all three at the job level. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> * ci: skip try-template comment on fork PRs Fork PRs get a read-only GITHUB_TOKEN, so the github-script upsert would 403 and fail the whole pr-template-artifact job for an author who can't fix it. Guard the comment step with the same head-repo check bundle-size.yml and eval-pr-comment.yml already use. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> * ci: merge eval link and template command into one PR comment Combine the evals-monitor link and the try-this-template command into a single sticky comment with two delimited sections instead of two separate comments. Add a shared upsert-pr-comment-section.cjs helper: each workflow owns one section id and rewrites only its block, preserving the other's content (a push reruns the template section without wiping the eval link). The two writers are separated in time — the eval link posts instantly on PR open, the template command posts after the ~5-min build — so concurrent writes to the shared comment don't occur. Bundle-size and breaking-change comments are intentionally left separate for now. Replaces the single-purpose upsert-template-artifact-comment.cjs and rewires eval-pr-comment.yml onto the shared helper. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> * ci: fold eval link into the template artifact comment Drop the separate Eval PR Comment workflow and the section-merge helper; the pr-template-artifact job now posts a single comment containing both the evals-monitor link and the run-anywhere template command. One writer, one comment, plain marker-based upsert — no cross-workflow coordination. Tradeoff: the eval link now rides the ~5-min build and is skipped on docs-only PRs (where the artifact job doesn't run and evals are moot), instead of posting instantly on every PR open. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> * ci: give the PR-bot comment a header and parallel section titles Add an overall '🤖 AppKit PR bot' header and a '### 🔬 Run evals' title so the evals link matches the template section's heading instead of being a bare blockquote. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> --------- Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com> Co-authored-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
1 parent 1286fab commit 92cb8bb

3 files changed

Lines changed: 101 additions & 60 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Upserts the sticky "PR bot" comment built by the pr-template-artifact job:
3+
* the evals-monitor link plus the run-anywhere command to scaffold an app from
4+
* this PR's template artifact.
5+
*
6+
* Invoked via `actions/github-script`. The comment body is read from the file
7+
* at COMMENT_PATH (built by the workflow step so the run id, artifact name, and
8+
* output dir are interpolated from CI context). The body carries the marker
9+
* below as its first line, which we reuse to find and update an existing
10+
* comment instead of posting a new one on every push.
11+
*/
12+
13+
const fs = require("node:fs");
14+
15+
const MARKER = "<!-- pr-bot -->";
16+
17+
module.exports = async ({ github, context }) => {
18+
const { owner, repo } = context.repo;
19+
const issue_number = context.issue.number;
20+
const body = fs.readFileSync(process.env.COMMENT_PATH, "utf-8");
21+
22+
const comments = await github.paginate(github.rest.issues.listComments, {
23+
owner,
24+
repo,
25+
issue_number,
26+
per_page: 100,
27+
});
28+
const existing = comments.find((c) => c.body?.includes(MARKER));
29+
30+
if (existing) {
31+
await github.rest.issues.updateComment({
32+
owner,
33+
repo,
34+
comment_id: existing.id,
35+
body,
36+
});
37+
} else {
38+
await github.rest.issues.createComment({
39+
owner,
40+
repo,
41+
issue_number,
42+
body,
43+
});
44+
}
45+
};

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ jobs:
171171
runs-on:
172172
group: databricks-protected-runner-group
173173
labels: linux-ubuntu-latest
174+
# Job-level permissions REPLACE (not merge with) the top-level set, so all
175+
# three must be listed: pull-requests: write for the sticky comment step,
176+
# and id-token: write which setup-jfrog-npm needs for its OIDC token.
177+
permissions:
178+
contents: read
179+
pull-requests: write
180+
id-token: write
174181

175182
steps:
176183
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -226,6 +233,55 @@ jobs:
226233
name: appkit-template-${{ steps.version.outputs.version }}
227234
path: appkit-template-${{ steps.version.outputs.version }}.zip
228235

236+
# Build the PR-bot comment: a link to the evals-monitor app, plus a
237+
# self-contained, run-anywhere command that downloads this run's artifact
238+
# and scaffolds an app from it. Every value (run id, repo, artifact name,
239+
# output dir) is baked in so the reader can paste it into any folder — no
240+
# repo checkout or specific cwd required.
241+
- name: Build PR-bot comment
242+
env:
243+
VERSION: ${{ steps.version.outputs.version }}
244+
RUN_ID: ${{ github.run_id }}
245+
REPO: ${{ github.repository }}
246+
PR_NUMBER: ${{ github.event.pull_request.number }}
247+
run: |
248+
ARTIFACT="appkit-template-${VERSION}"
249+
OUT="appkit-pr-${PR_NUMBER}"
250+
EVALS_URL="https://evals-monitor-6051921418418893.staging.aws.databricksapps.com/prs/appkit/${PR_NUMBER}"
251+
{
252+
echo "<!-- pr-bot -->"
253+
echo "## 🤖 AppKit PR bot"
254+
echo ""
255+
echo "### 🔬 Run evals"
256+
echo ""
257+
echo "Start an eval for this PR from the evals-monitor app: [**Go to Evals Monitor →**](${EVALS_URL})"
258+
echo ""
259+
echo "### 📦 Try this PR's app template"
260+
echo ""
261+
echo "Scaffolds a new app from this PR's SDK build. Run it in **any** folder (requires the GitHub CLI — \`gh auth login\` — and the Databricks CLI):"
262+
echo ""
263+
echo '```bash'
264+
echo "gh run download ${RUN_ID} -R ${REPO} -n ${ARTIFACT} -D ${OUT} \\"
265+
echo " && unzip -o \"${OUT}/${ARTIFACT}.zip\" -d \"${OUT}\" \\"
266+
echo " && databricks apps init --template \"${OUT}\""
267+
echo '```'
268+
echo ""
269+
echo "The template pins \`@databricks/appkit\` and \`@databricks/appkit-ui\` to tarballs built from this branch, so the scaffolded app runs against this PR's code."
270+
} > pr-bot-comment.md
271+
272+
# Fork PRs get a read-only GITHUB_TOKEN, so commenting would 403 and fail
273+
# a job the author can't fix. Skip for forks — the command is still in the
274+
# job log above. Matches bundle-size.yml.
275+
- name: Upsert PR-bot comment
276+
if: github.event.pull_request.head.repo.full_name == github.repository
277+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
278+
env:
279+
COMMENT_PATH: pr-bot-comment.md
280+
with:
281+
script: |
282+
const upsert = require('./.github/scripts/upsert-pr-bot-comment.cjs');
283+
await upsert({ github, context });
284+
229285
docs-build:
230286
name: Docs Build
231287
needs: detect-changes

.github/workflows/eval-pr-comment.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)