1- # GitHub Actions workflow to deploy a Next.js site to GitHub Pages
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+ #
25name : Deploy Next.js site to Pages
36
47on :
5- # Trigger the workflow on push to the "main" branch
8+ # Runs on pushes targeting the default branch
69 push :
7- branches : ["main "]
10+ branches : ["* "]
811
9- # Allow manual runs from the Actions tab
12+ # Allows you to run this workflow manually from the Actions tab
1013 workflow_dispatch :
1114
12- # Set permissions for GitHub Pages deployment
15+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1316permissions :
1417 contents : read
1518 pages : write
1619 id-token : write
1720
18- # Allow only one deployment at a time, but do not cancel in-progress deployments
21+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
1923concurrency :
2024 group : " pages"
2125 cancel-in-progress : false
2226
2327jobs :
24- # Build Job: Compiles and prepares the Next.js app for deployment
28+ # Build job
2529 build :
2630 runs-on : ubuntu-latest
27-
2831 steps :
29- # Step 1: Checkout the repository
30- - name : Checkout repository
32+ - name : Checkout
3133 uses : actions/checkout@v4
32-
33- # Step 2: Detect the package manager (npm or yarn)
3434 - name : Detect package manager
3535 id : detect-package-manager
3636 run : |
3737 if [ -f "${{ github.workspace }}/yarn.lock" ]; then
3838 echo "manager=yarn" >> $GITHUB_OUTPUT
3939 echo "command=install" >> $GITHUB_OUTPUT
4040 echo "runner=yarn" >> $GITHUB_OUTPUT
41+ exit 0
4142 elif [ -f "${{ github.workspace }}/package.json" ]; then
4243 echo "manager=npm" >> $GITHUB_OUTPUT
4344 echo "command=ci" >> $GITHUB_OUTPUT
4445 echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46+ exit 0
4547 else
4648 echo "Unable to determine package manager"
4749 exit 1
4850 fi
49-
50- # Step 3: Setup Node.js environment
51- - name : Setup Node.js
51+ - name : Setup Node
5252 uses : actions/setup-node@v4
5353 with :
5454 node-version : " 20"
5555 cache : ${{ steps.detect-package-manager.outputs.manager }}
56-
57- # Step 4: Install project dependencies
58- - name : Install dependencies
59- run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
60-
61- # Step 5: Install ts-node
62- - name : Install ts-node
63- run : npm install -g ts-node
64-
65- # Step 6: Run script to generate the manifest file for Next.js
66- - name : Run manifest generation script
67- run : ts-node scripts/generateManifest.mjs
68- # Step 7: Debugging - Check if manifest.json exists
69-
70- - name : Debug Manifest Generation
71- run : |
72- ls -l ./public/
73- cat ./public/manifest.json || echo "❌ Manifest not found"
74-
75- # Step 7: Configure GitHub Pages for Next.js
7656 - name : Setup Pages
7757 uses : actions/configure-pages@v5
7858 with :
79- # Automatically configures basePath and disables image optimization
80- static_site_generator : next
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).
8161
82- # Step 8: Restore Next.js build cache to speed up builds
83- - name : Restore Next.js cache
62+ # You may remove this line if you want to manage the configuration yourself.
63+ static_site_generator : next
64+ - name : Restore cache
8465 uses : actions/cache@v4
8566 with :
8667 path : |
8768 .next/cache
88- # Generate cache key based on package files and source code
89- key : ${{ runner.os }}-nextjs-${{ hashFiles('** /package-lock.json', '** /yarn.lock') }}-${{ hashFiles('** .[jt]s', '* *.[jt]sx') }}
90- # If cache key changes, try restoring from a previous cache
69+ # 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') }}
71+ # If source files changed but packages didn't, rebuild from a prior cache.
9172 restore-keys : |
92- ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
93-
94- # Step 9: Build the Next.js project
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 }}
76+ - name : Install ts-node
77+ run : npm install -g ts-node
78+ - name : Run manifest generation script
79+ run : ts-node scripts/generateManifest.mjs
9580 - name : Build with Next.js
9681 run : ${{ steps.detect-package-manager.outputs.runner }} next build
97-
98- # Step 10: Upload the built site as an artifact for deployment
99- - name : Upload build artifacts
82+ - name : Upload artifact
10083 uses : actions/upload-pages-artifact@v3
10184 with :
10285 path : ./out
103-
104- # Deployment Job: Deploys the built site to GitHub Pages
86+ # Deployment job
10587 deploy :
10688 environment :
10789 name : github-pages
10890 url : ${{ steps.deployment.outputs.page_url }}
10991 runs-on : ubuntu-latest
11092 needs : build
111-
11293 steps :
113- # Step 11: Deploy the site to GitHub Pages
11494 - name : Deploy to GitHub Pages
11595 id : deployment
116- uses : actions/deploy-pages@v4
96+ uses : actions/deploy-pages@v4
0 commit comments