Skip to content

Commit 02f7b66

Browse files
Massimiliano Pippiper1234
authored andcommitted
[skip changelog] document the docs generation workflow (#738)
* [skip changelog] document the docs generation workflow * clarify how humans should not push to gh-pages * Apply suggestions from code review Co-authored-by: per1234 <[email protected]> Co-authored-by: per1234 <[email protected]>
1 parent 5b83e05 commit 02f7b66

File tree

1 file changed

+111
-36
lines changed

1 file changed

+111
-36
lines changed

Diff for: docs/CONTRIBUTING.md

+111-36
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ repository. To propose improvements or fix a bug, feel free to submit a PR.
99

1010
Before we can accept your contributions you have to sign the [Contributor License Agreement][0]
1111

12+
## Pull Requests
13+
14+
In order to ease code reviews and have your contributions merged faster, here is
15+
a list of items you can check before submitting a PR:
16+
17+
* Create small PRs that are narrowly focused on addressing a single concern.
18+
* PR titles indirectly become part of the CHANGELOG so it's crucial to provide a
19+
good record of **what** change is being made in the title; **why** it was made
20+
will go in the PR description, along with a link to a GitHub issue if it
21+
exists.
22+
* Write tests for the code you wrote.
23+
* Open your PR against the `master` branch.
24+
* Maintain **clean commit history** and use **meaningful commit messages**.
25+
PRs with messy commit history are difficult to review and require a lot of
26+
work to be merged.
27+
* Your PR must pass all CI tests before we will merge it. If you're seeing an
28+
error and don't think
29+
it's your fault, it may not be! The reviewer will help you if there are test
30+
failures that seem
31+
not related to the change you are making.
32+
1233
## Prerequisites
1334

1435
To build the Arduino CLI from sources you need the following tools to be
@@ -141,59 +162,107 @@ task test-integration
141162

142163
## Working on docs
143164

144-
Documentation consists of several Markdown files stored under the `docs` folder
145-
at the root of the repo. Some of those files are automatically generated in the
146-
CI pipeline that builds the documentation website so you won't find them in the
147-
git repository and you need to generate them locally.
165+
Documentation is provided to final users in form of static HTML content generated
166+
from a tool called [MkDocs][9] and hosted on [GitHub Pages][7].
167+
168+
### Local development
169+
170+
Most of the documentation consists of static content written over several
171+
Markdown files under the `docs` folder at the root of this git repository but
172+
some other content is dynamically generated from the CI pipelines - this is the
173+
case with the command line reference and the gRPC interface, for example.
148174

149-
If you're working on docs and your changes are not trivial, you might want to
150-
preview the documentation website locally, before opening a Pull Request. To run
151-
the docs toolchain locally you need to have:
175+
If you want to check out how the documentation would look after some local
176+
changes, you might need to reproduce what happens in the CI, generating the full
177+
documentation website from your personal computer. To run the docs toolchain
178+
locally, you need to have a few dependencies and tools installed:
152179

153180
* [Go][1] version 1.12 or later
154181
* [Taskfile][2] to help you run the most common tasks from the command line
155-
* A working [Python][3] environment, version 3.5 or later
182+
* A working [Python][3] environment, see [this paragraph](#integration-tests)
183+
if you need to setup one
156184

157-
Before running the toolchain, perform the following operations:
185+
Before running the toolchain, perform the following operations from the root of
186+
the git repository (if you have a Python virtual environment, activate it before
187+
proceeding):
158188

159189
* go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
190+
* pip install -r requirements_docs.txt
160191

161192
When working on docs, you can launch a command that will take care of
162193
generating the docs, build the static website and start a local server you can
163-
access with your browser to see a preview of your changes - to launch this
164-
command do:
194+
later access with a web browser to see a preview of your changes. From the root
195+
of the git repository run:
165196

166197
```shell
167198
task docs:serve
168199
```
169200

170-
If you don't see any error, hit http://127.0.0.1:8000 with your browser.
171-
172-
## Pull Requests
173-
174-
In order to ease code reviews and have your contributions merged faster, here is
175-
a list of items you can check before submitting a PR:
176-
177-
* Create small PRs that are narrowly focused on addressing a single concern.
178-
* PR titles indirectly become part of the CHANGELOG so it's crucial to provide a
179-
good record of **what** change is being made in the title; **why** it was made
180-
will go in the PR description, along with a link to a GitHub issue if it
181-
exists.
182-
* Write tests for the code you wrote.
183-
* Open your PR against the `master` branch.
184-
* Maintain **clean commit history** and use **meaningful commit messages**.
185-
PRs with messy commit history are difficult to review and require a lot of
186-
work to be merged.
187-
* Your PR must pass all CI tests before we will merge it. If you're seeing an
188-
error and don't think
189-
it's your fault, it may not be! The reviewer will help you if there are test
190-
failures that seem
191-
not related to the change you are making.
201+
If you don't see any error, hit http://127.0.0.1:8000 with your browser to
202+
navigate the generated docs.
203+
204+
### Docs publishing
205+
206+
The present git repository has a special branch called `gh-pages` that contains
207+
the generated HTML code for the docs website; every time a change is pushed to
208+
this special branch, GitHub automatically triggers a [deployment][8] to pull the
209+
change and publish a new version of the website. Do not open Pull Requests to
210+
push changes to the `gh-pages` branch, that will be done exclusively from the
211+
CI.
212+
213+
### Docs versioning
214+
215+
In order to provide support for multiple Arduino CLI releases, Documentation is
216+
versioned so that visitors can select which version of the documentation website
217+
should be displayed. Unfortunately this feature isn't provided by GitHub pages
218+
or MkDocs, so we had to implement it on top of the generation process.
219+
220+
Before delving into the details of the generation process, here follow some
221+
requirements that were established to provide versioned documentation:
222+
223+
* A special version of the documentation called `dev` is provided to reflect the
224+
status of the Arduino CLI on the `master` branch - this includes unreleased
225+
features and bugfixes.
226+
* Docs are versioned after the minor version of an Arduino CLI release. For
227+
example, Arduino CLI `0.99.1` and `0.99.2` will be both covered by
228+
documentation version `0.99`.
229+
* The landing page of the documentation website will automatically redirect
230+
visitors to the most recently released version of the Arduino CLI.
231+
232+
To implement the requirements above, the execution of MkDocs is wrapped using a
233+
CLI tool called [Mike][10] that does a few things for us:
234+
235+
* It runs MkDocs targeting subfolders named after the Arduino CLI version, e.g.
236+
documentation for version `0.10.1` can be found under the folder `0.10`.
237+
* It injects an HTML control into the documentation website that lets visitors
238+
choose which version of the docs to browse from a dropdown list.
239+
* It provides a redirect to a version we decide when visitors hit the landing
240+
page of the documentation website.
241+
* It pushes generated contents to the `gh-pages` branch.
242+
243+
> **Note:** unless you're working on the generation process itself, you should
244+
> never run Mike from a local environment, either directly or through the Task
245+
> `docs:publish`. This might result in unwanted changes to the public website.
246+
247+
### Docs automation
248+
249+
In order to avoid unwanted changes to the public website hosting the Arduino
250+
CLI documentation, only Mike is allowed to push changes to the `gh-pages` branch,
251+
and this only happens from within the CI, in a workflow named [docs][11].
252+
253+
The CI is responsible for guessing which version of the Arduino CLI we're
254+
building docs for, so that generated contents will be stored in the appropriate
255+
section of the documentation website. Because this guessing might be fairly
256+
complex, the logic is implemented in a Python script called [`build.py`][12].
257+
The script will determine the version of the Arduino CLI that was modified in
258+
the current commit (either `dev` or an official, numbered release) and whether
259+
the redirect to the latest version that happens on the landing page should be
260+
updated or not.
192261

193262
## Internationalization (i18n)
194263

195-
In order to support i18n in the cli, any messages that are intended to be translated
196-
should be wrapped in a call to `i18n.Tr`. This call allows us to build a catalog of
264+
In order to support i18n in the cli, any messages that are intended to be translated
265+
should be wrapped in a call to `i18n.Tr`. This call allows us to build a catalog of
197266
translatable strings, replacing the reference string at runtime with the localized value.
198267

199268
Adding or modifying these messages requires an i18n update, as this process creates the
@@ -243,4 +312,10 @@ title with the string **[skip changelog]**
243312
[3]: https://www.python.org/downloads/
244313
[4]: https://docs.python.org/3/tutorial/venv.html
245314
[5]: https://github.com/ofek/hatch
246-
[6]: https://github.com/protocolbuffers/protobuf/releases
315+
[6]: https://github.com/protocolbuffers/protobuf/releases
316+
[7]: https://pages.github.com/
317+
[8]: https://github.com/arduino/arduino-cli/deployments?environment=github-pages#activity-log
318+
[9]: https://www.mkdocs.org/
319+
[10]: https://github.com/jimporter/mike
320+
[11]: https://github.com/arduino/arduino-cli/blob/master/.github/workflows/docs.yaml
321+
[12]: https://github.com/arduino/arduino-cli/blob/master/docs/build.py

0 commit comments

Comments
 (0)