Skip to content

ci: Comment the Vercel build log on PRs whose build fails - #1918

Closed
marcleblanc2 wants to merge 4 commits into
mainfrom
ci/vercel-build-failure-report
Closed

ci: Comment the Vercel build log on PRs whose build fails#1918
marcleblanc2 wants to merge 4 commits into
mainfrom
ci/vercel-build-failure-report

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Solution

  • On vercel.deployment.error comment the tail of the build log on the PR

  • On the next vercel.deployment.success, update that comment to ✅. The success path only reads Vercel's PR comments, it does not connect to Vercel

Token

  • VERCEL_TOKEN repo secret is a token scoped to the sourcegraph-docs project only, expiry 2026-12-10 (3 months, and beyond when the docs migration to MSP should be complete)

  • Vercel has no read-only scope for access tokens; project scope is the narrowest it offers

  • Fork PRs are skipped, and repository_dispatch runs the version of the workflow and script on main, so a malicious PR can't change the workflow to expose the token

Tested

Dry-run output (abridged)

❌ The Vercel build failed for this PR

Vercel only shows build logs to members of its team, so here is the end of the log.
Run npm run build locally to reproduce.

Build log

Running build in Cleveland, USA (East) – cle1
...
❌ Found 2 dead link(s) in 1 file(s):
📄 docs/code-search/features.mdx
   Line 154: /code-search/no-such-page
...
❌ Failed checks: links, filenames
 ELIFECYCLE  Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1

Amp thread

Merge order for the PR-check stack

Merge this PR first, so all subsequent PRs get the benefit of this output

@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 11, 2026 5:03pm UTC

Request Review

marcleblanc2 and others added 2 commits September 11, 2026 10:39
Vercel shows build logs only to members of its team, so contributors
saw a red X and a login wall. On vercel.deployment.error this posts the
tail of the build log on the PR; on the next successful build the same
comment is updated to say the failure is fixed. Fork PRs are skipped so
the project-scoped Vercel token is never used on their behalf.
…dispatch needs the file on main

Two open PRs at the same head SHA got one comment on whichever PR the
commits/{sha}/pulls API listed first. A deployment belongs to a commit,
so comment on each open PR at that head, fetching the build log once.

GitHub only resolves workflow_dispatch for workflows on the default
branch (gh workflow run --ref <branch> 404s before merge), so the header
now says to run the script locally until then.

Amp-Thread-ID: https://ampcode.com/threads/T-01a08fee-74b4-76dc-aaf9-d1245d68fdc9
Co-authored-by: Amp <amp@ampcode.com>
…omment cannot hold it

The comment says how many lines the log has and that the last 100 are
shown, matching tail -n 100. When that leaves lines out, the full log is
uploaded as a workflow artifact and linked from the comment; the
artifact ID rides in the comment marker so the run that reports the
build passing deletes it.

Amp-Thread-ID: https://ampcode.com/threads/T-01a09014-dfa8-740c-95b4-9e28c43cae51
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2

Copy link
Copy Markdown
Contributor Author

Moved to #1946 (branch renamed to marc/ci/vercel-build-failure-report).

auto-merge was automatically disabled September 11, 2026 17:26

Pull request was closed

@marcleblanc2
marcleblanc2 deleted the ci/vercel-build-failure-report branch September 11, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant