mirror of
https://github.com/j178/prek.git
synced 2026-04-25 02:11:36 +02:00
72 lines
2.8 KiB
YAML
72 lines
2.8 KiB
YAML
# This workflow comments on a PR with the results of the `cargo bloat check` performed in the performance workflow.
|
|
# This is a workaround for the limitations imposed by GitHub Actions on workflows triggered by pull requests from forked repositories.
|
|
|
|
# The restrictions apply to the pull_request event triggered by a fork opening a pull request in the upstream repository.
|
|
# - Events from forks cannot access secrets, except for the default GITHUB_TOKEN.
|
|
# - The GITHUB_TOKEN has read-only access when an event is triggered by a forked repository.
|
|
#
|
|
# These restrictions mean that during a pull_request event triggered by a forked repository,
|
|
# actions have no write access to GitHub resources and will fail on any attempt.
|
|
name: PR comment
|
|
on:
|
|
workflow_run: # zizmor: ignore[dangerous-triggers]
|
|
workflows: [Performance]
|
|
types: [completed]
|
|
workflow_dispatch:
|
|
inputs:
|
|
workflow_run_id:
|
|
description: The CI workflow that triggers the workflow run
|
|
required: true
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
bloat-comment:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
|
with:
|
|
name: bloat-check-results
|
|
path: /tmp/bloat-check/
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
run-id: ${{ github.event.workflow_run.id || github.event.inputs.workflow_run_id }}
|
|
|
|
- name: Comment bloat check on PR
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
with:
|
|
script: |
|
|
const fs = require('node:fs');
|
|
const marker = '<!-- prek-bloat-check -->';
|
|
const comparison = await fs.promises.readFile('/tmp/bloat-check/bloat-comparison.txt', 'utf8');
|
|
const body = `${marker}\n${comparison}`;
|
|
|
|
const { repo, owner } = context.repo;
|
|
const prNumber = await fs.promises.readFile('/tmp/bloat-check/pr-number.txt', 'utf8').then(Number);
|
|
|
|
const comments = await github.paginate(github.rest.issues.listComments, {
|
|
owner,
|
|
repo,
|
|
issue_number: prNumber,
|
|
per_page: 100,
|
|
});
|
|
|
|
const existing = comments.find((comment) => comment.body?.includes(marker));
|
|
|
|
if (existing) {
|
|
await github.rest.issues.updateComment({
|
|
owner,
|
|
repo,
|
|
comment_id: existing.id,
|
|
body,
|
|
});
|
|
} else {
|
|
await github.rest.issues.createComment({
|
|
owner,
|
|
repo,
|
|
issue_number: prNumber,
|
|
body,
|
|
});
|
|
}
|