1+ name : Deploy Next.js to GitHub 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 : " 18"
46+ cache : ${{ steps.detect-package-manager.outputs.manager }}
47+
48+ - name : Setup Pages
49+ uses : actions/configure-pages@v5
50+
51+ - name : Install dependencies
52+ run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
53+
54+ - name : Build with Next.js
55+ run : ${{ steps.detect-package-manager.outputs.runner }} next build
56+
57+ - name : Upload artifact
58+ uses : actions/upload-pages-artifact@v3
59+ with :
60+ path : ./out
61+
62+ deploy :
63+ environment :
64+ name : github-pages
65+ url : ${{ steps.deployment.outputs.page_url }}
66+ runs-on : ubuntu-latest
67+ needs : build
68+ steps :
69+ - name : Deploy to GitHub Pages
70+ id : deployment
71+ uses : actions/deploy-pages@v4
0 commit comments