Skip to content

ci(perf): post sticky comment for fork PRs via workflow_run#186

Merged
JacksonWeber merged 2 commits into
microsoft:mainfrom
JacksonWeber:fix-perf-sticky-comment-for-forks
Jun 4, 2026
Merged

ci(perf): post sticky comment for fork PRs via workflow_run#186
JacksonWeber merged 2 commits into
microsoft:mainfrom
JacksonWeber:fix-perf-sticky-comment-for-forks

Conversation

@JacksonWeber

Copy link
Copy Markdown
Contributor

Why

The Performance workflow runs in the PR's context, which means the GITHUB_TOKEN is read-only for pull requests opened from forks. The Post sticky PR comment step is therefore gated off whenever github.event.pull_request.head.repo.full_name != github.repository, so the perf comparison never appears on cross-repository PRs (e.g. #182).

What

  • New performance-comment.yml workflow triggered by workflow_run of Performance. Because workflow_run runs in the base repository's context, it has pull-requests: write even for fork PRs.
  • performance.yml now records the PR number in pr-number.txt and uploads it alongside report.md. The follow-up workflow downloads the perf-results artifact and uses that PR number to post the sticky comment with marocchino/sticky-pull-request-comment@v2.
  • Removed the in-place Post sticky PR comment step (and its fork gate) from performance.yml so we don't double-post for same-repo PRs.

Notes

  • workflow_run jobs execute against the base branch's workflow definition, so this is safe even though the upstream perf job runs untrusted PR code — the comment job only consumes the produced artifact.
  • if-no-files-found: ignore keeps the artifact upload from failing if an earlier step crashed before producing report.md; in that case the comment job sees an empty/missing report and skips posting rather than erroring.

The Performance workflow runs in the PR context, which only grants a
read-only GITHUB_TOKEN for pull requests from forks. As a result the
"Post sticky PR comment" step was gated off for cross-repo PRs and the
perf comparison never appeared on those PRs (e.g. microsoft#182).

Move the comment posting into a new "Performance Comment" workflow
triggered by workflow_run, which executes in the base repository
context with pull-requests: write regardless of the PR's origin. The
benchmarking workflow now records the PR number in pr-number.txt and
uploads it alongside report.md so the follow-up workflow can target the
correct PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the CI performance reporting so that perf comparison results can be posted as a sticky PR comment even when the pull request originates from a fork (where the GITHUB_TOKEN is read-only in the PR workflow context). It does so by moving the commenting step into a separate workflow_run workflow that runs in the base repository context.

Changes:

  • Adds a new Performance Comment workflow triggered by workflow_run to post the sticky perf comparison comment with pull-requests: write.
  • Updates performance.yml to record the PR number into an artifact (pr-number.txt) and removes the in-workflow sticky comment step.
  • Adjusts artifact upload behavior to tolerate missing files (if-no-files-found: ignore).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/performance.yml Uploads pr-number.txt alongside perf artifacts and removes direct PR commenting from the PR-context workflow.
.github/workflows/performance-comment.yml New base-context workflow_run workflow that downloads perf artifacts and posts the sticky PR comment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/performance-comment.yml
Comment thread .github/workflows/performance-comment.yml Outdated
Comment thread .github/workflows/performance-comment.yml Outdated
Address Copilot review feedback on microsoft#186:

* Treat the perf-results artifact as untrusted. Check out the base repo
  and regenerate report.md here from base.json/pr.json using the
  base-branch copy of perf.compare so the markdown posted under the
  writable GITHUB_TOKEN is never attacker-supplied by a fork PR.
* Make actions/download-artifact non-fatal (continue-on-error) and gate
  every subsequent step on the download outcome, so a cancelled or
  failed upstream Performance run skips cleanly instead of marking the
  comment job as failed.
* Validate that pr-number.txt contains a positive integer via regex
  before passing it to the sticky-comment action; skip cleanly if not.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread .github/workflows/performance-comment.yml
Comment thread .github/workflows/performance-comment.yml Outdated
Comment thread .github/workflows/performance-comment.yml Outdated
@JacksonWeber JacksonWeber merged commit 8ef4747 into microsoft:main Jun 4, 2026
11 checks passed
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.

3 participants