1+ name : Deploy Next.js site to Pages
2+
3+ on :
4+ push :
5+ branches : ["main"]
6+ workflow_dispatch :
7+
8+ permissions :
9+ contents : read
10+ pages : write
11+ id-token : write
12+
13+ concurrency :
14+ group : " pages"
15+ cancel-in-progress : false
16+
17+ jobs :
18+ build :
19+ runs-on : ubuntu-latest
20+ steps :
21+ - name : Checkout
22+ uses : actions/checkout@v4
23+
24+ - name : Detect package manager
25+ id : detect-package-manager
26+ run : |
27+ if [ -f "${{ github.workspace }}/yarn.lock" ]; then
28+ echo "manager=yarn" >> $GITHUB_OUTPUT
29+ echo "command=install" >> $GITHUB_OUTPUT
30+ echo "runner=yarn" >> $GITHUB_OUTPUT
31+ exit 0
32+ elif [ -f "${{ github.workspace }}/package.json" ]; then
33+ echo "manager=npm" >> $GITHUB_OUTPUT
34+ echo "command=ci" >> $GITHUB_OUTPUT
35+ echo "runner=npx --no-install" >> $GITHUB_OUTPUT
36+ exit 0
37+ else
38+ echo "Unable to determine package manager"
39+ exit 1
40+ fi
41+
42+ - name : Setup Node
43+ uses : actions/setup-node@v4
44+ with :
45+ node-version : " 20"
46+ cache : ${{ steps.detect-package-manager.outputs.manager }}
47+
48+ - name : Setup Pages
49+ uses : actions/configure-pages@v5
50+ with :
51+ static_site_generator : next
52+
53+ - name : Restore cache
54+ uses : actions/cache@v4
55+ with :
56+ path : |
57+ .next/cache
58+ key : ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
59+ restore-keys : |
60+ ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
61+
62+ - name : Install dependencies
63+ run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
64+
65+ - name : Build with Next.js
66+ run : ${{ steps.detect-package-manager.outputs.runner }} next build
67+
68+ - name : Static export (ensure out/ exists)
69+ run : ${{ steps.detect-package-manager.outputs.runner }} next export
70+
71+ - name : Upload artifact
72+ uses : actions/upload-pages-artifact@v3
73+ with :
74+ path : ./out
75+
76+ deploy :
77+ environment :
78+ name : github-pages
79+ url : ${{ steps.deployment.outputs.page_url }}
80+ runs-on : ubuntu-latest
81+ needs : build
82+ steps :
83+ - name : Deploy to GitHub Pages
84+ id : deployment
85+ uses : actions/deploy-pages@v4
0 commit comments