Skip to content

Commit 7f4b025

Browse files
authored
Use GitHub Action to deploy (#3)
* Use GitHub Action * Move action to the right folder * Fix pnpm command * Fix branch name * Update README.md * Format w/ single quotes and spaces * Convert tabs to spaces * Update comments * Use base path from pages action * Update readme
1 parent e47e8e4 commit 7f4b025

File tree

5 files changed

+220
-144
lines changed

5 files changed

+220
-144
lines changed

.github/workflows/deploy.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Deploy Next.js site to Pages
2+
3+
on:
4+
# Runs on pushes targeting the main branch
5+
push:
6+
branches:
7+
- main
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- uses: pnpm/action-setup@v4
32+
name: Install pnpm
33+
with:
34+
version: 10
35+
run_install: false
36+
37+
- name: Install Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: 22
41+
cache: 'pnpm'
42+
43+
- name: Install dependencies
44+
run: pnpm install
45+
46+
- name: Setup Pages
47+
id: setup_pages
48+
uses: actions/configure-pages@v5
49+
50+
- name: Restore cache
51+
uses: actions/cache@v4
52+
with:
53+
path: |
54+
.next/cache
55+
# Generate a new cache whenever packages or source files change.
56+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
57+
# If source files changed but packages didn't, rebuild from a prior cache.
58+
restore-keys: |
59+
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
60+
61+
- name: Build with Next.js
62+
run: pnpm run build
63+
env:
64+
PAGES_BASE_PATH: ${{ steps.setup_pages.outputs.base_path }}
65+
66+
- name: Upload artifact
67+
uses: actions/upload-pages-artifact@v3
68+
with:
69+
path: ./out
70+
71+
deploy:
72+
environment:
73+
name: github-pages
74+
url: ${{ steps.deployment.outputs.page_url }}
75+
runs-on: ubuntu-latest
76+
needs: build
77+
steps:
78+
- name: Deploy to GitHub Pages
79+
id: deployment
80+
uses: actions/deploy-pages@v4

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ This is a Next.js template which can be deployed to GitHub Pages as a static sit
55
## Deploying to GitHub Pages
66

77
1. Create a new public GitHub repository
8-
1. Edit `next.config.ts` to match your GitHub repository name:
9-
- Given the pattern `https://github.com/<user>/<repo>`
10-
- Update your `basePath` config to the name of your repo (e.g. `/repo`)
11-
1. Push the starter code to the `main` branch
12-
1. Run the `deploy` script (e.g. `npm run deploy`) to create the `gh-pages` branch
13-
1. On GitHub, go to **Settings** > **Pages** > **Branch**, and choose `gh-pages` as the branch with the `/root` folder. Hit **Save**
14-
1. Make a change
15-
1. Run the `deploy` script again to push the changes to GitHub Pages
8+
2. Push the starter code to the `main` branch
9+
3. On GitHub, go to **Settings** > **Pages** > **Source**, and choose **GitHub Actions** as the source
10+
4. Make a commit and push it to see the changes on GitHub Pages
1611

1712
Congratulations! You should have a URL like:
1813

next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { NextConfig } from 'next';
22

33
const nextConfig: NextConfig = {
44
output: 'export',
5-
basePath: '/your-repo-name',
5+
basePath: process.env.PAGES_BASE_PATH,
66
};
77

88
export default nextConfig;

package.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
2-
"private": true,
3-
"scripts": {
4-
"dev": "next dev --turbo",
5-
"build": "next build",
6-
"deploy": "next build && touch out/.nojekyll && git add out/ && git commit -m \"Deploy\" && git subtree push --prefix out origin gh-pages"
7-
},
8-
"dependencies": {
9-
"react": "19.0.0-rc-69d4b800-20241021",
10-
"react-dom": "19.0.0-rc-69d4b800-20241021",
11-
"next": "15.0.1"
12-
},
13-
"devDependencies": {
14-
"typescript": "^5",
15-
"@types/node": "^20",
16-
"@types/react": "npm:types-react@19.0.0-rc.1",
17-
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.1"
18-
}
2+
"private": true,
3+
"scripts": {
4+
"dev": "next dev --turbo",
5+
"build": "next build"
6+
},
7+
"dependencies": {
8+
"next": "^15.1.7",
9+
"react": "^19.0.0",
10+
"react-dom": "^19.0.0"
11+
},
12+
"devDependencies": {
13+
"@types/node": "^22.13.4",
14+
"@types/react": "^19.0.8",
15+
"@types/react-dom": "^19.0.3",
16+
"typescript": "^5.7.3"
17+
}
1918
}

0 commit comments

Comments
 (0)