Skip to content

Commit f01339c

Browse files
[workflow] Validate wiki publish before cleanup (#69) (#87)
* Validate wiki publish before cleanup * Update wiki submodule pointer for PR #87 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b11c6f4 commit f01339c

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

.github/wiki

Submodule wiki updated from 97d9cd1 to a95f045

.github/workflows/wiki.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,14 @@ jobs:
137137
git config --global --add safe.directory "$GITHUB_WORKSPACE/.github/wiki"
138138
139139
- name: Prepare wiki publish branch from preview branch
140+
id: prepare_publish
140141
working-directory: .github/wiki
141142
run: |
142143
git fetch origin "${WIKI_PUBLISH_BRANCH}" "${WIKI_PREVIEW_BRANCH}"
144+
expected_preview_sha="$(git rev-parse "origin/${WIKI_PREVIEW_BRANCH}")"
145+
echo "expected_preview_sha=${expected_preview_sha}" >> "$GITHUB_OUTPUT"
146+
echo "Expected wiki preview SHA: ${expected_preview_sha}"
147+
143148
git switch -C "${WIKI_PUBLISH_BRANCH}" --track "origin/${WIKI_PUBLISH_BRANCH}" || git switch "${WIKI_PUBLISH_BRANCH}"
144149
git reset --hard "origin/${WIKI_PREVIEW_BRANCH}"
145150
git clean -fd
@@ -148,6 +153,26 @@ jobs:
148153
working-directory: .github/wiki
149154
run: git push --force-with-lease origin HEAD:"${WIKI_PUBLISH_BRANCH}"
150155

156+
- name: Validate wiki publish branch
157+
working-directory: .github/wiki
158+
env:
159+
EXPECTED_PREVIEW_SHA: ${{ steps.prepare_publish.outputs.expected_preview_sha }}
160+
run: |
161+
actual_publish_sha="$(git ls-remote origin "refs/heads/${WIKI_PUBLISH_BRANCH}" | awk '{print $1}')"
162+
163+
echo "Expected wiki publish SHA: ${EXPECTED_PREVIEW_SHA}"
164+
echo "Actual wiki publish SHA: ${actual_publish_sha}"
165+
166+
if [ -z "${actual_publish_sha}" ]; then
167+
echo "Remote wiki publish branch ${WIKI_PUBLISH_BRANCH} was not found after push." >&2
168+
exit 1
169+
fi
170+
171+
if [ "${actual_publish_sha}" != "${EXPECTED_PREVIEW_SHA}" ]; then
172+
echo "Remote wiki publish branch ${WIKI_PUBLISH_BRANCH} does not match preview branch ${WIKI_PREVIEW_BRANCH}." >&2
173+
exit 1
174+
fi
175+
151176
- name: Delete wiki preview branch
152177
working-directory: .github/wiki
153178
run: |

docs/advanced/branch-protection-and-bot-commits.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ reject direct commits.
3434
After the pull request is merged into ``main``, the publish job copies the
3535
content from the wiki preview branch, such as ``pr-123``, to the wiki
3636
``master`` branch. That makes the reviewed wiki content live only after the
37-
source code merge is complete. The workflow then deletes the ``pr-123`` branch
38-
because it is no longer needed.
37+
source code merge is complete. The workflow validates that remote ``master``
38+
points to the expected preview commit before it deletes the ``pr-123`` branch
39+
because the preview branch is the last rollback source for that generated
40+
content.
3941

4042
If the pull request is closed without merge, the workflow deletes the matching
4143
wiki preview branch without promoting it to ``master``. A scheduled cleanup also

docs/troubleshooting.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ Likely causes:
221221
- the cleanup workflow did not run on the pull request close event;
222222
- the workflow token lacks permission to update Pages or the wiki repository;
223223
- a preview was removed after the comment was posted.
224+
- the wiki publish validation detected that remote ``master`` does not match
225+
the preview branch SHA.
224226

225227
Recovery:
226228

@@ -229,6 +231,8 @@ Recovery:
229231
request is closed or merged;
230232
- use the scheduled wiki cleanup workflow to remove leftover ``pr-<number>``
231233
branches for pull requests that are already closed;
234+
- keep the wiki preview branch until the publish validation log shows matching
235+
expected and actual SHAs;
232236
- check the reports and wiki workflow logs before deleting artifacts manually.
233237

234238
Related References

docs/usage/github-actions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The ``wiki.yml`` workflow synchronizes the documentation generated by the ``dev-
4747
**Behavior:**
4848
* **Submodule Management**: It manages a submodule at ``.github/wiki`` that points to the actual wiki repository.
4949
* **Pull Requests**: Pushes documentation changes to a dedicated branch (e.g., ``pr-123``) in the wiki repository for review.
50-
* **Merge**: When a PR is merged into ``main``, it pushes the changes to the ``master`` branch of the wiki, making them live.
50+
* **Merge**: When a PR is merged into ``main``, it pushes the changes to the ``master`` branch of the wiki, validates the remote branch SHA, and makes them live.
5151
* **Cleanup**: When a PR is closed, the workflow deletes the matching wiki preview branch. A scheduled cleanup also removes stale ``pr-{number}`` branches for already closed pull requests.
5252

5353
.. note::

0 commit comments

Comments
 (0)