Skip to content

Update the preview comment when the build or deploy fails - #451

Draft
Mpdreamz wants to merge 1 commit into
mainfrom
fix/preview-comment-on-failure
Draft

Mpdreamz wants to merge 1 commit into
mainfrom
fix/preview-comment-on-failure

Conversation

@Mpdreamz

Copy link
Copy Markdown
Member

Why

The preview comment on a PR can get stuck on "⏳ Building and deploying preview…" for good when the deploy workflow fails, so a failed deploy looks like a hung one.

How the comment works today in docs-deploy.yml:

  1. pre-comment writes ⏳ Building and deploying preview... [View progress](<run url>).
  2. build and deploy-preview run.
  3. comment replaces it with the preview links, but only when deploy-preview.outputs.deployed == 'true'.

If build or deploy-preview fails, comment is skipped and nothing else touches the comment. The workflow also runs on workflow_run, so it does not show up as a check on the PR; the comment is the only place the author sees it, and it says "building" indefinitely.

Real example: https://github.com/elastic/cloud/pull/161041. The build job failed at checkout (run, cause and fix in #450). deploy-preview and comment were skipped, and the PR still shows "Building and deploying preview…" a day later. The same happens for any other build failure (for example docs-builder errors under strict: true) or a failing S3 upload.

What

A new comment-failure job, placed after comment. It runs when all of these hold:

  • always(), so it still runs when build failed and later jobs were skipped
  • the event is pull_request, and the PR is not a fork PR from a non-member (the same audience condition as pre-comment and comment)
  • pre-comment succeeded, so there is an in-progress comment to update
  • build.result == 'failure' or deploy-preview.result == 'failure'
  • inputs.disable-comments != true

It rewrites the comment to:

🔍 Preview links for changed docs

❌ The preview build failed. View the logs

Push a new commit or re-run the failed jobs to try again.

("build" or "deployment", depending on which job failed.)

Design decisions:

  • Only this run's comment is touched. The comment is matched by title and by containing this run's URL, which pre-comment wrote. A comment from a newer run, or one already replaced by finished preview links, is never overwritten.
  • Cancelled runs are ignored. The workflow uses cancel-in-progress, so a cancelled run means a newer run took over and owns the comment.
  • Same permissions as comment: pull-requests: write only, everything else none. No checkout, no secrets, no PR content is used. Values reach the script through env, not template expansion.
  • continue-on-error: true like the other comment steps, so a comment problem never changes the workflow result.

Separate from #450

#450 fixes why the build fails for fork PRs of private repositories. This PR is only about telling the author when any build or deploy fails. They are independent: either can merge alone, and this one also covers every other failure mode.

Testing

Done:

  • actionlint and zizmor pass on docs-deploy.yml.
  • Extracted the script and ran it against a stubbed github client with three comments (this run's in-progress comment, another run's in-progress comment, a finished preview comment):
    • build failure updates only this run's comment, with "build failed"
    • deploy failure updates it with "deployment failed"
    • the other run's and the finished comment are not touched
  • Mutation check: removing the includes(runUrl) guard makes the third case fail (it then updates a comment it should not), so the test does exercise the guard.

Not done: an end-to-end run, since this is a reusable workflow_run workflow that cannot be triggered from a branch. After merge and the v1 tag move, a deliberately failing build on a test PR would confirm it.

Not covered: when build succeeds but reports skip == 'true', deploy-preview is skipped without failing, so the comment may also stay on "Building". I have not checked whether that case can happen after pre-comment; it is not handled here.

🤖 Generated with Claude Code

pre-comment writes 'Building and deploying preview...' and only the comment
job replaces it, after a successful deploy. If build or deploy-preview
fails the comment stays on 'Building' forever. Add a comment-failure job
that rewrites it to a failure message with a link to the run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mpdreamz Mpdreamz added the fix label Nov 12, 2026
@Mpdreamz

Copy link
Copy Markdown
Member Author

@elastic/docs-engineering could you review this? docs-deploy.yml is the reusable workflow behind @v1, so this adds a job to the deploy of every repository that uses it, and it cannot be exercised from a branch of this repo (it is a workflow_run workflow).

Where I'd like the most attention:

  • The if: on comment-failure (always() plus the result checks): it should fire only for a failed build or deploy-preview, never for cancelled or skipped runs.
  • It only rewrites the comment that links to its own run, so a newer run's comment or a finished preview is never overwritten.
  • Permissions are pull-requests: write only, no checkout and no secrets.

Independent of #450, which fixes why the build fails for fork PRs of private repositories. Either can merge alone. Untested end to end; a deliberately failing build on a test PR after the v1 tag move would confirm it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant