Skip to content

Commit 55dd141

Browse files
authored
Support merge_group event for preview builds (#593)
* Add merge_group event handling * fix * Checkout before changed-files action Because the action cannot use GH API for merge_group events * Remove duplicate checkout step * Fix condition * Refactor switch case
1 parent b83719b commit 55dd141

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

.github/workflows/preview-build.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,36 @@ jobs:
3636
build:
3737
concurrency:
3838
group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }}
39-
cancel-in-progress: ${{ github.event_name == 'pull_request_target' }}
39+
cancel-in-progress: ${{ startsWith(github.event_name, 'pull_request') }}
4040
runs-on: ubuntu-latest
4141
steps:
4242

43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
with:
46+
ref: ${{ github.event.pull_request.head.sha || github.ref }}
47+
persist-credentials: false
48+
4349
- name: Get changed files
44-
if: github.event_name == 'pull_request_target'
50+
if: startsWith(github.event_name, 'pull_request') || github.event_name == 'merge_group'
4551
id: check-files
4652
uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6
4753
with:
4854
files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}
4955

5056
- name: Free Disk Space
57+
if: github.event_name != 'merge_group'
5158
uses: jlumbroso/free-disk-space@main
5259
with:
5360
tool-cache: false
54-
55-
- name: Checkout
56-
if: github.event_name == 'push' || steps.check-files.outputs.any_changed == 'true'
57-
uses: actions/checkout@v4
58-
with:
59-
ref: ${{ github.event.pull_request.head.sha || github.ref }}
60-
persist-credentials: false
61-
61+
6262
- name: Create Deployment
63-
if: github.event_name == 'push' || steps.check-files.outputs.any_changed == 'true'
63+
if: github.event_name == 'push' || (steps.check-files.outputs.any_changed == 'true' && startsWith(github.event_name, 'pull_request'))
6464
uses: actions/github-script@v7
6565
id: deployment
6666
env:
6767
PR_NUMBER: ${{ github.event.pull_request.number }}
68-
REF: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref_name }}
68+
REF: ${{ startsWith(github.event_name, 'pull_request') && github.event.pull_request.head.sha || github.ref_name }}
6969
with:
7070
result-encoding: string
7171
script: |
@@ -99,7 +99,7 @@ jobs:
9999
GITHUB_REF_NAME: ${{ github.ref_name }}
100100
run: |
101101
case "${GITHUB_EVENT_NAME}" in
102-
"pull_request_target")
102+
"merge_group" | "pull_request" | "pull_request_target")
103103
echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV
104104
;;
105105
"push")
@@ -127,15 +127,15 @@ jobs:
127127
dotnet run --project src/docs-builder -- --strict --path-prefix "${PATH_PREFIX}"
128128
129129
- name: Build documentation
130-
if: github.repository != 'elastic/docs-builder' && steps.deployment.outputs.result
130+
if: github.repository != 'elastic/docs-builder' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_changed == 'true' && github.event_name == 'merge_group'))
131131
uses: elastic/docs-builder@main
132132
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
133133
with:
134134
prefix: ${{ env.PATH_PREFIX }}
135135
strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }}
136136

137137
- uses: elastic/docs-builder/actions/validate-inbound-local@main
138-
if: ${{ !cancelled() && steps.deployment.outputs.result }}
138+
if: ${{ !cancelled() && (steps.deployment.outputs.result || (steps.check-files.outputs.any_changed == 'true' && github.event_name == 'merge_group')) }}
139139

140140
- uses: elastic/docs-builder/.github/actions/aws-auth@main
141141
if: ${{ !cancelled() && steps.deployment.outputs.result }}

0 commit comments

Comments
 (0)