Skip to content

Commit b66f310

Browse files
authored
Use match job in docs-preview build (#1289)
* Make preview build steps dependant on match job output * Use match job in docs-preview build * remove unused env
1 parent b982035 commit b66f310

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

.github/workflows/preview-build.yml

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ jobs:
6565
- name: Not a push event
6666
id: event-check
6767
if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name)
68-
# ensure we emit static output to simplify our checks in the build step, next/current output has no barrings during preview builds
68+
# we always want to run for pull requests, but we do not want to indicate its either content source
6969
run: |
7070
echo "content-source-match=true" >> $GITHUB_OUTPUT
71-
echo "content-source-next=true" >> $GITHUB_OUTPUT
72-
echo "content-source-current=true" >> $GITHUB_OUTPUT
71+
echo "content-source-next=false" >> $GITHUB_OUTPUT
72+
echo "content-source-current=false" >> $GITHUB_OUTPUT
7373
- name: Match for push events
7474
id: match
7575
if: contains(fromJSON('["push"]'), github.event_name)
@@ -94,31 +94,36 @@ jobs:
9494
runs-on: ubuntu-latest
9595
env:
9696
GITHUB_PR_REF_NAME: ${{ github.event.pull_request.head.ref }}
97+
MATCH: ${{ needs.match.outputs.content-source-match }}
9798
needs: [ match ]
9899
steps:
99100

100101
- name: Checkout
101-
if: contains(fromJSON('["push", "merge_group", "workflow_dispatch"]'), github.event_name)
102+
if: env.MATCH == 'true' && (contains(fromJSON('["push", "merge_group", "workflow_dispatch"]'), github.event_name))
102103
uses: actions/checkout@v4
103104
with:
104105
ref: ${{ github.event.pull_request.head.sha || github.ref }}
105106

106107
- name: Get changed files
107-
if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name)
108+
if: env.MATCH == 'true' && (contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name))
108109
id: check-files
109110
uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1
110111
with:
111112
files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}
112113

113114
- name: Checkout
114-
if: startsWith(github.event_name, 'pull_request') && steps.check-files.outputs.any_modified == 'true'
115+
if: env.MATCH == 'true' && (startsWith(github.event_name, 'pull_request') && steps.check-files.outputs.any_modified == 'true')
115116
uses: actions/checkout@v4
116117
with:
117118
ref: ${{ github.event.pull_request.head.sha || github.ref }}
118119
persist-credentials: false
119120

120121
- name: Create Deployment
121-
if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) || (steps.check-files.outputs.any_modified == 'true' && startsWith(github.event_name, 'pull_request'))
122+
if: |
123+
env.MATCH == 'true' &&
124+
(contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name)
125+
|| (steps.check-files.outputs.any_modified == 'true' && startsWith(github.event_name, 'pull_request'))
126+
)
122127
uses: actions/github-script@v7
123128
id: deployment
124129
env:
@@ -151,7 +156,7 @@ jobs:
151156
return deployment.data.id
152157
153158
- name: Generate env.PATH_PREFIX
154-
if: steps.deployment.outputs.result
159+
if: env.MATCH == 'true' && (steps.deployment.outputs.result)
155160
env:
156161
PR_NUMBER: ${{ github.event.pull_request.number }}
157162
GITHUB_REF_NAME: ${{ github.ref_name }}
@@ -162,10 +167,6 @@ jobs:
162167
;;
163168
"push" | "workflow_dispatch")
164169
echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/tree/${GITHUB_REF_NAME}" >> $GITHUB_ENV
165-
if [[ ! "${GITHUB_REF_NAME}" =~ ^(main|master|16\.x)$ ]]; then
166-
echo "Unsupported ref name: '${GITHUB_REF_NAME}'";
167-
exit 1;
168-
fi
169170
;;
170171
*)
171172
echo "Unsupported event: '${GITHUB_EVENT_NAME}'";
@@ -174,18 +175,22 @@ jobs:
174175
esac
175176
176177
- name: Bootstrap Action Workspace
177-
if: github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result
178+
if: env.MATCH == 'true' && (github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result)
178179
uses: elastic/docs-builder/.github/actions/bootstrap@main
179180

180-
# we run our artifact directly please use the prebuild
181+
# we run our artifact directly, please use the prebuild
181182
# elastic/docs-builder@main GitHub Action for all other repositories!
182183
- name: Build documentation
183-
if: github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result
184+
if: env.MATCH == 'true' && (github.repository == 'elastic/docs-builder' && steps.deployment.outputs.result)
184185
run: |
185186
dotnet run --project src/tooling/docs-builder -- --strict --path-prefix "${PATH_PREFIX}"
186187
187188
- name: Build documentation
188-
if: github.repository != 'elastic/docs-builder' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group'))
189+
if: |
190+
env.MATCH == 'true' &&
191+
(github.repository != 'elastic/docs-builder' &&
192+
(steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group'))
193+
)
189194
uses: elastic/docs-builder@main
190195
id: docs-build
191196
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
@@ -195,32 +200,46 @@ jobs:
195200
metadata-only: ${{ fromJSON(inputs.metadata-only != '' && inputs.metadata-only || 'true') }}
196201

197202
- name: 'Validate inbound links'
198-
if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) }}
203+
if: |
204+
env.MATCH == 'true' &&
205+
(!cancelled() && steps.docs-build.outputs.skip != 'true'
206+
&& (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group'))
207+
)
199208
uses: elastic/docs-builder/actions/validate-inbound-local@main
200209

201210
- name: 'Validate local path prefixes against those claimed by global navigation.yml'
202-
if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) }}
211+
if: |
212+
env.MATCH == 'true' &&
213+
(!cancelled() && steps.docs-build.outputs.skip != 'true' &&
214+
(steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group'))
215+
)
203216
uses: elastic/docs-builder/actions/validate-path-prefixes-local@main
204217

205218
- uses: elastic/docs-builder/.github/actions/aws-auth@main
206219
if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && steps.deployment.outputs.result }}
207220

208221
- name: Upload to S3
209222
id: s3-upload
210-
if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && steps.deployment.outputs.result }}
223+
if: |
224+
env.MATCH == 'true' &&
225+
(!cancelled() && steps.docs-build.outputs.skip != 'true' && steps.deployment.outputs.result)
211226
run: |
212227
aws s3 sync .artifacts/docs/html "s3://elastic-docs-v3-website-preview${PATH_PREFIX}" --delete --no-follow-symlinks
213228
aws cloudfront create-invalidation \
214229
--distribution-id EKT7LT5PM8RKS \
215230
--paths "${PATH_PREFIX}" "${PATH_PREFIX}/*"
216231
217232
- name: Update Link Index
218-
if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && steps.s3-upload.outcome == 'success'
233+
if: |
234+
env.MATCH == 'true' &&
235+
(contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name)
236+
&& (needs.match.outputs.content-source-current == 'true' || needs.match.outputs.content-source-next == 'true')
237+
&& steps.s3-upload.outcome == 'success')
219238
uses: elastic/docs-builder/actions/update-link-index@main
220239

221240
- name: Update deployment status
222241
uses: actions/github-script@v7
223-
if: always() && steps.deployment.outputs.result
242+
if: env.MATCH == 'true' && (always() && steps.deployment.outputs.result)
224243
env:
225244
PR_NUMBER: ${{ github.event.pull_request.number }}
226245
LANDING_PAGE_PATH: ${{ steps.docs-build.outputs.landing-page-path || env.PATH_PREFIX }}

0 commit comments

Comments
 (0)