@@ -2,34 +2,62 @@ name: Build Preview
22run-name : ' Build Preview for "${{ github.event.pull_request.title }}" (#${{ github.event.pull_request.number }})'
33
44on :
5- # pull_request_target:
6- # types: [opened, synchronize]
7- # branches:
8- # - main
9- # paths:
10- # - 'content/**'
11-
12- pull_request :
13- paths :
14- - ' content/**'
15- - ' app/**'
16- - ' scripts/**'
17- - ' !scripts/**/*.test.ts'
18- - ' !scripts/**/*.test.mjs'
19- - ' !app/**/*.test.ts'
5+ pull_request_target :
6+ types : [opened, synchronize]
7+ branches :
8+ - main
9+ - develop
10+ # paths:
11+ # Hello Security 👋, we are checking to make sure forked repo PR changed paths are only in content/** inside the job security-check.
12+ # We are doing this so we can also reuse this workflow for internal PRs, as pull_request_target also triggers on internal PRs. (As does pull_request)
2013
2114concurrency :
2215 group : ${{ github.workflow }}-${{github.event_name}}-${{ github.event.pull_request.number || github.ref }}
2316 cancel-in-progress : true
2417
25- # permissions:
26- # pull-requests: write
27- # contents: read # for embargoed content repos
18+ permissions :
19+ pull-requests : write
20+ contents : read # for embargoed content repos
2821
2922jobs :
23+ get-changed-files :
24+ runs-on : ubuntu-latest
25+ outputs :
26+ changed_content_files : ${{ steps.changed-files.outputs.content_all_changed_files }}
27+ changed_content_files_count : ${{ steps.changed-files.outputs.content_all_changed_files_count }}
28+
29+ not_content_bad_boy_naughty_files_count : ${{ steps.changed-files.outputs.not_content_bad_boy_naughty_all_changed_files_count }}
30+ steps :
31+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32+
33+ - name : Get changed files in the content/ subdirectories
34+ id : changed-files
35+ uses : tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
36+ with :
37+ files_yaml : |
38+ content:
39+ - 'content/**'
40+ not_content_bad_boy_naughty:
41+ - '!content/**'
42+ base_sha : ${{ github.event.pull_request.base.sha }}
43+ sha : ${{ github.event.pull_request.head.sha }}
44+
45+ security-check :
46+ name : Security Check
47+ runs-on : ubuntu-latest
48+ needs : [get-changed-files]
49+ if : needs.get-changed-files.outputs.not_content_bad_boy_naughty_files_count > 0 && ${{ github.event.pull_request.head.repo.full_name }} != ${{ github.repository }}
50+ steps :
51+ - name : If in a forked repo, fail if any changes outside of content/**
52+ run : |
53+ echo "😠 This is a PR from a forked repo. Please only edit files in the content/** directory." >> $GITHUB_STEP_SUMMARY
54+ exit 1
55+
56+
3057 deploy-unified-docs-api-preview :
3158 name : Deploy Unified Docs API Preview
3259 runs-on : ubuntu-latest
60+ needs : [get-changed-files]
3361 # Don't rerun this job if the PR is from a forked repo, as pull_request_target will trigger the job first
3462 # if: github.event.pull_request.head.repo.full_name == github.repository
3563 outputs :
@@ -218,32 +246,10 @@ jobs:
218246 | Dev Portal | ✅ Ready ([Inspect](${{ steps.dev_portal_inspector_url.outputs.inspector_url }})) | [Visit Preview](${{ steps.deploy_dev_portal_preview.outputs.preview_url }}) | ${{ steps.deploy_dev_portal_preview.outputs.created_utc }} |
219247 | Unified Docs API | ✅ Ready ([Inspect](${{ needs.deploy-unified-docs-api-preview.outputs.inspector_url }} )) | [Visit Preview](${{ needs.deploy-unified-docs-api-preview.outputs.preview_url }}) | ${{ needs.deploy-unified-docs-api-preview.outputs.created_utc }} |
220248
221- get-changed-files :
222- runs-on : ubuntu-latest
223- needs : [deploy-dev-portal-preview]
224- outputs :
225- changed_files : ${{ steps.changed-files.outputs.all_changed_files }}
226- steps :
227- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
228-
229- - name : Get changed files in the content/ subdirectories
230- id : changed-files
231- uses : tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
232- with :
233- files : |
234- content/**/*.mdx
235- base_sha : ${{ github.event.pull_request.base.sha }}
236- sha : ${{ github.event.pull_request.head.sha }}
237-
238- - name : Print changed files
239- run : |
240- echo "Changed files:"
241- echo ${{ steps.changed-files.outputs.all_changed_files }}
242-
243249 check-links :
244250 name : check links
245251 needs : [get-changed-files, deploy-dev-portal-preview]
246- if : needs.get-changed-files.outputs.changed_files != ''
252+ if : needs.get-changed-files.outputs.changed_content_files_count > 0
247253 runs-on : ubuntu-latest
248254 steps :
249255 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -252,7 +258,7 @@ jobs:
252258 id : lychee
253259 uses : lycheeverse/lychee-action@f613c4a64e50d792e0b31ec34bbcbba12263c6a6 # v2.3.0
254260 with :
255- args : ${{ needs.get-changed-files.outputs.changed_files }} -b ${{ needs.deploy-dev-portal-preview.outputs.preview_url }} --exclude-all-private --exclude '\.(svg|gif|jpg|png)' --accept 200,429 --timeout=60 --max-concurrency 24 --no-progress --verbose
261+ args : ${{ needs.get-changed-files.outputs.changed_content_files }} -b ${{ needs.deploy-dev-portal-preview.outputs.preview_url }} --exclude-all-private --exclude '\.(svg|gif|jpg|png)' --accept 200,429 --timeout=60 --max-concurrency 24 --no-progress --verbose
256262 fail : false
257263 env :
258264 GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
@@ -295,7 +301,7 @@ jobs:
295301 skip-check-links :
296302 name : skip link checker
297303 needs : [get-changed-files]
298- if : needs.get-changed-files.outputs.changed_files == ''
304+ if : needs.get-changed-files.outputs.changed_content_files_count == 0
299305 runs-on : ubuntu-latest
300306 steps :
301307 - name : Update PR comment
0 commit comments