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+ #
5+ name : Deploy Next.js site to Pages
6+
7+ on :
8+ # Runs on pushes targeting the default branch
9+ push :
10+ branches : ["main"]
11+ paths :
12+ - " docs"
13+
14+ pull_request :
15+ types :
16+ - closed
17+ branches : ["main"]
18+ paths :
19+ - " docs"
20+
21+ # Allows you to run this workflow manually from the Actions tab
22+ workflow_dispatch :
23+
24+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
25+ permissions :
26+ contents : read
27+ pages : write
28+ id-token : write
29+
30+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
31+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
32+ concurrency :
33+ group : " pages"
34+ cancel-in-progress : false
35+
36+ jobs :
37+ # Build job
38+ build :
39+ runs-on : ubuntu-latest
40+ steps :
41+ - name : Checkout
42+ uses : actions/checkout@v3
43+ - name : Detect package manager
44+ id : detect-package-manager
45+ run : |
46+ if [ -f "${{ github.workspace }}/yarn.lock" ]; then
47+ echo "manager=yarn" >> $GITHUB_OUTPUT
48+ echo "command=install" >> $GITHUB_OUTPUT
49+ echo "runner=yarn" >> $GITHUB_OUTPUT
50+ exit 0
51+ elif [ -f "${{ github.workspace }}/package.json" ]; then
52+ echo "manager=npm" >> $GITHUB_OUTPUT
53+ echo "command=ci" >> $GITHUB_OUTPUT
54+ echo "runner=npx --no-install" >> $GITHUB_OUTPUT
55+ exit 0
56+ else
57+ echo "Unable to determine package manager"
58+ exit 1
59+ fi
60+ - name : Setup Node
61+ uses : actions/setup-node@v3
62+ with :
63+ node-version : " 16"
64+ cache : ${{ steps.detect-package-manager.outputs.manager }}
65+ - name : Setup Pages
66+ uses : actions/configure-pages@v3
67+ with :
68+ # Automatically inject basePath in your Next.js configuration file and disable
69+ # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
70+ #
71+ # You may remove this line if you want to manage the configuration yourself.
72+ static_site_generator : next
73+ - name : Restore cache
74+ uses : actions/cache@v3
75+ with :
76+ path : |
77+ .next/cache
78+ # Generate a new cache whenever packages or source files change.
79+ key : ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
80+ # If source files changed but packages didn't, rebuild from a prior cache.
81+ restore-keys : |
82+ ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
83+ - name : Install dependencies
84+ run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
85+ - name : Build with Next.js
86+ run : ${{ steps.detect-package-manager.outputs.runner }} next build
87+ - name : Static HTML export with Next.js
88+ run : ${{ steps.detect-package-manager.outputs.runner }} next export
89+ - name : Upload artifact
90+ uses : actions/upload-pages-artifact@v2
91+ with :
92+ path : ./out
93+
94+ # Deployment job
95+ deploy :
96+ environment :
97+ name : github-pages
98+ url : ${{ steps.deployment.outputs.page_url }}
99+ runs-on : ubuntu-latest
100+ needs : build
101+ steps :
102+ - name : Deploy to GitHub Pages
103+ id : deployment
104+ uses : actions/deploy-pages@v2
0 commit comments