diff --git a/.github/actions/docs-preview/README.md b/.github/actions/docs-preview/README.md new file mode 100644 index 0000000000000..e6d6373f0601b --- /dev/null +++ b/.github/actions/docs-preview/README.md @@ -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 | diff --git a/.github/actions/docs-preview/action.yml b/.github/actions/docs-preview/action.yml new file mode 100644 index 0000000000000..c12625c5980de --- /dev/null +++ b/.github/actions/docs-preview/action.yml @@ -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, + }); diff --git a/.github/workflows/doc-preview.yml b/.github/workflows/doc-preview.yml new file mode 100644 index 0000000000000..6f5d3ba9ab1e5 --- /dev/null +++ b/.github/workflows/doc-preview.yml @@ -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