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- #
1+ # Workflow for building and deploying a Next.js site to GitHub Pages
52name : Deploy Next.js site to Pages
63
74on :
8- # Runs on pushes targeting the default branch
95 push :
106 branches : ["main"]
11-
12- # Allows you to run this workflow manually from the Actions tab
137 workflow_dispatch :
148
15- # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
169permissions :
1710 contents : read
1811 pages : write
1912 id-token : write
2013
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.
2314concurrency :
2415 group : " pages"
2516 cancel-in-progress : false
2617
2718jobs :
28- # Build job
2919 build :
3020 runs-on : ubuntu-latest
3121 steps :
3222 - name : Checkout
3323 uses : actions/checkout@v4
24+
3425 - name : Detect package manager
3526 id : detect-package-manager
3627 run : |
@@ -48,45 +39,45 @@ jobs:
4839 echo "Unable to determine package manager"
4940 exit 1
5041 fi
42+
5143 - name : Setup Node
5244 uses : actions/setup-node@v4
5345 with :
5446 node-version : " 20"
5547 cache : ${{ steps.detect-package-manager.outputs.manager }}
48+
5649 - name : Setup Pages
5750 uses : actions/configure-pages@v5
5851 with :
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).
61- #
62- # You may remove this line if you want to manage the configuration yourself.
6352 static_site_generator : next
53+
6454 - name : Restore cache
6555 uses : actions/cache@v4
6656 with :
67- path : |
68- .next/cache
69- # Generate a new cache whenever packages or source files change.
57+ path : .next/cache
7058 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.
7259 restore-keys : |
7360 ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
61+
7462 - name : Install dependencies
7563 run : ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
64+
7665 - name : Build with Next.js
7766 run : ${{ steps.detect-package-manager.outputs.runner }} next build
67+ env :
68+ NEXT_PUBLIC_OPENWEATHER_API_KEY : ${{ secrets.NEXT_PUBLIC_OPENWEATHER_API_KEY }}
69+
7870 - name : Upload artifact
7971 uses : actions/upload-pages-artifact@v3
8072 with :
8173 path : ./out
8274
83- # Deployment job
8475 deploy :
76+ needs : build
77+ runs-on : ubuntu-latest
8578 environment :
8679 name : github-pages
8780 url : ${{ steps.deployment.outputs.page_url }}
88- runs-on : ubuntu-latest
89- needs : build
9081 steps :
9182 - name : Deploy to GitHub Pages
9283 id : deployment
0 commit comments