Files
RustPython/.github/workflows/pyperformance-comment.yaml
T
dependabot[bot] 76995a264c build(deps): bump actions/download-artifact from 8.0.1 to 8.0.2 (#9331)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 8.0.1 to 8.0.2.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c...9000827ccba6bdab643e8b6fd33ac0654aef8333)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-24 01:02:00 +09:00

82 lines
3.0 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
on:
workflow_run:
workflows: [pyperformance]
types: [completed]
name: pyperformance comment
# Same split as `codspeed-comment.yaml`: a `pull_request` run from a fork gets
# a read-only token however it is configured, so the comparison is computed
# there and handed over as an artifact, and this workflow -- which
# `workflow_run` always runs in the base repo's context -- is the one trusted
# with a token that may write the comment.
permissions:
contents: read
actions: read # needed by download-artifact to fetch another run's artifact
pull-requests: write
jobs:
comment:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Download the comparison produced by the pyperformance workflow
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: pyperformance-diff
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
continue-on-error: true # absent when the job was skipped or dispatched
- name: Post or update the PR comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
if (!fs.existsSync('diff.md')) {
core.info('No diff.md in this run; nothing to comment.');
return;
}
const marker = '<!-- pyperformance-local-diff -->';
const run = context.payload.workflow_run;
let prNumber = (run.pull_requests || []).map((pr) => pr.number)[0];
if (!prNumber) {
const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: run.head_sha,
});
prNumber = data.find((pr) => pr.state === 'open')?.number;
}
if (!prNumber) {
core.info(`No open pull request for ${run.head_sha}; nothing to comment.`);
return;
}
const raw = fs.readFileSync('diff.md', 'utf8').slice(0, 60000);
const body = `${marker}\n\n${raw.replace(/<!--/g, '<!-​-')}`;
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find((c) => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}