From 60d969e8bd4ed8dfb1777548c73189a502a25ecd Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Feb 2025 16:19:49 +0100 Subject: [PATCH 1/6] Add merge_group event handling --- .github/workflows/preview-build.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 924bdf7f9..2a1bca308 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -36,18 +36,19 @@ jobs: build: concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request_target' }} + cancel-in-progress: ${{ startsWith(github.event_name, 'pull_request') }} runs-on: ubuntu-latest steps: - name: Get changed files - if: github.event_name == 'pull_request_target' + if: startsWith(github.event_name, 'pull_request') || github.event_name == 'merge_group' id: check-files uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6 with: files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }} - name: Free Disk Space + if: github.event_name != 'merge_group' uses: jlumbroso/free-disk-space@main with: tool-cache: false @@ -58,9 +59,9 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha || github.ref }} persist-credentials: false - + - name: Create Deployment - if: github.event_name == 'push' || steps.check-files.outputs.any_changed == 'true' + if: github.event_name == 'push' || (steps.check-files.outputs.any_changed == 'true' && startsWith(github.event_name, 'pull_request')) uses: actions/github-script@v7 id: deployment env: @@ -127,7 +128,7 @@ jobs: dotnet run --project src/docs-builder -- --strict --path-prefix "${PATH_PREFIX}" - name: Build documentation - if: github.repository != 'elastic/docs-builder' && steps.deployment.outputs.result + if: github.repository != 'elastic/docs-builder' && steps.deployment.outputs.result || github.event_name == 'merge_group' uses: elastic/docs-builder@main continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }} with: @@ -135,7 +136,7 @@ jobs: strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }} - uses: elastic/docs-builder/actions/validate-inbound-local@main - if: ${{ !cancelled() && steps.deployment.outputs.result }} + if: ${{ !cancelled() && (steps.deployment.outputs.result || github.event_name == 'merge_group') }} - uses: elastic/docs-builder/.github/actions/aws-auth@main if: ${{ !cancelled() && steps.deployment.outputs.result }} From 71e3a3eb5f6f35968a7d032e73d186178c6cfd4c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Feb 2025 16:21:42 +0100 Subject: [PATCH 2/6] fix --- .github/workflows/preview-build.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 2a1bca308..0912e2f6b 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -66,7 +66,7 @@ jobs: id: deployment env: PR_NUMBER: ${{ github.event.pull_request.number }} - REF: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref_name }} + REF: ${{ startsWith(github.event_name, 'pull_request') && github.event.pull_request.head.sha || github.ref_name }} with: result-encoding: string script: | @@ -100,9 +100,15 @@ jobs: GITHUB_REF_NAME: ${{ github.ref_name }} run: | case "${GITHUB_EVENT_NAME}" in + "merge_group") + echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV + ;; "pull_request_target") echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV ;; + "pull_request") + echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV + ;; "push") echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/tree/${GITHUB_REF_NAME}" >> $GITHUB_ENV if [[ ! "${GITHUB_REF_NAME}" =~ ^(main|master|16\.x)$ ]]; then From e7af1176932325da29ecc8fff92915b0c14f7668 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Feb 2025 16:33:20 +0100 Subject: [PATCH 3/6] Checkout before changed-files action Because the action cannot use GH API for merge_group events --- .github/workflows/preview-build.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 0912e2f6b..f1d8e3a00 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -40,6 +40,12 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.ref }} + persist-credentials: false + - name: Get changed files if: startsWith(github.event_name, 'pull_request') || github.event_name == 'merge_group' id: check-files From f335613957ba308a37988b9211bd28da208514e5 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Feb 2025 16:39:16 +0100 Subject: [PATCH 4/6] Remove duplicate checkout step --- .github/workflows/preview-build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index f1d8e3a00..ab241079b 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -58,13 +58,6 @@ jobs: uses: jlumbroso/free-disk-space@main with: tool-cache: false - - - name: Checkout - if: github.event_name == 'push' || steps.check-files.outputs.any_changed == 'true' - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha || github.ref }} - persist-credentials: false - name: Create Deployment if: github.event_name == 'push' || (steps.check-files.outputs.any_changed == 'true' && startsWith(github.event_name, 'pull_request')) From 31e49fc217fcd29baab3ed60bb138def5c383ebc Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Feb 2025 16:46:09 +0100 Subject: [PATCH 5/6] Fix condition --- .github/workflows/preview-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index ab241079b..2fcda20b2 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -133,7 +133,7 @@ jobs: dotnet run --project src/docs-builder -- --strict --path-prefix "${PATH_PREFIX}" - name: Build documentation - if: github.repository != 'elastic/docs-builder' && steps.deployment.outputs.result || github.event_name == 'merge_group' + if: github.repository != 'elastic/docs-builder' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_changed == 'true' && github.event_name == 'merge_group')) uses: elastic/docs-builder@main continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }} with: @@ -141,7 +141,7 @@ jobs: strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }} - uses: elastic/docs-builder/actions/validate-inbound-local@main - if: ${{ !cancelled() && (steps.deployment.outputs.result || github.event_name == 'merge_group') }} + if: ${{ !cancelled() && (steps.deployment.outputs.result || (steps.check-files.outputs.any_changed == 'true' && github.event_name == 'merge_group')) }} - uses: elastic/docs-builder/.github/actions/aws-auth@main if: ${{ !cancelled() && steps.deployment.outputs.result }} From 33822b6fa1f87a920f9be8d587170d0b5f9fa1d5 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Feb 2025 16:48:36 +0100 Subject: [PATCH 6/6] Refactor switch case --- .github/workflows/preview-build.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 2fcda20b2..94804564d 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -99,13 +99,7 @@ jobs: GITHUB_REF_NAME: ${{ github.ref_name }} run: | case "${GITHUB_EVENT_NAME}" in - "merge_group") - echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV - ;; - "pull_request_target") - echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV - ;; - "pull_request") + "merge_group" | "pull_request" | "pull_request_target") echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV ;; "push")