Skip to content

Commit 1f4e06f

Browse files
authored
Refactor Next.js deployment workflow
Updated the Next.js GitHub Actions workflow to use Node.js 22 and simplified dependency installation steps.
1 parent 510c8aa commit 1f4e06f

File tree

1 file changed

+20
-39
lines changed

1 file changed

+20
-39
lines changed

.github/workflows/nextjs.yml

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
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-
#
51
name: Deploy Next.js site to Pages
62

73
on:
8-
# Runs on pushes targeting the default branch
4+
# Runs on pushes targeting the main branch
95
push:
10-
branches: ["main"]
6+
branches:
7+
- main
118

129
# Allows you to run this workflow manually from the Actions tab
1310
workflow_dispatch:
@@ -25,62 +22,46 @@ concurrency:
2522
cancel-in-progress: false
2623

2724
jobs:
28-
# Build job
2925
build:
3026
runs-on: ubuntu-latest
3127
steps:
3228
- name: Checkout
3329
uses: actions/checkout@v4
34-
- name: Detect package manager
35-
id: detect-package-manager
36-
run: |
37-
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
38-
echo "manager=yarn" >> $GITHUB_OUTPUT
39-
echo "command=install" >> $GITHUB_OUTPUT
40-
echo "runner=yarn" >> $GITHUB_OUTPUT
41-
exit 0
42-
elif [ -f "${{ github.workspace }}/package.json" ]; then
43-
echo "manager=npm" >> $GITHUB_OUTPUT
44-
echo "command=ci" >> $GITHUB_OUTPUT
45-
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46-
exit 0
47-
else
48-
echo "Unable to determine package manager"
49-
exit 1
50-
fi
51-
- name: Setup Node
30+
31+
- name: Install Node.js
5232
uses: actions/setup-node@v4
5333
with:
54-
node-version: "20"
55-
cache: ${{ steps.detect-package-manager.outputs.manager }}
34+
node-version: 22
35+
cache: "npm"
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
5640
- name: Setup Pages
41+
id: setup_pages
5742
uses: actions/configure-pages@v5
58-
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.
63-
static_site_generator: next
43+
6444
- name: Restore cache
6545
uses: actions/cache@v4
6646
with:
6747
path: |
6848
.next/cache
6949
# 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') }}
50+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
7151
# If source files changed but packages didn't, rebuild from a prior cache.
7252
restore-keys: |
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 }}
53+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
7654
- name: Build with Next.js
77-
run: ${{ steps.detect-package-manager.outputs.runner }} next build
55+
run: npm run build
56+
#env:
57+
# Remove or comment out this line for custom domains
58+
# PAGES_BASE_PATH: ${{ steps.setup_pages.outputs.base_path }}
59+
7860
- name: Upload artifact
7961
uses: actions/upload-pages-artifact@v3
8062
with:
8163
path: ./out
8264

83-
# Deployment job
8465
deploy:
8566
environment:
8667
name: github-pages

0 commit comments

Comments
 (0)