11# Sample workflow for building and deploying a Next.js site to GitHub Pages
2- #
3- # To get started with Next.js see: https://nextjs.org/docs/getting-started
4- #
52name : Deploy Next.js site to Pages
63
74on :
8- # Runs on pushes targeting the default branch
95 push :
10- branches : ["main"]
6+ branches : ["main"] # Runs on pushes targeting the default branch
7+ workflow_dispatch : # Allows manual trigger from the Actions tab
118
12- # Allows you to run this workflow manually from the Actions tab
13- workflow_dispatch :
14-
15- # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
169permissions :
1710 contents : read
1811 pages : write
1912 id-token : write
2013
21- # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22- # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
2314concurrency :
2415 group : " pages"
2516 cancel-in-progress : false
2617
2718jobs :
28- # Build job
2919 build :
3020 runs-on : ubuntu-latest
3121 steps :
3222 - name : Checkout
33- uses : actions/checkout@v3
23+ uses : actions/checkout@v4
24+
3425 - name : Detect package manager
3526 id : detect-package-manager
3627 run : |
3728 if [ -f "${{ github.workspace }}/yarn.lock" ]; then
3829 echo "manager=yarn" >> $GITHUB_OUTPUT
39- echo "command=install" >> $GITHUB_OUTPUT
30+ echo "command=install --frozen-lockfile " >> $GITHUB_OUTPUT
4031 echo "runner=yarn" >> $GITHUB_OUTPUT
4132 exit 0
4233 elif [ -f "${{ github.workspace }}/package.json" ]; then
@@ -48,48 +39,56 @@ jobs:
4839 echo "Unable to determine package manager"
4940 exit 1
5041 fi
42+
5143 - name : Setup Node
52- uses : actions/setup-node@v3
44+ uses : actions/setup-node@v4
5345 with :
54- node-version : " 16 "
46+ node-version : " 20 "
5547 cache : ${{ steps.detect-package-manager.outputs.manager }}
48+
5649 - name : Setup Pages
57- uses : actions/configure-pages@v3
50+ uses : actions/configure-pages@v4
5851 with :
59- # Automatically inject basePath in your Next.js configuration file and disable
60- # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
61- #
62- # You may remove this line if you want to manage the configuration yourself.
6352 static_site_generator : next
64- - name : Restore cache
65- uses : actions/cache@v3
53+
54+ - name : Restore Next.js cache
55+ uses : actions/cache@v4
6656 with :
67- path : |
68- .next/cache
69- # Generate a new cache whenever packages or source files change.
57+ path : .next/cache
7058 key : ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
71- # If source files changed but packages didn't, rebuild from a prior cache.
7259 restore-keys : |
7360 ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
61+
7462 - name : Install dependencies
7563 run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
64+
7665 - name : Build with Next.js
7766 run : ${{ steps.detect-package-manager.outputs.runner }} next build
67+
7868 - name : Static HTML export with Next.js
7969 run : ${{ steps.detect-package-manager.outputs.runner }} next export
70+
8071 - name : Upload artifact
81- uses : actions/upload-pages- artifact@v2
72+ uses : actions/upload-artifact@v4
8273 with :
74+ name : nextjs-site
8375 path : ./out
8476
85- # Deployment job
8677 deploy :
8778 environment :
8879 name : github-pages
8980 url : ${{ steps.deployment.outputs.page_url }}
9081 runs-on : ubuntu-latest
9182 needs : build
9283 steps :
84+ - name : Download artifact
85+ uses : actions/download-artifact@v4
86+ with :
87+ name : nextjs-site
88+ path : ./out
89+
9390 - name : Deploy to GitHub Pages
9491 id : deployment
95- uses : actions/deploy-pages@v2
92+ uses : actions/deploy-pages@v4
93+ with :
94+ path : ./out
0 commit comments