Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/actions/docs-preview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## About

GitHub Action to create a GitHub comment with the docs-preview

* [Usage](#usage)
* [Configuration](#configuration)
* [Customizing](#customizing)
* [inputs](#inputs)

## Usage

### Configuration

Given the CI GitHub action:

```yaml
---
on:
pull_request_target:
types: [opened]

permissions:
pull-requests: write

jobs:
doc-preview:
runs-on: ubuntu-latest
steps:
- uses: elastic/docs/.github/actions/docs-preview@current
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.event.repository.name }}
preview-path: 'guide/en/observability/master/index.html'
pr: ${{ github.event.pull_request.number }}

```

## Customizing

### inputs

Following inputs can be used as `step.with` keys

| Name | Type | Description |
|-------------------|---------|------------------------------------------------|
| `preview-path` | String | Path to append to base doc url in preview link |
| `repo` | String | The GitHub repository name without org |
| `github-token` | String | The GitHub token |
| `pr` | String | The GitHub PR number |
42 changes: 42 additions & 0 deletions .github/actions/docs-preview/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'docs-preview'
description: 'Add docs-preview comment in the given repository.'
inputs:
repo:
description: 'the name of the repository'
required: true
pr:
description: 'the pull-request'
required: true
github-token:
description: 'The GitHub access token.'
required: true
preview-path:
description: 'Path to append to base doc url in preview link'
required: false
default: ''
runs:
using: "composite"
steps:
- uses: actions/github-script@v7
env:
REPO: ${{ inputs.repo }}
PR: ${{ inputs.pr }}
PREVIEW_PATH: ${{ inputs.preview-path }}
with:
github-token: ${{ inputs.github-token }}
script: |
const { REPO, PR, PREVIEW_PATH } = process.env

const comment = `A documentation preview will be available soon.
Help us out by validating the Buildkite preview and reporting issues [here](https://github.com/elastic/docs/issues/new?labels=buildkite-migration,bug).

- 📚 HTML diff: [Buildkite](https://${REPO}_bk_${PR}.docs-preview.app.elstc.co/diff) - [Jenkins](https://${REPO}_${PR}.docs-preview.app.elstc.co/diff)
- 📙 Preview: [Buildkite](https://${REPO}_bk_${PR}.docs-preview.app.elstc.co/${PREVIEW_PATH}) - [Jenkins](https://${REPO}_${PR}.docs-preview.app.elstc.co/${PREVIEW_PATH})
- 🧪 [Buildkite vs Jenkins diff](https://github.com/elastic/built-docs/compare/${REPO}_bk_${PR}..${REPO}_${PR})`;

github.rest.issues.createComment({
issue_number: PR,
owner: 'elastic',
repo: REPO,
body: comment,
});
32 changes: 32 additions & 0 deletions .github/workflows/doc-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: test-docs-preview

on:
workflow_dispatch:
pull_request_target:
types: [opened]

permissions:
pull-requests: write

jobs:
doc-preview-pr:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- uses: elastic/docs/.github/actions/docs-preview@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.event.repository.name }}
pr: ${{ github.event.pull_request.number }}

doc-preview-manual:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: elastic/docs/.github/actions/docs-preview@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.event.repository.name }}
preview-path: 'guide/en/observability/master/index.html'
pr: 2842