Skip to content

Commit cadc952

Browse files
nkammahgtback
andauthored
Add a shared GH action for docs preview (#2843)
* Add a shared GH action for docs preview * Rename Guide into Preview * Update .github/actions/docs-preview/action.yml Co-authored-by: Greg Back <[email protected]> * Rename guide-crumb into preview-path * Rename doc preview * Remove preview-path for doc changes --------- Co-authored-by: Greg Back <[email protected]>
1 parent 62a7232 commit cadc952

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## About
2+
3+
GitHub Action to create a GitHub comment with the docs-preview
4+
5+
* [Usage](#usage)
6+
* [Configuration](#configuration)
7+
* [Customizing](#customizing)
8+
* [inputs](#inputs)
9+
10+
## Usage
11+
12+
### Configuration
13+
14+
Given the CI GitHub action:
15+
16+
```yaml
17+
---
18+
on:
19+
pull_request_target:
20+
types: [opened]
21+
22+
permissions:
23+
pull-requests: write
24+
25+
jobs:
26+
doc-preview:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: elastic/docs/.github/actions/docs-preview@current
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
repo: ${{ github.event.repository.name }}
33+
preview-path: 'guide/en/observability/master/index.html'
34+
pr: ${{ github.event.pull_request.number }}
35+
36+
```
37+
38+
## Customizing
39+
40+
### inputs
41+
42+
Following inputs can be used as `step.with` keys
43+
44+
| Name | Type | Description |
45+
|-------------------|---------|------------------------------------------------|
46+
| `preview-path` | String | Path to append to base doc url in preview link |
47+
| `repo` | String | The GitHub repository name without org |
48+
| `github-token` | String | The GitHub token |
49+
| `pr` | String | The GitHub PR number |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: 'docs-preview'
2+
description: 'Add docs-preview comment in the given repository.'
3+
inputs:
4+
repo:
5+
description: 'the name of the repository'
6+
required: true
7+
pr:
8+
description: 'the pull-request'
9+
required: true
10+
github-token:
11+
description: 'The GitHub access token.'
12+
required: true
13+
preview-path:
14+
description: 'Path to append to base doc url in preview link'
15+
required: false
16+
default: ''
17+
runs:
18+
using: "composite"
19+
steps:
20+
- uses: actions/github-script@v7
21+
env:
22+
REPO: ${{ inputs.repo }}
23+
PR: ${{ inputs.pr }}
24+
PREVIEW_PATH: ${{ inputs.preview-path }}
25+
with:
26+
github-token: ${{ inputs.github-token }}
27+
script: |
28+
const { REPO, PR, PREVIEW_PATH } = process.env
29+
30+
const comment = `A documentation preview will be available soon.
31+
Help us out by validating the Buildkite preview and reporting issues [here](https://github.com/elastic/docs/issues/new?labels=buildkite-migration,bug).
32+
33+
- 📚 HTML diff: [Buildkite](https://${REPO}_bk_${PR}.docs-preview.app.elstc.co/diff) - [Jenkins](https://${REPO}_${PR}.docs-preview.app.elstc.co/diff)
34+
- 📙 Preview: [Buildkite](https://${REPO}_bk_${PR}.docs-preview.app.elstc.co/${PREVIEW_PATH}) - [Jenkins](https://${REPO}_${PR}.docs-preview.app.elstc.co/${PREVIEW_PATH})
35+
- 🧪 [Buildkite vs Jenkins diff](https://github.com/elastic/built-docs/compare/${REPO}_bk_${PR}..${REPO}_${PR})`;
36+
37+
github.rest.issues.createComment({
38+
issue_number: PR,
39+
owner: 'elastic',
40+
repo: REPO,
41+
body: comment,
42+
});

.github/workflows/doc-preview.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: test-docs-preview
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request_target:
7+
types: [opened]
8+
9+
permissions:
10+
pull-requests: write
11+
12+
jobs:
13+
doc-preview-pr:
14+
if: github.event_name == 'pull_request_target'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: elastic/docs/.github/actions/docs-preview@main
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
repo: ${{ github.event.repository.name }}
21+
pr: ${{ github.event.pull_request.number }}
22+
23+
doc-preview-manual:
24+
if: github.event_name == 'workflow_dispatch'
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: elastic/docs/.github/actions/docs-preview@main
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
repo: ${{ github.event.repository.name }}
31+
preview-path: 'guide/en/observability/master/index.html'
32+
pr: 2842

0 commit comments

Comments
 (0)