Skip to content

Commit 2f0f65d

Browse files
committed
2 parents a93e5d9 + de40ee0 commit 2f0f65d

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

.github/workflows/nextjs.yml

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,55 @@ jobs:
2828
# Build job
2929
build:
3030
runs-on: ubuntu-latest
31-
3231
steps:
3332
- name: Checkout
34-
uses: actions/checkout@v3
35-
36-
- name: Install Node.js
37-
uses: actions/setup-node@v3
38-
with:
39-
node-version: 16
40-
41-
- uses: pnpm/action-setup@v2
42-
name: Install pnpm
43-
id: pnpm-install
44-
with:
45-
version: 7
46-
run_install: false
47-
48-
- name: Get pnpm store directory
49-
id: pnpm-cache
50-
shell: bash
33+
uses: actions/checkout@v4
34+
- name: Detect package manager
35+
id: detect-package-manager
5136
run: |
52-
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
53-
- uses: actions/cache@v3
54-
name: Setup pnpm cache
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
52+
uses: actions/setup-node@v4
5553
with:
56-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
57-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
58-
restore-keys: |
59-
${{ runner.os }}-pnpm-store-
60-
- name: Install dependencies
61-
run: pnpm install
62-
54+
node-version: "20"
55+
cache: ${{ steps.detect-package-manager.outputs.manager }}
6356
- name: Setup Pages
64-
uses: actions/configure-pages@v3
57+
uses: actions/configure-pages@v5
6558
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.
6663
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') }}-
74+
- name: Install dependencies
75+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
6776
- name: Build with Next.js
68-
run: pnpm next build
69-
- name: Static HTML export with Next.js
70-
run: pnpm next export
77+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
7178
- name: Upload artifact
72-
uses: actions/upload-pages-artifact@v4
79+
uses: actions/upload-pages-artifact@v3
7380
with:
7481
path: ./out
7582

@@ -83,4 +90,4 @@ jobs:
8390
steps:
8491
- name: Deploy to GitHub Pages
8592
id: deployment
86-
uses: actions/deploy-pages@v2
93+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)