1- # 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- #
51name : Deploy Next.js site to Pages
62
73on :
8- # Runs on pushes targeting the default branch
4+ # Runs on pushes targeting the main branch
95 push :
10- branches : ["main"]
6+ branches :
7+ - main
118
129 # Allows you to run this workflow manually from the Actions tab
1310 workflow_dispatch :
@@ -25,62 +22,52 @@ concurrency:
2522 cancel-in-progress : false
2623
2724jobs :
28- # Build job
2925 build :
3026 runs-on : ubuntu-latest
3127 steps :
3228 - name : Checkout
3329 uses : actions/checkout@v4
34- - name : Detect package manager
35- id : detect-package-manager
36- run : |
37- if [ -f "${{ github.workspace }}/yarn.lock" ]; then
38- echo "manager=yarn" >> $GITHUB_OUTPUT
39- echo "command=install" >> $GITHUB_OUTPUT
40- echo "runner=yarn" >> $GITHUB_OUTPUT
41- exit 0
42- elif [ -f "${{ github.workspace }}/package.json" ]; then
43- echo "manager=npm" >> $GITHUB_OUTPUT
44- echo "command=ci" >> $GITHUB_OUTPUT
45- echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46- exit 0
47- else
48- echo "Unable to determine package manager"
49- exit 1
50- fi
51- - name : Setup Node
30+
31+ - uses : pnpm/action-setup@v4
32+ name : Install pnpm
33+ with :
34+ version : 10
35+ run_install : false
36+
37+ - name : Install Node.js
5238 uses : actions/setup-node@v4
5339 with :
54- node-version : " 20"
55- cache : ${{ steps.detect-package-manager.outputs.manager }}
40+ node-version : 22
41+ cache : ' pnpm'
42+
43+ - name : Install dependencies
44+ run : pnpm install
45+
5646 - name : Setup Pages
47+ id : setup_pages
5748 uses : actions/configure-pages@v5
58- 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.
63- static_site_generator : next
49+
6450 - name : Restore cache
6551 uses : actions/cache@v4
6652 with :
6753 path : |
6854 .next/cache
6955 # Generate a new cache whenever packages or source files change.
70- key : ${{ runner.os }}-nextjs-${{ hashFiles('**/package -lock.json', '**/yarn.lock ') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
56+ key : ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm -lock.yaml ') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
7157 # If source files changed but packages didn't, rebuild from a prior cache.
7258 restore-keys : |
73- ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
74- - name : Install dependencies
75- run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
59+ ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
60+
7661 - name : Build with Next.js
77- run : ${{ steps.detect-package-manager.outputs.runner }} next build
62+ run : pnpm run build
63+ env :
64+ PAGES_BASE_PATH : ${{ steps.setup_pages.outputs.base_path }}
65+
7866 - name : Upload artifact
7967 uses : actions/upload-pages-artifact@v3
8068 with :
8169 path : ./out
8270
83- # Deployment job
8471 deploy :
8572 environment :
8673 name : github-pages
9077 steps :
9178 - name : Deploy to GitHub Pages
9279 id : deployment
93- uses : actions/deploy-pages@v4
80+ uses : actions/deploy-pages@v4
0 commit comments