Skip to content

Commit 5002397

Browse files
[docs] Document branch protection workflow (#61) (#77)
* Document branch protection workflow * Update wiki submodule pointer for PR #77 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2e73b37 commit 5002397

5 files changed

Lines changed: 135 additions & 5 deletions

File tree

.github/wiki

Submodule wiki updated from 05a1440 to 6e2dfcc
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Branch Protection and Bot Commits
2+
=================================
3+
4+
Fast Forward repositories keep generated documentation out of protected
5+
branches until the related pull request is merged. This keeps ``main`` stable,
6+
lets maintainers review generated output before it becomes canonical, and
7+
avoids requiring automation to bypass branch protection for normal preview
8+
updates.
9+
10+
The model has two publishing lanes:
11+
12+
- pull requests publish isolated previews;
13+
- merges into ``main`` publish the final wiki and reports.
14+
15+
Wiki Preview Lifecycle
16+
----------------------
17+
18+
The wiki workflow writes generated Markdown to the GitHub wiki repository, but
19+
it does not publish pull request content directly to the wiki ``master`` branch.
20+
Instead, each pull request receives a dedicated wiki branch.
21+
22+
For pull request ``123`` the workflow:
23+
24+
1. runs ``composer dev-tools wiki -- --target=.github/wiki``;
25+
2. commits the generated wiki content to the wiki branch ``pr-123``;
26+
3. updates the parent repository submodule pointer at ``.github/wiki``;
27+
4. commits that pointer update back to the pull request branch.
28+
29+
The parent repository commit is important because reviewers can see exactly
30+
which generated wiki revision belongs to the pull request. The bot commit SHOULD
31+
stay on the pull request branch because protected ``main`` branches usually
32+
reject direct commits.
33+
34+
After the pull request is merged into ``main``, the publish job copies the
35+
content from the wiki preview branch, such as ``pr-123``, to the wiki
36+
``master`` branch. That makes the reviewed wiki content live only after the
37+
source code merge is complete.
38+
39+
Reports Preview Lifecycle
40+
-------------------------
41+
42+
Reports use the same review-before-publish idea, but the output is served from
43+
GitHub Pages instead of the wiki repository.
44+
45+
On pull requests, the reports workflow:
46+
47+
- generates docs, coverage, and report assets from the pull request code;
48+
- publishes them under ``previews/pr-<number>/`` in the Pages branch;
49+
- comments on the pull request with preview links when possible;
50+
- keeps workflow artifacts available as a fallback when Pages publishing or the
51+
comment update is unavailable.
52+
53+
On ``main``, the reports workflow publishes the final site at the root of the
54+
Pages branch. Pull request previews use PR-specific directories, so multiple
55+
open pull requests can have independent previews without overwriting each other.
56+
57+
When a pull request is closed, the workflow SHOULD remove its preview directory.
58+
This prevents stale documentation and coverage reports from looking like active
59+
review artifacts.
60+
61+
Branch Protection Interactions
62+
------------------------------
63+
64+
Protected branches usually block direct pushes, require status checks, and may
65+
require signed commits or linear history. The preview workflows are designed to
66+
respect those rules:
67+
68+
- bot commits update the pull request branch, not ``main``;
69+
- final wiki publication runs after the merge into ``main``;
70+
- final reports publication runs from the already-accepted ``main`` revision;
71+
- preview branches such as ``pr-123`` are temporary review targets.
72+
73+
If a repository restricts bot pushes to pull request branches, maintainers
74+
should either allow the workflow token to update PR branches or require authors
75+
to refresh generated pointers manually. The preferred path is to allow bot
76+
updates on PR branches while keeping ``main`` protected.
77+
78+
At a high level, the workflows need permission to read repository contents,
79+
write generated preview commits, update pull request comments, and publish Pages
80+
content. Keep those permissions scoped to the workflow jobs that actually need
81+
them.
82+
83+
Resolving ``.github/wiki`` Pointer Conflicts
84+
--------------------------------------------
85+
86+
Submodule pointer conflicts happen when ``main`` and the pull request point to
87+
different generated wiki commits. Resolve them by rebasing the pull request and
88+
choosing the preview wiki commit that belongs to the pull request.
89+
90+
For pull request ``123``:
91+
92+
.. code-block:: bash
93+
94+
git fetch origin main
95+
git rebase origin/main
96+
git -C .github/wiki fetch origin master pr-123
97+
git -C .github/wiki switch --detach origin/pr-123
98+
git add .github/wiki
99+
git rebase --continue
100+
git push --force-with-lease
101+
102+
If the conflict appears after the preview job has already produced a newer bot
103+
commit, prefer the latest ``pr-123`` wiki commit. If the wiki branch no longer
104+
exists because the pull request was closed or merged, rerun the wiki workflow or
105+
regenerate the wiki locally before updating the pointer.
106+
107+
Operational Checklist
108+
---------------------
109+
110+
- Keep source changes and generated pointer updates in the same pull request.
111+
- Review PR preview links before merging documentation-heavy changes.
112+
- Merge only through the protected ``main`` flow.
113+
- Let the post-merge wiki job publish to ``master``.
114+
- Let closed pull requests clean up their report preview directories.
115+
116+
See :doc:`consumer-automation` for how reusable workflows and consumer stubs fit
117+
into this model, and :doc:`../usage/github-actions` for the workflow summary.

docs/advanced/consumer-automation.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,23 @@ How GitHub Pages Publishing Works
3636
---------------------------------
3737

3838
- ``.github/workflows/reports.yml`` runs ``composer dev-tools reports``.
39-
- The workflow uploads ``public/`` as the Pages artifact.
40-
- On the ``main`` branch, GitHub Pages serves the generated site.
39+
- Pull requests publish previews under ``previews/pr-<number>/``.
40+
- On the ``main`` branch, GitHub Pages serves the generated site from the root
41+
of the Pages branch.
4142

4243
How Wiki Publishing Works
4344
-------------------------
4445

4546
- ``.github/workflows/wiki.yml`` runs
4647
``composer dev-tools wiki -- --target=.github/wiki``.
47-
- The workflow commits the wiki submodule contents.
48-
- The parent repository then commits the updated submodule pointer.
48+
- Pull requests publish generated wiki content to branches such as
49+
``pr-123``.
50+
- The parent repository then commits the updated submodule pointer to the pull
51+
request branch.
52+
- After merge, the preview content is promoted to the wiki ``master`` branch.
53+
54+
See :doc:`branch-protection-and-bot-commits` for the branch protection model,
55+
bot commit behavior, and ``.github/wiki`` conflict resolution steps.
4956

5057
Producer Impact
5158
---------------

docs/advanced/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ custom Rector and PHPDoc behavior.
99
:maxdepth: 1
1010

1111
consumer-automation
12+
branch-protection-and-bot-commits
1213
phpunit-extension
1314
rector-and-phpdoc

docs/usage/github-actions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Example of an inherited workflow:
1818
1919
This approach ensures that all libraries in the ecosystem benefit from infrastructure updates without requiring manual changes to every repository.
2020

21+
For the protected-branch-safe preview and publish model, see
22+
:doc:`../advanced/branch-protection-and-bot-commits`.
23+
2124
Fast Forward Reports
2225
--------------------
2326

@@ -48,6 +51,8 @@ The ``wiki.yml`` workflow synchronizes the documentation generated by the ``dev-
4851

4952
.. note::
5053
See :doc:`../configuration/repository-setup` for mandatory initial setup required for the Wiki workflow to function.
54+
See :doc:`../advanced/branch-protection-and-bot-commits` for branch
55+
protection, bot commit, and submodule pointer conflict guidance.
5156

5257
Fast Forward Tests
5358
------------------

0 commit comments

Comments
 (0)