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
1722permissions :
1823 contents : read
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/
0 commit comments