Skip to content

Commit 8b13fa5

Browse files
committed
Add a shared GH action for docs preview
1 parent 39c83fd commit 8b13fa5

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-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+
guide-crumb: '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 | Default | Description |
45+
|-------------------|---------|-----------------------------|-----------------------------------------|
46+
| `guide-crumb` | String | | The URL crumb to append to base doc url |
47+
| `repo` | String | | The GitHub repository name without org |
48+
| `github-token` | String | | The GitHub token |
49+
| `pr` | String | | The GitHub PR |
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+
guide-crumb:
14+
description: 'the name of the project'
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+
GUIDE_CRUMB: ${{ inputs.guide-crumb }}
25+
with:
26+
github-token: ${{ inputs.github-token }}
27+
script: |
28+
const { REPO, PR, GUIDE_CRUMB } = 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+
- 📙 Guide: [Buildkite](https://${REPO}_bk_${PR}.docs-preview.app.elstc.co/${GUIDE_CRUMB}) - [Jenkins](https://${REPO}_${PR}.docs-preview.app.elstc.co/${GUIDE_CRUMB})
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+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
guide-crumb: 'guide/en/observability/master/index.html'
22+
pr: ${{ github.event.pull_request.number }}
23+
24+
doc-preview-manual:
25+
if: github.event_name == 'workflow_dispatch'
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: elastic/docs/.github/actions/docs-preview@main
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
repo: ${{ github.event.repository.name }}
32+
guide-crumb: 'guide/en/observability/master/index.html'
33+
pr: 2842

0 commit comments

Comments
 (0)