Skip to content

Commit b82c7d4

Browse files
Update nextjs.yml to work with next.js 15 + app router.
1 parent 94d6967 commit b82c7d4

File tree

1 file changed

+20
-50
lines changed

1 file changed

+20
-50
lines changed

.github/workflows/nextjs.yml

+20-50
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
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
52
name: Deploy Next.js site to Pages
63

74
on:
8-
# Runs on pushes targeting the default branch
5+
# Trigger on pushes to the default branch
96
push:
107
branches: ["main"]
118

12-
# Allows you to run this workflow manually from the Actions tab
9+
# Allow manual triggering from the Actions tab
1310
workflow_dispatch:
1411

15-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
# Set permissions for deployment
1613
permissions:
1714
contents: read
1815
pages: write
1916
id-token: write
2017

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.
18+
# Allow only one deployment at a time
2319
concurrency:
2420
group: "pages"
2521
cancel-in-progress: false
@@ -31,54 +27,28 @@ jobs:
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: Setup Node.js
5232
uses: actions/setup-node@v4
5333
with:
5434
node-version: "20"
55-
cache: ${{ steps.detect-package-manager.outputs.manager }}
56-
- name: Setup Pages
57-
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
64-
- name: Restore cache
65-
uses: actions/cache@v4
66-
with:
67-
path: |
68-
.next/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.
72-
restore-keys: |
73-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
35+
cache: "yarn"
36+
7437
- name: Install dependencies
75-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
76-
- name: Build with Next.js
77-
run: ${{ steps.detect-package-manager.outputs.runner }} next build
38+
run: yarn install
39+
40+
- name: Configure Next.js for GitHub Pages
41+
run: |
42+
echo 'module.exports = { output: "export", basePath: "/<REPOSITORY-NAME>", trailingSlash: true }' > next.config.js
43+
cat next.config.js
44+
45+
- name: Build Next.js site
46+
run: yarn next build && yarn next export
47+
7848
- name: Upload artifact
7949
uses: actions/upload-pages-artifact@v3
8050
with:
81-
path: ./out
51+
path: out
8252

8353
# Deployment job
8454
deploy:

0 commit comments

Comments
 (0)