@@ -2,6 +2,10 @@ name: Build Preview
22run-name : ' Build Preview for "${{ github.event.pull_request.title }}" (#${{ github.event.pull_request.number }})'
33
44on :
5+ # 1: Change this to `pull_request` to see changes while testing this file in a PR.
6+ # 2: This is because `pull_request_target` only works from the context of the base branch
7+ # https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target
8+ # 3: Change this back to `pull_request_target` before merge for security reasons
59 pull_request :
610 types : [opened, synchronize]
711 # Hello Security 👋, we are checking to make sure forked repo PR changed paths are only in content/** inside the job security-check.
@@ -105,17 +109,11 @@ jobs:
105109 cache : ' npm'
106110 node-version-file : ' package.json'
107111
108- - name : Use cache
112+ - name : Cache Next.js build
109113 uses : actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
110114 with :
111- path : |
112- ~/.npm
113- ${{ github.workspace }}/.next/cache
114- # Only invalidate cache when actual build dependencies change (not content files)
115- key : ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('scripts/**/*.{js,mjs}', 'app/**/*.{ts,tsx}', 'next.config.js', 'productConfig.mjs') }}
116- # Fallback to cache with same dependencies, even if build scripts differ
117- restore-keys : |
118- ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
115+ path : ${{ github.workspace }}/.next/cache
116+ key : ${{ runner.os }}-nextjs-build-${{ hashFiles('package-lock.json', 'next.config.js') }}
119117
120118 - name : Install Vercel CLI
121119 run : npm i --global vercel@latest
@@ -184,18 +182,6 @@ jobs:
184182 with :
185183 repository : hashicorp/dev-portal
186184 path : ./unified-docs-frontend-preview
187- - name : Use cache
188- uses : actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
189- with :
190- path : |
191- ~/.npm
192- ${{ github.workspace }}/unified-docs-frontend-preview/.next/cache
193- # Generate a new cache whenever packages or source files change.
194- # However, we could potentially have this only cache based on package changes.
195- key : ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.mdx') }}
196- # If source files changed but packages didn't, rebuild from a prior cache.
197- restore-keys : |
198- ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
199185
200186 - name : Setup Node.js
201187 uses : actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
@@ -204,6 +190,12 @@ jobs:
204190 cache-dependency-path : ' unified-docs-frontend-preview/package-lock.json'
205191 node-version-file : ' unified-docs-frontend-preview/package.json'
206192
193+ - name : Cache Next.js build
194+ uses : actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
195+ with :
196+ path : ${{ github.workspace }}/unified-docs-frontend-preview/.next/cache
197+ key : ${{ runner.os }}-nextjs-build-devportal-${{ hashFiles('unified-docs-frontend-preview/package-lock.json', 'unified-docs-frontend-preview/next.config.js') }}
198+
207199 - name : Setup Vercel CLI
208200 run : npm i --global vercel@latest
209201
0 commit comments