From abc2dc21e9c44dfd8be138e8097f6d55cc1ff281 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 21 May 2025 13:42:56 +0200 Subject: [PATCH 1/3] Make preview build steps dependant on match job output --- .github/workflows/preview-build.yml | 56 +++++++++++++++++++---------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index fd49e3a02..5b6fffc89 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -94,31 +94,36 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PR_REF_NAME: ${{ github.event.pull_request.head.ref }} + MATCH: ${{ needs.match.outputs.content-source-match }} needs: [ match ] steps: - name: Checkout - if: contains(fromJSON('["push", "merge_group", "workflow_dispatch"]'), github.event_name) + if: env.MATCH == 'true' && (contains(fromJSON('["push", "merge_group", "workflow_dispatch"]'), github.event_name)) uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha || github.ref }} - name: Get changed files - if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name) + if: env.MATCH == 'true' && (contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name)) id: check-files uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1 with: files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }} - name: Checkout - if: startsWith(github.event_name, 'pull_request') && steps.check-files.outputs.any_modified == 'true' + if: env.MATCH == 'true' && (startsWith(github.event_name, 'pull_request') && steps.check-files.outputs.any_modified == 'true') uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha || github.ref }} persist-credentials: false - name: Create Deployment - if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) || (steps.check-files.outputs.any_modified == 'true' && startsWith(github.event_name, 'pull_request')) + if: | + env.MATCH == 'true' && + (contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) + || (steps.check-files.outputs.any_modified == 'true' && startsWith(github.event_name, 'pull_request')) + ) uses: actions/github-script@v7 id: deployment env: @@ -151,10 +156,11 @@ jobs: return deployment.data.id - name: Generate env.PATH_PREFIX - if: steps.deployment.outputs.result + if: env.MATCH == 'true' && (steps.deployment.outputs.result) env: PR_NUMBER: ${{ github.event.pull_request.number }} GITHUB_REF_NAME: ${{ github.ref_name }} + CONTENT_SOURCE_MATCH: ${{ needs.match.outputs.content-source-match }} run: | case "${GITHUB_EVENT_NAME}" in "merge_group" | "pull_request" | "pull_request_target") @@ -162,10 +168,6 @@ jobs: ;; "push" | "workflow_dispatch") echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/tree/${GITHUB_REF_NAME}" >> $GITHUB_ENV - if [[ ! "${GITHUB_REF_NAME}" =~ ^(main|master|16\.x)$ ]]; then - echo "Unsupported ref name: '${GITHUB_REF_NAME}'"; - exit 1; - fi ;; *) echo "Unsupported event: '${GITHUB_EVENT_NAME}'"; @@ -174,18 +176,22 @@ jobs: esac - name: Bootstrap Action Workspace - if: github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result + if: env.MATCH == 'true' && (github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result) uses: elastic/docs-builder/.github/actions/bootstrap@main - # we run our artifact directly please use the prebuild + # we run our artifact directly, please use the prebuild # elastic/docs-builder@main GitHub Action for all other repositories! - name: Build documentation - if: github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result + if: env.MATCH == 'true' && (github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result) run: | dotnet run --project src/tooling/docs-builder -- --strict --path-prefix "${PATH_PREFIX}" - name: Build documentation - if: github.repository != 'elastic/docs-builder' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) + if: | + env.MATCH == 'true' && + (github.repository != 'elastic/docs-builder' && + (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) + ) uses: elastic/docs-builder@main id: docs-build continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }} @@ -195,11 +201,19 @@ jobs: metadata-only: ${{ fromJSON(inputs.metadata-only != '' && inputs.metadata-only || 'true') }} - name: 'Validate inbound links' - if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) }} + if: | + env.MATCH == 'true' && + (!cancelled() && steps.docs-build.outputs.skip != 'true' + && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) + ) uses: elastic/docs-builder/actions/validate-inbound-local@main - name: 'Validate local path prefixes against those claimed by global navigation.yml' - if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) }} + if: | + env.MATCH == 'true' && + (!cancelled() && steps.docs-build.outputs.skip != 'true' && + (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) + ) uses: elastic/docs-builder/actions/validate-path-prefixes-local@main - uses: elastic/docs-builder/.github/actions/aws-auth@main @@ -207,7 +221,9 @@ jobs: - name: Upload to S3 id: s3-upload - if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && steps.deployment.outputs.result }} + if: | + env.MATCH == 'true' && + (!cancelled() && steps.docs-build.outputs.skip != 'true' && steps.deployment.outputs.result) run: | aws s3 sync .artifacts/docs/html "s3://elastic-docs-v3-website-preview${PATH_PREFIX}" --delete --no-follow-symlinks aws cloudfront create-invalidation \ @@ -215,12 +231,16 @@ jobs: --paths "${PATH_PREFIX}" "${PATH_PREFIX}/*" - name: Update Link Index - if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && steps.s3-upload.outcome == 'success' + if: | + env.MATCH == 'true' && + (contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) + && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') + && steps.s3-upload.outcome == 'success') uses: elastic/docs-builder/actions/update-link-index@main - name: Update deployment status uses: actions/github-script@v7 - if: always() && steps.deployment.outputs.result + if: env.MATCH == 'true' && always() && steps.deployment.outputs.result env: PR_NUMBER: ${{ github.event.pull_request.number }} LANDING_PAGE_PATH: ${{ steps.docs-build.outputs.landing-page-path || env.PATH_PREFIX }} From 0af3029fad921560ba0a13339dddb6d43f5f8422 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 21 May 2025 13:59:47 +0200 Subject: [PATCH 2/3] Use match job in docs-preview build --- .github/workflows/preview-build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 5b6fffc89..41dadad72 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -65,11 +65,11 @@ jobs: - name: Not a push event id: event-check if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name) - # ensure we emit static output to simplify our checks in the build step, next/current output has no barrings during preview builds + # we always want to run for pull requests, but we do not want to indicate its either content source run: | echo "content-source-match=true" >> $GITHUB_OUTPUT - echo "content-source-next=true" >> $GITHUB_OUTPUT - echo "content-source-current=true" >> $GITHUB_OUTPUT + echo "content-source-next=false" >> $GITHUB_OUTPUT + echo "content-source-current=false" >> $GITHUB_OUTPUT - name: Match for push events id: match if: contains(fromJSON('["push"]'), github.event_name) @@ -234,13 +234,13 @@ jobs: if: | env.MATCH == 'true' && (contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) - && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') + && (needs.match.outputs.content-source-current == 'true' || needs.match.outputs.content-source-next == 'true') && steps.s3-upload.outcome == 'success') uses: elastic/docs-builder/actions/update-link-index@main - name: Update deployment status uses: actions/github-script@v7 - if: env.MATCH == 'true' && always() && steps.deployment.outputs.result + if: env.MATCH == 'true' && (always() && steps.deployment.outputs.result) env: PR_NUMBER: ${{ github.event.pull_request.number }} LANDING_PAGE_PATH: ${{ steps.docs-build.outputs.landing-page-path || env.PATH_PREFIX }} From b307a230f30a507ed24c1b4446311a2d09a2159d Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 21 May 2025 14:01:15 +0200 Subject: [PATCH 3/3] remove unused env --- .github/workflows/preview-build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 41dadad72..7935e0daf 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -160,7 +160,6 @@ jobs: env: PR_NUMBER: ${{ github.event.pull_request.number }} GITHUB_REF_NAME: ${{ github.ref_name }} - CONTENT_SOURCE_MATCH: ${{ needs.match.outputs.content-source-match }} run: | case "${GITHUB_EVENT_NAME}" in "merge_group" | "pull_request" | "pull_request_target")