Skip to content

Commit b90b253

Browse files
committed
ci: add GitHub Pages deployment workflow
Add GitHub Actions workflow for automatic deployment to GitHub Pages. Includes build and deploy jobs with pnpm setup and caching. Also update package.json with deploy scripts and vite.config.ts with base URL configuration for production.
1 parent bf59b04 commit b90b253

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "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 job
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '20'
36+
37+
- name: Setup pnpm
38+
uses: pnpm/action-setup@v4
39+
with:
40+
version: latest
41+
42+
- name: Get pnpm store directory
43+
shell: bash
44+
run: |
45+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
46+
47+
- name: Setup pnpm cache
48+
uses: actions/cache@v4
49+
with:
50+
path: ${{ env.STORE_PATH }}
51+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
52+
restore-keys: |
53+
${{ runner.os }}-pnpm-store-
54+
55+
- name: Install dependencies
56+
run: pnpm install --frozen-lockfile
57+
58+
- name: Build
59+
run: pnpm build
60+
61+
- name: Setup Pages
62+
uses: actions/configure-pages@v5
63+
64+
- name: Upload artifact
65+
uses: actions/upload-pages-artifact@v3
66+
with:
67+
path: './dist'
68+
69+
# Deployment job
70+
deploy:
71+
environment:
72+
name: github-pages
73+
url: ${{ steps.deployment.outputs.page_url }}
74+
runs-on: ubuntu-latest
75+
needs: build
76+
steps:
77+
- name: Deploy to GitHub Pages
78+
id: deployment
79+
uses: actions/deploy-pages@v4

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"dev": "vite",
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
10-
"preview": "vite preview"
10+
"preview": "vite preview",
11+
"deploy": "pnpm build && gh-pages -d dist",
12+
"predeploy": "pnpm build"
1113
},
1214
"dependencies": {
1315
"@reduxjs/toolkit": "^2.9.0",

public/.nojekyll

Whitespace-only changes.

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import tailwindcss from "@tailwindcss/vite"
66
// https://vite.dev/config/
77
export default defineConfig({
88
plugins: [react(), tailwindcss()],
9+
base: process.env.NODE_ENV === 'production' ? '/react-template/' : '/',
910
resolve: {
1011
alias: {
1112
"@": fileURLToPath(new URL("./src", import.meta.url)),

0 commit comments

Comments
 (0)