Skip to content

Commit cff7668

Browse files
authored
Update onboarding docs for elastic/docs-actions workflows (#3162)
- Replace docs-builder preview-build/preview-cleanup with docs-actions @v1: docs-build, docs-deploy, docs-preview-cleanup (two-phase security model) - Document required check docs-build / build and branch protection migration - Note fork PR org membership via docs-actions#85 (no public org visibility step) - Refresh move-ref-docs Step 3 and content-sources tagged-branch CI examples Made-with: Cursor
1 parent a079ea7 commit cff7668

4 files changed

Lines changed: 170 additions & 75 deletions

File tree

docs/configure/content-sources.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,33 @@ To get started:
4848

4949
#### CI configuration
5050

51-
To ensure repositories that use the [tagged branching strategy](#tagged) can be onboarded correctly, our CI integration needs to have appropriate `push`
52-
branch triggers.
51+
To ensure repositories that use the [tagged branching strategy](#tagged) can be onboarded correctly, our CI integration needs appropriate `push` branch triggers and matching settings on the reusable workflows in [`elastic/docs-actions`](https://github.com/elastic/docs-actions).
52+
53+
Also add **`docs-deploy.yml`** and **`docs-preview-cleanup.yml`** as described in [How to set up docs previews](../migration/guide/how-to-set-up-docs-previews.md); the snippet below only highlights the tagged-branching-specific parts of **docs-build** (and the same `with:` block must be passed through on your **docs-deploy** consumer job).
5354

5455
```yml
5556
name: docs-build
5657

5758
on:
59+
pull_request:
60+
types: [opened, synchronize, reopened]
5861
push:
5962
branches:
6063
- main
6164
- '\d+.\d+' <1>
62-
pull_request_target: ~
6365
merge_group: ~
6466

67+
permissions:
68+
contents: read
69+
pull-requests: read
70+
6571
jobs:
66-
docs-preview:
67-
uses: elastic/docs-builder/.github/workflows/preview-build.yml@main
72+
build:
73+
uses: elastic/docs-actions/.github/workflows/docs-build.yml@v1
6874
with:
6975
path-pattern: docs/**
70-
permissions:
71-
deployments: write
72-
id-token: write
73-
contents: read
74-
pull-requests: write
76+
use-release-branches: true <2>
7577
```
7678
7779
1. Ensure version branches are built and publish their links ahead of time.
80+
2. Matches **docs-deploy** `with:` (`path-pattern`, `use-release-branches`) so release-line pushes still produce `links.json` when needed even if `docs/**` is unchanged for a long time.

docs/contribute/add-repo.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ repositories:
3838
3939
::::{step} Add the workflow actions to the repository
4040
41-
Add the following actions to the `.github/workflows` directory of your repo:
42-
43-
- https://github.com/elastic/docs-builder/blob/main/.github%2Fworkflows%2Fpreview-build.yml
44-
- https://github.com/elastic/docs-builder/blob/main/.github/workflows/preview-cleanup.yml
41+
Add the documentation CI workflows to the `.github/workflows` directory. Reusable workflows are maintained in [`elastic/docs-actions`](https://github.com/elastic/docs-actions); consumer repos add **`docs-build.yml`**, **`docs-deploy.yml`**, and **`docs-preview-cleanup.yml`** that call those workflows at `@v1`. Follow [How to set up docs previews](../migration/guide/how-to-set-up-docs-previews.md) for full YAML and permissions.
4542

4643
Then, successfully run a docs build on the `main` branch. This is a requirement. For example, you can merge a docs pull request to `main` after adding the workflow actions.
4744

docs/migration/guide/how-to-set-up-docs-previews.md

Lines changed: 101 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22

33
This guide will help you set up docs previews for your GitHub repository.
44

5-
## GitHub Workflows
5+
Reusable workflows live in [`elastic/docs-actions`](https://github.com/elastic/docs-actions). Pin them to **`@v1`** so the docs team can ship updates independently of [`elastic/docs-builder`](https://github.com/elastic/docs-builder). Reference repos: [elastic/elastic-otel-rum-js](https://github.com/elastic/elastic-otel-rum-js), [elastic/ecs-logging-nodejs](https://github.com/elastic/ecs-logging-nodejs).
66

7-
The docs preview system consists of two GitHub Workflows:
8-
- [`docs-build.yml`](#build): **Build** the docs on a PR
9-
- [`docs-cleanup.yml`](#cleanup): **Cleanup** the docs after a PR is merged or closed
7+
## GitHub workflows
8+
9+
The integration uses **three** workflows:
10+
11+
- [`docs-build.yml`](#build) — Required checks: validate and build docs in an unprivileged context (`pull_request`, `push`, `merge_group`).
12+
- [`docs-deploy.yml`](#deploy) — Runs after `docs-build` completes (`workflow_run`). Handles preview deployment, PR comments, and org checks; never checks out untrusted code before gating.
13+
- [`docs-preview-cleanup.yml`](#preview-cleanup) — Removes preview artifacts when a PR is closed (`pull_request_target`).
14+
15+
This follows GitHub’s [recommended two-phase approach](https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/) for fork PRs: the **build** workflow uses `pull_request` (not `pull_request_target`) for the main validation path.
1016

1117

1218
### Build
1319

14-
This workflow is triggered when a PR is opened. The underlying reusable workflow, builds the documentation and uploads it as an artifact.
15-
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.
16-
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.
20+
This workflow runs on pull requests, pushes to your default branch (and optionally release branches), and merge queue events. The reusable workflow builds the documentation and uploads artifacts for the deploy phase.
1721

22+
If the `path-pattern` input does not match any changes in the PR, the workflow can skip the heavy build while still reporting a successful status check, so you can keep **docs-build** as a required check. The default path pattern is `docs/**` (see [optional inputs](#optional-workflow-inputs)).
1823

1924
::::{tab-set}
2025

@@ -25,83 +30,141 @@ This way you only build and deploy the docs when there are changes to the docs a
2530
name: docs-build
2631

2732
on:
33+
pull_request:
34+
types: [opened, synchronize, reopened]
2835
push:
29-
branches:
30-
- main <1>
31-
- '\d+.\d+' <2>
32-
pull_request_target: ~
36+
branches:
37+
- main <1>
38+
merge_group: ~
39+
40+
permissions:
41+
contents: read
42+
pull-requests: read
3343

3444
jobs:
35-
docs-preview:
36-
uses: elastic/docs-builder/.github/workflows/preview-build.yml <3>
37-
with:
38-
path-pattern: docs/** <4>
39-
permissions:
40-
id-token: write
41-
deployments: write
42-
contents: read
43-
pull-requests: read
45+
build:
46+
uses: elastic/docs-actions/.github/workflows/docs-build.yml@v1 <2>
4447
```
4548
46-
1. You need to adjust this to your default branch. E.g `main`, `master`, etc.
47-
2. Optional, a match for the branch you wish to publish to production if different from the first.
48-
3. Reusable workflow: [elastic/docs-builder/.github/workflows/preview-build.yml](https://github.com/elastic/docs-builder/blob/main/.github/workflows/preview-build.yml)
49-
4. This should be the path to your `docs` folder.
49+
1. Adjust to your default branch (`main`, `master`, etc.).
50+
2. Reusable workflow: [`elastic/docs-actions/.github/workflows/docs-build.yml`](https://github.com/elastic/docs-actions/blob/main/.github/workflows/docs-build.yml)
5051

5152
:::
5253

5354
::::
5455

5556

56-
### Cleanup
57+
### Deploy
58+
59+
This workflow runs when **docs-build** finishes. It downloads artifacts, deploys previews, manages GitHub deployments, and may post or update PR comments. It does **not** use `pull_request_target` on the PR head for the same event as the build; it is triggered via `workflow_run` after the build workflow completes.
60+
61+
::::{tab-set}
62+
63+
:::{tab-item} .github/workflows/docs-deploy.yml
64+
65+
```yaml
66+
---
67+
name: docs-deploy
68+
69+
on:
70+
workflow_run:
71+
workflows: [docs-build]
72+
types: [completed]
5773
58-
This workflow is triggered when a PR is either merged or closed. The underlying reusable workflow, deletes the docs from the preview environment.
74+
permissions:
75+
contents: read
76+
deployments: write
77+
id-token: write
78+
pull-requests: write
79+
actions: read
80+
81+
jobs:
82+
deploy:
83+
uses: elastic/docs-actions/.github/workflows/docs-deploy.yml@v1 <1>
84+
```
85+
86+
1. Reusable workflow: [`elastic/docs-actions/.github/workflows/docs-deploy.yml`](https://github.com/elastic/docs-actions/blob/main/.github/workflows/docs-deploy.yml)
87+
88+
:::
89+
90+
::::
91+
92+
93+
### Preview cleanup
94+
95+
This workflow runs when a PR is **closed** (merged or not). It deletes preview content from the preview environment.
5996

6097
:::{note}
61-
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/).
62-
The workflow never checks out the code and doesn't use any user modifiable inputs (e.g. PR title).
98+
Using `pull_request_target` here is intentional. As in GitHub’s guidance, this workflow should **not** check out the PR head for arbitrary code execution with elevated secrets. The reusable cleanup workflow follows that model.
6399
:::
64100

65101
::::{tab-set}
66102

67-
:::{tab-item} .github/workflows/docs-cleanup.yml
103+
:::{tab-item} .github/workflows/docs-preview-cleanup.yml
68104

69105
```yaml
70106
---
71-
name: docs-cleanup
107+
name: docs-preview-cleanup
72108
73109
on:
74110
pull_request_target:
75111
types:
76112
- closed
77113
78114
jobs:
79-
docs-preview:
80-
uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml <1>
115+
cleanup:
116+
uses: elastic/docs-actions/.github/workflows/docs-preview-cleanup.yml@v1 <1>
81117
permissions:
82118
contents: none <2>
83119
id-token: write
84120
deployments: write
85121
```
86122

87-
1. Reusable workflow: [elastic/docs-builder/.github/workflows/preview-cleanup.yml](https://github.com/elastic/docs-builder/blob/main/.github/workflows/preview-cleanup.yml)
88-
2. No permissions to read content
123+
1. Reusable workflow: [`elastic/docs-actions/.github/workflows/docs-preview-cleanup.yml`](https://github.com/elastic/docs-actions/blob/main/.github/workflows/docs-preview-cleanup.yml)
124+
2. No permission to read repository contents from the workflow token as provided here; adjust only if your org policy requires a different matrix.
89125

90126
:::
91127

92128
::::
93129

94-
## Required Status Checks
95130

96-
To ensure that the docs are always in a deployable state, we need to set up required status checks.
131+
### Fork pull requests
132+
133+
Contributors opening PRs from forks still get **build validation** from **docs-build**. Preview **deploy** for fork PRs may depend on membership checks in the deploy workflow. That logic is implemented in `docs-actions` (for example, [elastic/docs-actions#85](https://github.com/elastic/docs-actions/pull/85) — org membership is verified via the GitHub API; contributors do **not** need to change Elastic org visibility on their public profile for that check).
134+
135+
136+
### Optional workflow inputs
137+
138+
Pass `with:` on the **`uses:`** line when you need non-default behavior (for example documentation outside `docs/`, [tagged branching](../../configure/content-sources.md), or Vale). Inputs are defined on each reusable workflow’s `workflow_call` interface — see the files under [`.github/workflows/`](https://github.com/elastic/docs-actions/tree/main/.github/workflows) in `docs-actions`.
139+
140+
Common cases:
97141

98-
In this case only the `docs-build` workflow is required, which will produce a status check named `docs-preview / build`.
142+
- **`path-pattern`** — Glob for which paths count as doc changes (default `docs/**`). If you set it on **docs-build**, use the **same** values on **docs-deploy** so both phases agree.
143+
- **`use-release-branches`** — Set to `true` on **both** build and deploy when you use semver release branches (for example `8.11`) and need link-index / build behavior on pushes that do not touch `docs/**`. See [CI configuration in *Content sources*](../../configure/content-sources.md).
144+
145+
Example fragment (only the job — combine with triggers and permissions from the tabs above):
146+
147+
```yaml
148+
jobs:
149+
build:
150+
uses: elastic/docs-actions/.github/workflows/docs-build.yml@v1
151+
with:
152+
path-pattern: docs/**
153+
use-release-branches: true
154+
```
155+
156+
157+
## Required status checks
158+
159+
To keep docs in a deployable state, enable required status checks for the **docs-build** workflow. The check name is typically **`docs-build / build`** (workflow name + job id).
99160

100161
![docs-preview required status check](img/docs-preview-required-status-check.png)
101162

102163

103164
## Deployments
104165

105-
If the `docs-build` workflow is successful, the `docs-deploy` workflow will create a deployment visible in the GitHub UI on your PR.
166+
After **docs-build** succeeds, **docs-deploy** runs and can create or update a deployment in the GitHub UI for the PR.
106167

107168
![docs-preview deployment](img/docs-preview-deployment.png)
169+
170+
If you previously required **`docs-preview / build`** or **`preview-build`**, update branch protection to require **`docs-build`** / **`docs-build / build`** instead.

docs/migration/guide/move-ref-docs.md

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,63 +103,95 @@ Example commit: [#398/commit](https://github.com/elastic/apm-agent-android/pull/
103103

104104
### Step 3: Add the new CI checks
105105

106-
There are two CI checks to add:
106+
Add three workflow files from [`elastic/docs-actions`](https://github.com/elastic/docs-actions) (`@v1`). Full copy-paste examples and explanations are in [How to set up docs previews](./how-to-set-up-docs-previews.md).
107107

108-
**`docs-build.yml`**
109-
Add a file named `docs-build.yml` at `.github/workflows/docs-build.yml`. The contents of this file are below:
108+
**`docs-build.yml`**`.github/workflows/docs-build.yml`
110109

111110
```yml
112111
name: docs-build
113112

114113
on:
114+
pull_request:
115+
types: [opened, synchronize, reopened]
115116
push:
116117
branches:
117118
- main
118119
- '\d+.\d+' <1>
119-
pull_request_target: ~
120120
merge_group: ~
121121

122+
permissions:
123+
contents: read
124+
pull-requests: read
125+
122126
jobs:
123-
docs-preview:
124-
uses: elastic/docs-builder/.github/workflows/preview-build.yml@main
127+
build:
128+
uses: elastic/docs-actions/.github/workflows/docs-build.yml@v1
125129
with:
126-
path-pattern: docs/**
127-
permissions:
128-
deployments: write
129-
id-token: write
130-
contents: read
131-
pull-requests: read
130+
path-pattern: docs/** <2>
131+
use-release-branches: true <3>
132132
```
133133
134-
1. Optional match for version branches if you do not wish to publish to production from `main`.
134+
1. Optional: semver-style branches when docs publish from a release line rather than only `main`.
135+
2. Update if your Markdown does not live under `docs/`.
136+
3. Pair with the same flags on **docs-deploy**; set `use-release-branches` only when you use release-line pushes as above.
135137

136-
Learn more about this file: [`docs-build.yml`](./how-to-set-up-docs-previews.md#build).
138+
[`docs-build.yml`](./how-to-set-up-docs-previews.md#build)
137139

138-
:::{important}
139-
If the documentation you are adding will not live in the `/docs/*` dir of the repository, you must update the `path-pattern` appropriately. Please reach out in #docs-team if you need help with this.
140-
:::
140+
**`docs-deploy.yml`** — `.github/workflows/docs-deploy.yml`
141+
142+
```yml
143+
name: docs-deploy
144+
145+
on:
146+
workflow_run:
147+
workflows: [docs-build]
148+
types: [completed]
149+
150+
permissions:
151+
contents: read
152+
deployments: write
153+
id-token: write
154+
pull-requests: write
155+
actions: read
141156
142-
**`docs-cleanup.yml`**
143-
Add a file named `docs-cleanup.yml` at `.github/workflows/docs-cleanup.yml`. The contents of this file are below:
157+
jobs:
158+
deploy:
159+
uses: elastic/docs-actions/.github/workflows/docs-deploy.yml@v1
160+
with:
161+
path-pattern: docs/**
162+
use-release-branches: true
163+
```
164+
165+
[`docs-deploy.yml`](./how-to-set-up-docs-previews.md#deploy)
166+
167+
**`docs-preview-cleanup.yml`** — `.github/workflows/docs-preview-cleanup.yml`
144168

145169
```yml
146-
name: docs-cleanup
170+
name: docs-preview-cleanup
147171
148172
on:
149173
pull_request_target:
150174
types:
151175
- closed
152176
153177
jobs:
154-
docs-preview:
155-
uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main
178+
cleanup:
179+
uses: elastic/docs-actions/.github/workflows/docs-preview-cleanup.yml@v1
156180
permissions:
157181
contents: none
158182
id-token: write
159183
deployments: write
160184
```
161185

162-
Learn more about this file: [`docs-cleanup.yml`](./how-to-set-up-docs-previews.md#cleanup)
186+
[`docs-preview-cleanup.yml`](./how-to-set-up-docs-previews.md#preview-cleanup)
187+
188+
:::{important}
189+
If the documentation you are adding will not live in the `/docs/*` dir of the repository, you must update `path-pattern` on **both** `docs-build` and `docs-deploy` (and adjust `use-release-branches` only if your branching strategy requires it). Please reach out in #docs-team if you need help with this.
190+
:::
191+
192+
:::{note}
193+
If you only use continuous deployment from `main` (no release-line branches), omit `\d+.\d+` from `push.branches`, remove `use-release-branches`, and drop the matching `with:` from **docs-deploy** — see the minimal examples in [How to set up docs previews](./how-to-set-up-docs-previews.md).
194+
:::
163195

164196
Example PR: [#398](https://github.com/elastic/apm-agent-android/pull/398)
165197

0 commit comments

Comments
 (0)