Skip to content

Commit 3bf1328

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 3bf1328

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Diff for: .github/workflows/pr.yml

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
permissions:
88
contents: write
9+
issues: write
910
steps:
1011
- uses: actions/checkout@v4
1112
with:
@@ -19,7 +20,7 @@ jobs:
1920
git add -A \*.html &&
2021
git diff-index --cached --exit-code HEAD -- ||
2122
echo "need-to-commit=yes" >>$GITHUB_OUTPUT
22-
- name: commit & push
23+
- name: commit
2324
if: steps.check.outputs.need-to-commit == 'yes'
2425
run: |
2526
git config user.name "${{github.actor}}" &&
@@ -28,5 +29,21 @@ jobs:
2829
git update-index --refresh &&
2930
git diff-files --exit-code &&
3031
git diff-index --cached --exit-code HEAD -- &&
31-
git push
32-
32+
git bundle create git.bundle ${{ github.event.pull_request.head.sha }}..${{ github.event.pull_request.head.ref }}
33+
- name: commit
34+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
35+
run: git push
36+
- name: publish bundle
37+
id: bundle
38+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: bundle
42+
path: git.bundle
43+
- name: instructions how to fetch bundle
44+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
45+
run: |
46+
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'
47+
echo "::error::$body" >&2
48+
echo "$body" >>$GITHUB_STEP_SUMMARY
49+
exit 1

0 commit comments

Comments
 (0)