Skip to content

Commit 11d6a64

Browse files
committed
PR build: try to push to temporary branch when being called from forks
This might not work due to permissions. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c5f311f commit 11d6a64

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

.github/workflows/pr.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ 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}}" &&
2626
git config user.email "${{github.actor}}@users.noreply.github.com" &&
2727
git commit -m 'Convert Markdown to HTML' -- \*.html &&
2828
git update-index --refresh &&
2929
git diff-files --exit-code &&
30-
git diff-index --cached --exit-code HEAD -- &&
31-
git push
32-
30+
git diff-index --cached --exit-code HEAD --
31+
- name: commit
32+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
33+
run: git push
34+
- name: publish temporary branch and add instructions how to fetch
35+
if: steps.check.outputs.need-to-commit == 'yes' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
36+
run: |
37+
auth="$(printf 'PAT:%s' '${{ secrets.GITHUB_TOKEN }}' | base64 -w 0)" &&
38+
echo "::add-mask::$auth" &&
39+
git -c http.extraHeader="Authorization: Basic $auth" push "${{ github.event.pull_request.base.repo.clone_url }}" HEAD:refs/tmp/pr-${{ github.event.number }} &&
40+
echo '::error::HTML pages are out of date. Please call `git pull --ff-only ${{ github.event.pull_request.base.repo.clone_url }}" refs/tmp/pr-${{ github.event.number }}` and push to the PR branch' >&2
41+
exit 1

0 commit comments

Comments
 (0)