Skip to content

Commit 94a4cfb

Browse files
committed
gh-pages: add nextjs config
1 parent c8ed2a4 commit 94a4cfb

File tree

2 files changed

+66
-35
lines changed

2 files changed

+66
-35
lines changed

.github/workflows/gh-pages.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/nextjs.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
#
5+
name: Deploy Next.js site to Pages
6+
7+
on:
8+
# Runs on pushes targeting the main branch
9+
push:
10+
branches: ["master", "main"]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
build-and-deploy:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
- name: Detect package manager
24+
id: detect-package-manager
25+
run: |
26+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
27+
echo "manager=yarn" >> $GITHUB_OUTPUT
28+
echo "command=install" >> $GITHUB_OUTPUT
29+
echo "runner=yarn" >> $GITHUB_OUTPUT
30+
echo "runner=yarn run" >> $GITHUB_OUTPUT
31+
exit 0
32+
elif [ -f "${{ github.workspace }}/package.json" ]; then
33+
echo "manager=npm" >> $GITHUB_OUTPUT
34+
echo "command=ci" >> $GITHUB_OUTPUT
35+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
36+
exit 0
37+
else
38+
echo "Unable to determine package manager"
39+
exit 1
40+
fi
41+
- name: Setup Node
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: "20"
45+
cache: ${{ steps.detect-package-manager.outputs.manager }}
46+
- name: Restore cache
47+
uses: actions/cache@v4
48+
with:
49+
path: |
50+
.next/cache
51+
# Generate a new cache whenever packages or source files change.
52+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
53+
# If source files changed but packages didn't, rebuild from a prior cache.
54+
restore-keys: |
55+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
56+
- name: Install dependencies
57+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
58+
- name: Build with Next.js
59+
run: ${{ steps.detect-package-manager.outputs.runner }} build
60+
- name: Build
61+
run: yarn build
62+
- name: Deploy to GitHub Pages
63+
uses: peaceiris/actions-gh-pages@v3
64+
with:
65+
github_token: ${{ secrets.GITHUB_TOKEN }}
66+
publish_dir: ./out

0 commit comments

Comments
 (0)