Skip to content

Commit 35a45d1

Browse files
committed
Add path-pattern input to preview-build.yml workflow
1 parent 7ec2d91 commit 35a45d1

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

.github/workflows/preview-build.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
type: string
1414
required: false
1515
default: 'true'
16+
path-pattern:
17+
description: 'Path pattern to filter files. Only if changed files match the pattern, the workflow will continue.'
18+
type: string
19+
default: '**'
20+
required: false
1621

1722
permissions:
1823
contents: read
@@ -21,7 +26,15 @@ jobs:
2126
build:
2227
runs-on: ubuntu-latest
2328
steps:
29+
30+
- name: Get changed files
31+
id: check-files
32+
uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6
33+
with:
34+
files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}
35+
2436
- name: Checkout
37+
if: steps.check-files.outputs.any_changed == 'true'
2538
uses: actions/checkout@v4
2639
with:
2740
persist-credentials: false
@@ -30,11 +43,13 @@ jobs:
3043
env:
3144
PR_NUMBER: ${{ github.event.pull_request.number }}
3245
PR_REF: ${{ github.event.pull_request.head.sha }}
46+
ANY_CHANGED: ${{ steps.check-files.outputs.any_changed }}
3347
run: |
3448
cat << EOF > pull_request.json
3549
{
3650
"number": ${PR_NUMBER},
37-
"ref": "${PR_REF}"
51+
"ref": "${PR_REF}",
52+
"any_changed": ${ANY_CHANGED}"
3853
}
3954
EOF
4055
@@ -48,26 +63,28 @@ jobs:
4863
compression-level: 1
4964

5065
- name: Bootstrap Action Workspace
51-
if: github.repository == 'elastic/docs-builder'
66+
if: github.repository == 'elastic/docs-builder' && steps.check-files.outputs.any_changed == 'true'
5267
uses: ./.github/actions/bootstrap
5368

5469
# we run our artifact directly please use the prebuild
5570
# elastic/docs-builder@main GitHub Action for all other repositories!
5671
- name: Build documentation
57-
if: github.repository == 'elastic/docs-builder'
72+
if: github.repository == 'elastic/docs-builder' && steps.check-files.outputs.any_changed == 'true'
5873
env:
5974
PR_NUMBER: ${{ github.event.pull_request.number }}
6075
run: |
6176
dotnet run --project src/docs-builder -- --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}"
6277
6378
- name: Build documentation
64-
if: github.repository != 'elastic/docs-builder'
79+
if: github.repository != 'elastic/docs-builder' && steps.check-files.outputs.any_changed == 'true'
6580
uses: elastic/docs-builder@main
6681
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
6782
with:
6883
prefix: "/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
6984
strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }}
85+
7086
- uses: actions/upload-artifact@v4
87+
if: steps.check-files.outputs.any_changed == 'true'
7188
with:
7289
name: docs
7390
path: .artifacts/docs/html/

.github/workflows/preview-deploy.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414
actions: read
1515

1616
jobs:
17-
docs-deploy:
17+
deploy:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Download PR data
@@ -30,9 +30,11 @@ jobs:
3030
{
3131
echo "number=$(jq -r '.number' pull_request.json)"
3232
echo "ref=$(jq -r '.ref' pull_request.json)"
33+
echo "any_changed=$(jq -r '.any_changed' pull_request.json)"
3334
} >> "${GITHUB_OUTPUT}"
3435
3536
- name: Create Deployment
37+
if: steps.pull_request.outputs.any_changed == 'true'
3638
uses: actions/github-script@v7
3739
id: deployment
3840
env:
@@ -60,6 +62,7 @@ jobs:
6062
return deployment.data.id
6163
6264
- name: Download docs
65+
if: steps.pull_request.outputs.any_changed == 'true'
6366
env:
6467
GH_TOKEN: ${{ github.token }}
6568
run: |
@@ -69,8 +72,10 @@ jobs:
6972
--dir html
7073
7174
- uses: elastic/docs-builder/.github/actions/aws-auth@main
75+
if: steps.pull_request.outputs.any_changed == 'true'
7276

7377
- name: Upload to S3
78+
if: steps.pull_request.outputs.any_changed == 'true'
7479
env:
7580
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
7681
run: |

0 commit comments

Comments
 (0)