-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: split SHASUM summary comment workflow into two
commenting on a PR requires permissions which don't work from forks of public repos. Circumvent this by using a second workflow which runs via `on_workflow`, where the correct permissions are obtained. Previously, the workflow would run the shasum-summary tool and store the comment in a file. The file contents would then be used as the comment body. Commenting however fails due to external forks not having the permissions to comment. Now, the workflow is split into two parts. First, the comment (and PR number) is stored in file which is uploaded as build-artifact. Upon completion, a second workflow starts, downloads the build-artifact, and comments on the PR.
- Loading branch information
1 parent
cbfaa87
commit 16e1893
Showing
2 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Comment on PR | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["SHASUM summary"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
comment: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: shasum-comment | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
repository: ${{ github.repository }} | ||
run-id: ${{ github.event.workflow_run.id }} | ||
- name: comment | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
let issue_number = Number(fs.readFileSync('./issue-number', 'utf8').trim()); | ||
let comment = fs.readFileSync('./comment', 'utf8').trim(); | ||
if (comment.length > 0) { | ||
github.rest.issues.createComment({ | ||
issue_number: issue_number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: "${{ github.event.pull_request.head.sha }}\n\n" + comment | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters