1+ # Workflow for building and deploying a Next.js site to GitHub Pages
2+ name : Deploy Next.js site to Pages
3+
4+ on :
5+ # Runs on pushes targeting the default branch
6+ push :
7+ branches : ["main"]
8+
9+ # Allows you to run this workflow manually from the Actions tab
10+ workflow_dispatch :
11+
12+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+ permissions :
14+ contents : read
15+ pages : write
16+ id-token : write
17+
18+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+ concurrency :
21+ group : " pages"
22+ cancel-in-progress : false
23+
24+ jobs :
25+ # Build job
26+ build :
27+ runs-on : ubuntu-latest
28+ steps :
29+ - name : Checkout
30+ uses : actions/checkout@v4
31+ - name : Detect Package Manager
32+ id : detect-package-manager
33+ run : |
34+ if [ -f "${{ github.workspace }}/yarn.lock" ]; then
35+ echo "manager=yarn" >> $GITHUB_OUTPUT
36+ echo "command=install" >> $GITHUB_OUTPUT
37+ exit 0
38+ elif [ -f "${{ github.workspace }}/package.json" ]; then
39+ echo "manager=npm" >> $GITHUB_OUTPUT
40+ echo "command=ci" >> $GITHUB_OUTPUT
41+ exit 0
42+ else
43+ echo "Unable to determine package manager"
44+ exit 1
45+ fi
46+ - name : Setup Node
47+ uses : actions/setup-node@v4
48+ with :
49+ node-version : " 20"
50+ cache : ${{ steps.detect-package-manager.outputs.manager }}
51+ - name : Setup Pages
52+ uses : actions/configure-pages@v5
53+ - name : Install dependencies
54+ run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
55+ - name : Build with Next.js
56+ run : ${{ steps.detect-package-manager.outputs.manager }} run build
57+ - name : Upload artifact
58+ uses : actions/upload-pages-artifact@v3
59+ with :
60+ path : ./out
61+
62+ # Deployment job
63+ deploy :
64+ environment :
65+ name : github-pages
66+ url : ${{ steps.deployment.outputs.page_url }}
67+ runs-on : ubuntu-latest
68+ needs : build
69+ steps :
70+ - name : Deploy to GitHub Pages
71+ id : deployment
72+ uses : actions/deploy-pages@v4
0 commit comments