Skip to content

Commit e3f3913

Browse files
[wiki] Fix branch-protection publishing flow (#48) (#49)
* Fix wiki branch protection flow * Update wiki submodule pointer for PR #49 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fdfe54f commit e3f3913

3 files changed

Lines changed: 88 additions & 36 deletions

File tree

.github/wiki

Submodule wiki updated from ec27577 to aef19f1

.github/workflows/wiki.yml

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@ name: Update Wiki
33
on:
44
workflow_call:
55
workflow_dispatch:
6-
push:
7-
branches: ["main"]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
pull_request_target:
9+
types: [closed]
810

911
permissions:
1012
contents: write
11-
pull-requests: write
13+
pull-requests: read
1214

1315
concurrency:
14-
group: update-wiki-${{ github.ref }}
16+
group: update-wiki-${{ github.event.pull_request.number || github.ref }}
1517
cancel-in-progress: true
1618

1719
jobs:
18-
wiki:
19-
name: Update Wiki
20+
preview:
21+
name: Update Wiki Preview
22+
if: github.event_name == 'pull_request'
2023
runs-on: ubuntu-latest
2124

25+
env:
26+
WIKI_PREVIEW_BRANCH: pr-${{ github.event.pull_request.number }}
27+
2228
steps:
23-
- name: Checkout repository
29+
- name: Checkout PR branch
2430
uses: actions/checkout@v6
2531
with:
2632
token: ${{ github.token }}
33+
ref: ${{ github.event.pull_request.head.ref }}
34+
repository: ${{ github.event.pull_request.head.repo.full_name }}
2735
submodules: recursive
2836
fetch-depth: 0
2937

@@ -49,32 +57,39 @@ jobs:
4957
env:
5058
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
5159
COMPOSER_CACHE_DIR: /tmp/composer-cache
52-
COMPOSER_ROOT_VERSION: dev-main
60+
COMPOSER_ROOT_VERSION: dev-${{ github.event.pull_request.head.ref }}
5361
run: composer install --prefer-dist --no-progress --no-interaction --no-scripts
5462

55-
- name: Prepare wiki submodule branch
63+
- name: Prepare wiki preview branch
5664
working-directory: .github/wiki
5765
run: |
58-
git fetch origin master
59-
git switch -C master --track origin/master || git switch master
60-
git reset --hard origin/master
66+
git fetch origin
67+
68+
if git ls-remote --exit-code --heads origin "${WIKI_PREVIEW_BRANCH}" >/dev/null 2>&1; then
69+
git switch -C "${WIKI_PREVIEW_BRANCH}" --track "origin/${WIKI_PREVIEW_BRANCH}"
70+
git reset --hard "origin/${WIKI_PREVIEW_BRANCH}"
71+
else
72+
git switch --orphan "${WIKI_PREVIEW_BRANCH}"
73+
git rm -rf . >/dev/null 2>&1 || true
74+
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
75+
fi
76+
6177
git clean -fd
6278
6379
- name: Create Docs Markdown
6480
env:
65-
COMPOSER_ROOT_VERSION: dev-main
81+
COMPOSER_ROOT_VERSION: dev-${{ github.event.pull_request.head.ref }}
6682
run: composer dev-tools wiki -- --target=.github/wiki
6783

68-
- name: Commit & push wiki submodule
84+
- name: Commit & push wiki preview branch
6985
id: wiki_commit
7086
uses: EndBug/add-and-commit@v10
7187
with:
7288
cwd: .github/wiki
7389
add: .
74-
message: "Update wiki docs"
90+
message: "Update wiki docs for PR #${{ github.event.pull_request.number }}"
7591
default_author: github_actions
76-
pull: "--rebase --autostash"
77-
push: true
92+
push: origin HEAD:${{ env.WIKI_PREVIEW_BRANCH }}
7893

7994
- name: Check submodule pointer changes
8095
id: submodule_status
@@ -85,19 +100,52 @@ jobs:
85100
echo "changed=true" >> "$GITHUB_OUTPUT"
86101
fi
87102
88-
- name: Create or update pull request for wiki submodule pointer
103+
- name: Commit parent repo submodule pointer
89104
if: steps.submodule_status.outputs.changed == 'true'
90-
uses: peter-evans/create-pull-request@v7
105+
id: parent_commit
106+
uses: EndBug/add-and-commit@v10
107+
with:
108+
add: .github/wiki
109+
message: "Update wiki submodule pointer for PR #${{ github.event.pull_request.number }}"
110+
default_author: github_actions
111+
pull: "--rebase --autostash"
112+
push: true
113+
114+
publish:
115+
name: Publish Wiki Main
116+
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
117+
runs-on: ubuntu-latest
118+
119+
env:
120+
WIKI_PREVIEW_BRANCH: pr-${{ github.event.pull_request.number }}
121+
122+
steps:
123+
- name: Checkout main branch
124+
uses: actions/checkout@v6
91125
with:
92126
token: ${{ github.token }}
93-
branch: chore/update-wiki-submodule-pointer
94-
base: main
95-
title: "Update wiki submodule pointer"
96-
body: |
97-
This PR updates the repository submodule pointer for `.github/wiki` to match the latest wiki revision generated by the workflow.
98-
commit-message: "Update wiki submodule pointer"
99-
author: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
100-
committer: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
101-
add-paths: |
102-
.github/wiki
103-
delete-branch: true
127+
ref: main
128+
submodules: recursive
129+
fetch-depth: 0
130+
131+
- name: Mark workspace as safe for git
132+
run: |
133+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
134+
git config --global --add safe.directory "$GITHUB_WORKSPACE/.github/wiki"
135+
136+
- name: Prepare wiki main branch from preview branch
137+
working-directory: .github/wiki
138+
run: |
139+
git fetch origin main "${WIKI_PREVIEW_BRANCH}"
140+
git switch -C main --track origin/main || git switch main
141+
git reset --hard "origin/${WIKI_PREVIEW_BRANCH}"
142+
git clean -fd
143+
144+
- name: Commit & push wiki main branch
145+
uses: EndBug/add-and-commit@v10
146+
with:
147+
cwd: .github/wiki
148+
add: .
149+
message: "Publish wiki docs from PR #${{ github.event.pull_request.number }}"
150+
default_author: github_actions
151+
push: origin HEAD:main

resources/github-actions/wiki.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
name: "Fast Forward Wiki Update"
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
pull_request_target:
7+
types: [closed]
78
workflow_dispatch:
89

910
permissions:
1011
contents: write
11-
pages: write
12-
id-token: write
12+
pull-requests: read
13+
14+
concurrency:
15+
group: fast-forward-wiki-${{ github.event.pull_request.number || github.ref }}
16+
cancel-in-progress: true
1317

1418
jobs:
1519
wiki:

0 commit comments

Comments
 (0)