Skip to content

Commit 4299a03

Browse files
Rewrite GitHub Pages deployment with official Next.js workflow and modern best practices (#21)
2 parents e82c8ca + 5cd3e2b commit 4299a03

9 files changed

Lines changed: 245 additions & 260 deletions

File tree

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main", "develop" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18, 20, 22]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Lint
31+
run: npm run lint
32+
33+
- name: Type check
34+
run: npx tsc --noEmit
35+
36+
- name: Build
37+
run: npm run build

.github/workflows/copilot-validation.yml

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

.github/workflows/deploy.yml

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

.github/workflows/nextjs.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 default branch
9+
push:
10+
branches: ["main"]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
16+
permissions:
17+
contents: read
18+
pages: write
19+
id-token: write
20+
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.
23+
concurrency:
24+
group: "pages"
25+
cancel-in-progress: false
26+
27+
jobs:
28+
# Build job
29+
build:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Detect package manager
36+
id: detect-package-manager
37+
run: |
38+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
39+
echo "manager=yarn" >> $GITHUB_OUTPUT
40+
echo "command=install" >> $GITHUB_OUTPUT
41+
echo "runner=yarn" >> $GITHUB_OUTPUT
42+
exit 0
43+
elif [ -f "${{ github.workspace }}/package.json" ]; then
44+
echo "manager=npm" >> $GITHUB_OUTPUT
45+
echo "command=ci" >> $GITHUB_OUTPUT
46+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
47+
exit 0
48+
else
49+
echo "Unable to determine package manager"
50+
exit 1
51+
fi
52+
53+
- name: Setup Node
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: "20"
57+
cache: ${{ steps.detect-package-manager.outputs.manager }}
58+
59+
- name: Setup Pages
60+
uses: actions/configure-pages@v5
61+
with:
62+
# Automatically infer Next.js configuration
63+
# https://github.com/actions/configure-pages#next-js
64+
static_site_generator: next
65+
66+
- name: Restore cache
67+
uses: actions/cache@v4
68+
with:
69+
path: |
70+
.next/cache
71+
# Generate a new cache whenever packages or source files change.
72+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
73+
# If source files changed but packages didn't, rebuild from a prior cache.
74+
restore-keys: |
75+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
76+
77+
- name: Install dependencies
78+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
79+
80+
- name: Build with Next.js
81+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
82+
83+
- name: Upload artifact
84+
uses: actions/upload-pages-artifact@v3
85+
with:
86+
path: ./out
87+
88+
# Deployment job
89+
deploy:
90+
environment:
91+
name: github-pages
92+
url: ${{ steps.deployment.outputs.page_url }}
93+
runs-on: ubuntu-latest
94+
needs: build
95+
steps:
96+
- name: Deploy to GitHub Pages
97+
id: deployment
98+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
# next.js
1717
/.next/
18-
# The `out` directory should not be ignored by version control
19-
# /out/
18+
# The `out` directory contains build artifacts and should not be committed
19+
/out/
2020

2121
# production
2222
/build

0 commit comments

Comments
 (0)