Skip to content

Commit 80bfec0

Browse files
committed
Add docs preview setup guide
1 parent 7ec2d91 commit 80bfec0

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

docs/docset.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ toc:
5050
- file: automated.md
5151
- file: tooling.md
5252
- file: mapping.md
53+
- file: how-to-set-up-docs-previews.md
5354
- folder: configure
5455
children:
5556
- file: index.md
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 the docs on a PR
9+
- `docs-deploy.yml`: Deploy the docs to our preview environment
10+
- `docs-cleanup.yml`: 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` intput 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 # The naming is important, don't change it
26+
27+
on:
28+
pull_request: ~
29+
30+
jobs:
31+
docs-preview:
32+
uses: elastic/docs-builder/.github/workflows/preview-build.yml
33+
with:
34+
path-pattern: docs/** # The path to your docs folder.
35+
permissions: # Only needs read permissions.
36+
contents: read
37+
pull-requests: read
38+
```
39+
40+
::::
41+
42+
### Deploy
43+
44+
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.
45+
46+
47+
::::{dropdown} .github/workflows/docs-deploy.yml
48+
:open:
49+
50+
```yaml
51+
---
52+
name: docs-deploy
53+
54+
on:
55+
workflow_run:
56+
workflows: [docs-build] # The name of the docs-build workflow.
57+
types:
58+
- completed
59+
60+
jobs:
61+
docs-preview:
62+
uses: elastic/docs-builder/.github/workflows/preview-deploy.yml
63+
permissions:
64+
contents: none # No need to read the code.
65+
id-token: write
66+
deployments: write
67+
actions: read
68+
```
69+
70+
::::
71+
72+
### Cleanup
73+
74+
This workflow is triggered when a PR is either merged or closed. The underlying reusable workflow, deletes the docs from the preview environment.
75+
76+
::::{dropdown} .github/workflows/docs-cleanup.yml
77+
:open:
78+
79+
```yaml
80+
---
81+
name: docs-cleanup
82+
83+
on:
84+
pull_request_target: # We are using the pull_request_target event, but the code is never checked out.
85+
types:
86+
- closed
87+
88+
jobs:
89+
docs-preview:
90+
uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml
91+
permissions:
92+
contents: none # We don't even grant read permissions, because the code is never checked out.
93+
id-token: write
94+
deployments: write
95+
```
96+
97+
::::
98+
99+
## Required Status Checks
100+
101+
To ensure that the docs are always in a deployable state, we need to set up required status checks.
102+
103+
In this case only the `docs-build` workflow is required, which will produce a status check named `docs-preview / build`.
104+
105+
![docs-preview required status check](img/docs-preview-required-status-check.png)
106+
107+
108+
## Deployments
109+
110+
If the `docs-build` workflow is successful, the `docs-deploy` workflow will create a deployment visible in the GitHub UI on your PR.
111+
112+
![docs-preview deployment](img/docs-preview-deployment.png)
62.6 KB
Loading
18 KB
Loading

0 commit comments

Comments
 (0)