Skip to content

Commit fc9661e

Browse files
committed
PR build: when called from forks, publish a Git bundle
When the HTML page(s) are not up to date, the PR build re-generates them, commits the result and wants to push it to the branch. However, this only works if the PR branch and the target branch are in the same repository. Otherwise the workflow run's `GITHUB_TOKEN` lacks write permission, even if the PR author gave permission to the maintainers to push to that branch. Let's fall back to doing the next best thing and publish a Git bundle, and provide instructions how to fetch from them and update the PR with those changes. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c5f311f commit fc9661e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

.github/workflows/pr.yml

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
git add -A \*.html &&
2020
git diff-index --cached --exit-code HEAD -- ||
2121
echo "need-to-commit=yes" >>$GITHUB_OUTPUT
22-
- name: commit & push
22+
- name: commit
2323
if: steps.check.outputs.need-to-commit == 'yes'
2424
run: |
2525
git config user.name "${{github.actor}}" &&
@@ -28,5 +28,23 @@ jobs:
2828
git update-index --refresh &&
2929
git diff-files --exit-code &&
3030
git diff-index --cached --exit-code HEAD -- &&
31-
git push
32-
31+
git bundle create git.bundle ${{ github.event.pull_request.head.sha }}..${{ github.event.pull_request.head.ref }}
32+
- name: commit
33+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
34+
run: git push
35+
- name: publish bundle
36+
id: bundle
37+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: bundle
41+
path: git.bundle
42+
- name: instructions how to fetch bundle
43+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
44+
env:
45+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
body='The HTML pages are out of date. Please download the `bundle` artifact from ${{ steps.bundle.outputs.artifact-url }}, extract the `git.bundle` file from it, then run `git pull /path/to/git.bundle ${{ github.event.pull_request.head.ref }}` and then push to the PR branch'
48+
echo "::error::$body" >&2
49+
gh pr comment ${{ github.event.number }} --body "$body" -R ${{ github.event.pull_request.base.repo.full_name }}
50+
exit 1

0 commit comments

Comments
 (0)