Skip to content

Commit 2fd596b

Browse files
authored
Add docs preview setup guide (#423)
* Add docs preview setup guide * Add some additional info * Add external host * Fix typo * fix typo * Fix link * Fix code callout * Fix typos * Syntactic sugar
1 parent cf4e3df commit 2fd596b

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

docs/docset.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ external_hosts:
1919
- checkvist.com
2020
- commonmark.org
2121
- github.io
22+
- github.com
2223
exclude:
2324
- '_*.md'
2425
subs:
@@ -50,6 +51,7 @@ toc:
5051
- file: automated.md
5152
- file: tooling.md
5253
- file: mapping.md
54+
- file: how-to-set-up-docs-previews.md
5355
- folder: configure
5456
children:
5557
- file: index.md
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# How to set up docs previews
2+
3+
This guide will help you set up docs previews for your GitHub repository.
4+
5+
## GitHub Workflows
6+
7+
The docs preview system consists of three GitHub Workflows:
8+
- [`docs-build.yml`](#build): **Build** the docs on a PR
9+
- [`docs-deploy.yml`](#deploy): **Deploy** the docs to our preview environment
10+
- [`docs-cleanup.yml`](#cleanup): **Cleanup** the docs after a PR is merged or closed
11+
12+
13+
### Build
14+
15+
This workflow is triggered when a PR is opened. The underlying reusable workflow, builds the documentation and uploads it as an artifact.
16+
If the `path-pattern` input does not match any changes in the PR, the workflow will skip the build, but still set a green status check.
17+
This way you only build and deploy the docs when there are changes to the docs and you can still set it as a required status check.
18+
19+
20+
::::{dropdown} .github/workflows/docs-build.yml
21+
:open:
22+
23+
```yaml
24+
---
25+
name: docs-build <1>
26+
27+
on:
28+
pull_request: ~
29+
30+
jobs:
31+
docs-preview:
32+
uses: elastic/docs-builder/.github/workflows/preview-build.yml <2>
33+
with:
34+
path-pattern: docs/** <3>
35+
permissions:
36+
contents: read
37+
pull-requests: read
38+
```
39+
40+
1. The naming is important so that the `docs-deploy` workflow is triggered.
41+
2. This should be the path to your docs folder.
42+
3. Reusable workflow: [elastic/docs-builder/.github/workflows/preview-build.yml](https://github.com/elastic/docs-builder/blob/main/.github/workflows/preview-build.yml)
43+
44+
45+
::::
46+
47+
### Deploy
48+
49+
This workflow is triggered when the `docs-build` workflow is completed. The underlying reusable workflow, downloads the artifact and deploys the docs to our preview environment.
50+
51+
52+
::::{dropdown} .github/workflows/docs-deploy.yml
53+
:open:
54+
55+
```yaml
56+
---
57+
name: docs-deploy
58+
59+
on:
60+
workflow_run:
61+
workflows:
62+
- docs-build <1>
63+
types:
64+
- completed
65+
66+
jobs:
67+
docs-preview:
68+
uses: elastic/docs-builder/.github/workflows/preview-deploy.yml <2>
69+
permissions:
70+
contents: none <3>
71+
id-token: write
72+
deployments: write
73+
actions: read
74+
```
75+
1. The name of the previously mentioned `docs-build` workflow.
76+
2. Reusable workflow: [elastic/docs-builder/.github/workflows/preview-deploy.yml](https://github.com/elastic/docs-builder/blob/main/.github/workflows/preview-deploy.yml)
77+
3. No need to read the code.
78+
79+
::::
80+
81+
### Cleanup
82+
83+
This workflow is triggered when a PR is either merged or closed. The underlying reusable workflow, deletes the docs from the preview environment.
84+
85+
:::{note}
86+
We are aware of the security implications of using `pull_request_target` as described in [this blog post](https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/).
87+
The workflow never checks out the code and doesn't use any user modifiable inputs (e.g. PR title).
88+
:::
89+
90+
::::{dropdown} .github/workflows/docs-cleanup.yml
91+
:open:
92+
```yaml
93+
---
94+
name: docs-cleanup
95+
96+
on:
97+
pull_request_target:
98+
types:
99+
- closed
100+
101+
jobs:
102+
docs-preview:
103+
uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml <1>
104+
permissions:
105+
contents: none <2>
106+
id-token: write
107+
deployments: write
108+
```
109+
110+
1. Reusable workflow: [elastic/docs-builder/.github/workflows/preview-cleanup.yml](https://github.com/elastic/docs-builder/blob/main/.github/workflows/preview-cleanup.yml)
111+
2. No permissions to read content
112+
113+
::::
114+
115+
## Required Status Checks
116+
117+
To ensure that the docs are always in a deployable state, we need to set up required status checks.
118+
119+
In this case only the `docs-build` workflow is required, which will produce a status check named `docs-preview / build`.
120+
121+
![docs-preview required status check](img/docs-preview-required-status-check.png)
122+
123+
124+
## Deployments
125+
126+
If the `docs-build` workflow is successful, the `docs-deploy` workflow will create a deployment visible in the GitHub UI on your PR.
127+
128+
![docs-preview deployment](img/docs-preview-deployment.png)
62.6 KB
Loading
18 KB
Loading

0 commit comments

Comments
 (0)