-
Notifications
You must be signed in to change notification settings - Fork 43
Split docs preview: reusable Docker workflow + local dotnet workflow #3064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9392937
Split docs preview: reusable Docker workflow + local dotnet workflow
Mpdreamz 460bd48
fix(ci): use glob patterns for push branch/tag filters in docs-previe…
Mpdreamz 59e7e9c
chore(ci): use [0-9] character-class globs for docs-preview-local pus…
Mpdreamz ec7524f
fix(ci): drop pull_request_target checks from docs-preview-local (not…
Mpdreamz 795e68a
fix(ci): align docs-preview-local with pull_request/push triggers only
Mpdreamz 298ccc7
Update .github/workflows/docs-preview-local.yml
Mpdreamz 1860692
feat(ci): docs-preview-cleanup-local; preview-cleanup workflow_call only
Mpdreamz f1cd7d0
chore(ci): remove preview-build/preview-cleanup; inline docs-preview-…
Mpdreamz 69c794f
Merge origin/main into feature/preview-build-local
Mpdreamz ee09d23
fix(ci): scope docs-preview-local concurrency by PR number on pull_re…
Mpdreamz fc79284
fix(preview): match IGNORE_PATTERNS on paths without filesystem glob
Mpdreamz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,392 @@ | ||
| name: Docs preview (local) | ||
|
|
||
| # In-repo docs build using dotnet run (elastic/docs-builder only). Replaces the former | ||
| # github.repository branches in preview-build.yml; consumers still use preview-build.yml (Docker). | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - synchronize | ||
| - reopened | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| - '\d+.\d+.\d+' | ||
| - '\d+.\d+' | ||
| - '\d+.x' | ||
| tags: | ||
| - 'v?\d+.\d+.\d+' | ||
| - 'v?\d+.\d+' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| pull-requests: read | ||
|
|
||
| concurrency: | ||
| group: docs-preview-local-${{ github.event.pull_request.head.ref || github.ref }} | ||
| cancel-in-progress: ${{ startsWith(github.event_name, 'pull_request') }} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| jobs: | ||
| match: | ||
| if: github.event.repository.fork == false | ||
| runs-on: ubuntu-latest | ||
|
Mpdreamz marked this conversation as resolved.
|
||
| permissions: | ||
| contents: none | ||
| deployments: none | ||
| pull-requests: none | ||
| id-token: none | ||
| outputs: | ||
| content-source-match: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-match, steps.push-check.outputs.content-source-match, steps.merge-group-check.outputs.content-source-match) }} | ||
| content-source-next: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-next, steps.push-check.outputs.content-source-next, steps.merge-group-check.outputs.content-source-next) }} | ||
| content-source-current: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-current, steps.push-check.outputs.content-source-current, steps.merge-group-check.outputs.content-source-current) }} | ||
| content-source-edge: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-edge, steps.push-check.outputs.content-source-edge, steps.merge-group-check.outputs.content-source-edge) }} | ||
| content-source-speculative: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-speculative, steps.push-check.outputs.content-source-speculative, steps.merge-group-check.outputs.content-source-speculative) }} | ||
| steps: | ||
| - name: Find merge-group base branch | ||
| if: contains(fromJSON('["merge_group"]'), github.event_name) | ||
| id: merge-group-base-branch | ||
| run: | | ||
| BASE_BRANCH=$(basename "${{ github.event.merge_group.base_ref }}") | ||
| echo "base_ref=${BASE_BRANCH}" >> $GITHUB_OUTPUT | ||
| - name: Match for merge-group events | ||
| id: merge-group-check | ||
| if: contains(fromJSON('["merge_group"]'), github.event_name) | ||
| uses: elastic/docs-builder/actions/assembler-match@main | ||
| with: | ||
| ref_name: ${{ steps.merge-group-base-branch.outputs.base_ref }} | ||
| repository: ${{ github.repository }} | ||
|
|
||
| - name: Match for PR events | ||
| id: pr-check | ||
| if: contains(fromJSON('["pull_request", "pull_request_target"]'), github.event_name) | ||
| uses: elastic/docs-builder/actions/assembler-match@main | ||
| with: | ||
| ref_name: ${{ github.base_ref }} | ||
| repository: ${{ github.repository }} | ||
| - name: Match for PR events debug | ||
| if: contains(fromJSON('["pull_request", "pull_request_target"]'), github.event_name) | ||
| run: | | ||
| echo "ref=${{ github.base_ref }}" | ||
| echo "repo=${{ github.repository }}" | ||
|
|
||
| - name: Match for push events | ||
| id: push-check | ||
| if: contains(fromJSON('["push"]'), github.event_name) | ||
| uses: elastic/docs-builder/actions/assembler-match@main | ||
| with: | ||
| ref_name: ${{ github.ref_name }} | ||
| repository: ${{ github.repository }} | ||
| - name: Match for push events debug | ||
| if: contains(fromJSON('["push"]'), github.event_name) | ||
| run: | | ||
| echo "ref=${{ github.ref_name }}" | ||
| echo "repo=${{ github.repository }}" | ||
|
|
||
| - name: Debug outputs | ||
| run: | | ||
| echo "content-source-match: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-match, steps.push-check.outputs.content-source-match, steps.merge-group-check.outputs.content-source-match) }}" | ||
| echo "content-source-next: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-next, steps.push-check.outputs.content-source-next, steps.merge-group-check.outputs.content-source-next) }}" | ||
| echo "content-source-current: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-current, steps.push-check.outputs.content-source-current, steps.merge-group-check.outputs.content-source-current) }}" | ||
| echo "content-source-edge: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-edge, steps.push-check.outputs.content-source-edge, steps.merge-group-check.outputs.content-source-edge) }}" | ||
| echo "content-source-speculative: ${{ format('{0}{1}{2}', steps.pr-check.outputs.content-source-speculative, steps.push-check.outputs.content-source-speculative, steps.merge-group-check.outputs.content-source-speculative) }}" | ||
|
|
||
| check: | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - match | ||
| permissions: | ||
| contents: read | ||
| deployments: none | ||
| id-token: none | ||
| pull-requests: read | ||
| outputs: | ||
| any_modified: ${{ steps.check-files.outputs.any_modified }} | ||
| all_changed_files: ${{ steps.check-files.outputs.all_changed_files }} | ||
| added_files: ${{ steps.check-modified-file-detail.outputs.added_files }} | ||
| modified_files: ${{ steps.check-modified-file-detail.outputs.modified_files }} | ||
| deleted_files: ${{ steps.check-modified-file-detail.outputs.deleted_files }} | ||
| renamed_files: ${{ steps.check-modified-file-detail.outputs.renamed_files }} | ||
| steps: | ||
| - name: Checkout | ||
| if: contains(fromJSON('["push", "merge_group", "workflow_dispatch"]'), github.event_name) | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
|
|
||
| - name: Get changed files | ||
| if: contains(fromJSON('["push", "merge_group", "pull_request", "pull_request_target"]'), github.event_name) | ||
| id: check-files | ||
| uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1 | ||
| with: | ||
| files: '**' | ||
| files_ignore: | | ||
| .github/** | ||
| README.md | ||
|
|
||
| - name: Get modified file detail | ||
| if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name) | ||
| id: check-modified-file-detail | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| env: | ||
| IGNORE_PATTERNS: | | ||
| .github/** | ||
| README.md | ||
| with: | ||
| script: | | ||
| const ignorePatterns = process.env.IGNORE_PATTERNS; | ||
| const ignoreGlobber = await glob.create(ignorePatterns); | ||
| const ignoredPaths = new Set(await ignoreGlobber.glob()); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| const { owner, repo } = context.repo; | ||
|
|
||
| let allFiles; | ||
| if (context.eventName === 'merge_group') { | ||
| const baseSha = context.payload.merge_group.base_sha; | ||
| const headSha = context.payload.merge_group.head_sha; | ||
| const comparison = await github.rest.repos.compareCommitsWithBasehead({ | ||
| owner, | ||
| repo, | ||
| basehead: `${baseSha}...${headSha}`, | ||
| }); | ||
| allFiles = comparison.data.files || []; | ||
| } else { | ||
| const pull_number = context.payload.pull_request.number; | ||
| allFiles = await github.paginate(github.rest.pulls.listFiles, { | ||
| owner, | ||
| repo, | ||
| pull_number, | ||
| }); | ||
| } | ||
|
|
||
| const filteredFiles = allFiles.filter(file => !ignoredPaths.has(file.filename)); | ||
|
|
||
| const added = []; | ||
| const modified = []; | ||
| const deleted = []; | ||
| const renamed = []; | ||
|
|
||
| for (const file of filteredFiles) { | ||
| switch (file.status) { | ||
| case 'added': | ||
| added.push(file.filename); | ||
| break; | ||
| case 'modified': | ||
| modified.push(file.filename); | ||
| break; | ||
| case 'removed': | ||
| deleted.push(file.filename); | ||
| break; | ||
| case 'renamed': | ||
| renamed.push(`${file.previous_filename}:${file.filename}`); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| core.setOutput('added_files', added.join(' ')); | ||
| core.setOutput('modified_files', modified.join(' ')); | ||
| core.setOutput('deleted_files', deleted.join(' ')); | ||
| core.setOutput('renamed_files', renamed.join(' ')); | ||
|
|
||
| build: | ||
| if: github.event.repository.fork == false | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| deployments: none | ||
| id-token: write | ||
| pull-requests: none | ||
| outputs: | ||
| deployment_result: ${{ steps.deployment.outputs.result }} | ||
| path_prefix: ${{ steps.generate-path-prefix.outputs.result }} | ||
| env: | ||
| GITHUB_PR_REF_NAME: ${{ github.event.pull_request.head.ref }} | ||
| MATCH: ${{ needs.match.outputs.content-source-match }} | ||
| ADDED_FILES: ${{ needs.check.outputs.added_files }} | ||
| MODIFIED_FILES: ${{ needs.check.outputs.modified_files }} | ||
| DELETED_FILES: ${{ needs.check.outputs.deleted_files }} | ||
| RENAMED_FILES: ${{ needs.check.outputs.renamed_files }} | ||
| needs: | ||
| - check | ||
| - match | ||
| steps: | ||
| - name: Checkout | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Create Deployment | ||
| # disabled: deployments are not enabled on this branch | ||
| if: > | ||
| false | ||
| && env.MATCH == 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| && ( | ||
| contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) | ||
| || startsWith(github.event_name, 'pull_request') | ||
| ) | ||
| uses: actions/github-script@v8 | ||
| id: deployment | ||
| env: | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| REF: ${{ startsWith(github.event_name, 'pull_request') && github.event.pull_request.head.sha || github.ref_name }} | ||
| with: | ||
| result-encoding: string | ||
| script: | | ||
| const { owner, repo } = context.repo; | ||
| const prNumber = process.env.PR_NUMBER; | ||
| const environment = 'docs-preview'; | ||
| const task = prNumber ? `docs-preview-${prNumber}` : undefined; | ||
| const deployment = await github.rest.repos.createDeployment({ | ||
| owner, | ||
| repo, | ||
| environment, | ||
| task, | ||
| ref: process.env.REF, | ||
| auto_merge: false, | ||
| transient_environment: true, | ||
| required_contexts: [], | ||
| }) | ||
| await github.rest.repos.createDeploymentStatus({ | ||
| deployment_id: deployment.data.id, | ||
| owner, | ||
| repo, | ||
| state: "in_progress", | ||
| log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | ||
| }) | ||
| return deployment.data.id | ||
|
|
||
| - name: Generate env.PATH_PREFIX | ||
| id: generate-path-prefix | ||
| # disabled: preview path prefix is not needed on this branch | ||
| if: > | ||
| false | ||
| && env.MATCH == 'true' | ||
| && steps.deployment.outputs.result | ||
| env: | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| GITHUB_REF_NAME: ${{ github.ref_name }} | ||
| run: | | ||
| case "${GITHUB_EVENT_NAME}" in | ||
| "merge_group" | "pull_request" | "pull_request_target") | ||
| path_prefix="/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" | ||
| ;; | ||
| "push" | "workflow_dispatch") | ||
| path_prefix="/${GITHUB_REPOSITORY}/tree/${GITHUB_REF_NAME}" | ||
| ;; | ||
| *) | ||
| echo "Unsupported event: '${GITHUB_EVENT_NAME}'"; | ||
| exit 1; | ||
| ;; | ||
| esac | ||
| echo "PATH_PREFIX=${path_prefix}" >> $GITHUB_ENV | ||
| echo "result=${path_prefix}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Bootstrap Action Workspace | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
| uses: elastic/docs-builder/.github/actions/bootstrap@main | ||
|
|
||
| - name: 'Validate redirect rules' | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
| run: | | ||
| dotnet run --project src/tooling/docs-builder -- diff validate | ||
|
|
||
| - name: Build documentation | ||
| id: internal-docs-build | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
| run: | | ||
| dotnet run --project src/tooling/docs-builder -- --strict | ||
|
|
||
| - name: 'Validate inbound links' | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && !cancelled() | ||
| && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
| && steps.internal-docs-build.outputs.skip != 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| run: | | ||
| dotnet run --project src/tooling/docs-builder -- inbound-links validate-link-reference | ||
|
|
||
| - name: 'Validate local path prefixes against those claimed by global navigation.yml' | ||
| id: internal-validate-path-prefixes | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && !cancelled() | ||
| && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
| && steps.internal-docs-build.outputs.skip != 'true' | ||
| && steps.internal-docs-build.outcome != 'skipped' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| run: | | ||
| dotnet run --project src/tooling/docs-builder -- assembler navigation validate-link-reference | ||
|
|
||
| - uses: elastic/docs-builder/.github/actions/aws-auth@main | ||
| if: > | ||
| !cancelled() | ||
| && needs.check.outputs.any_modified != 'false' | ||
| && steps.internal-validate-path-prefixes.outcome == 'success' | ||
|
|
||
| - name: Upload to S3 | ||
| id: s3-upload | ||
| # disabled: preview uploads are not enabled on this branch | ||
| if: > | ||
| false | ||
| && env.MATCH == 'true' | ||
| && !cancelled() | ||
| && steps.internal-docs-build.outputs.skip != 'true' | ||
| && steps.deployment.outputs.result | ||
| && steps.internal-docs-build.outcome == 'success' | ||
| env: | ||
| AWS_RETRY_MODE: standard | ||
| AWS_MAX_ATTEMPTS: 6 | ||
| run: | | ||
| aws s3 sync .artifacts/docs/html "s3://elastic-docs-v3-website-preview${PATH_PREFIX}" --delete --no-follow-symlinks | ||
| aws cloudfront create-invalidation \ | ||
| --distribution-id EKT7LT5PM8RKS \ | ||
| --paths "${PATH_PREFIX}" "${PATH_PREFIX}/*" | ||
|
|
||
| - name: Update Link Index | ||
| if: > | ||
| env.MATCH == 'true' | ||
| && needs.check.outputs.any_modified != 'false' | ||
| && ( | ||
| contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) | ||
| && steps.internal-validate-path-prefixes.outcome == 'success' | ||
| ) | ||
| uses: elastic/docs-builder/actions/update-link-index@main | ||
|
|
||
| - name: Update deployment status | ||
| uses: actions/github-script@v8 | ||
| # disabled: deployments are not enabled on this branch | ||
| if: > | ||
| false | ||
| && env.MATCH == 'true' | ||
| && always() | ||
| && steps.deployment.outputs.result | ||
| env: | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| LANDING_PAGE_PATH: ${{ env.PATH_PREFIX }} | ||
| with: | ||
| script: | | ||
| await github.rest.repos.createDeploymentStatus({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| deployment_id: ${{ steps.deployment.outputs.result }}, | ||
| state: "${{ steps.internal-docs-build.outputs.skip == 'true' && 'inactive' || (steps.s3-upload.outcome == 'success' && 'success' || 'failure') }}", | ||
| environment_url: `https://docs-v3-preview.elastic.dev${process.env.LANDING_PAGE_PATH}`, | ||
| log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.