Skip to content

Commit e7989ff

Browse files
committed
feat: auto deploy to github page
1 parent 6761277 commit e7989ff

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

.github/workflows/deploy-site.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Deploy Site
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Use Node.js 20
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Build site
33+
run: npm run site:build
34+
env:
35+
PUBLIC_PATH: /tiny-ui/
36+
37+
- name: Copy 404.html for SPA routing
38+
run: cp site/build/index.html site/build/404.html
39+
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@v3
42+
with:
43+
path: site/build
44+
45+
deploy:
46+
environment:
47+
name: github-pages
48+
url: ${{ steps.deployment.outputs.page_url }}
49+
runs-on: ubuntu-latest
50+
needs: build
51+
steps:
52+
- name: Deploy to GitHub Pages
53+
id: deployment
54+
uses: actions/deploy-pages@v4

site/config/webpack.common.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ const path = require('path');
22
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
33
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const webpack = require('webpack');
6+
7+
const PUBLIC_PATH = process.env.PUBLIC_PATH || '/';
58

69
module.exports = {
710
entry: path.resolve(__dirname, '../src/index.tsx'),
811
output: {
912
path: path.resolve(__dirname, '../build'),
1013
filename: 'bundle.[contenthash].js',
11-
publicPath: '/',
14+
publicPath: PUBLIC_PATH,
1215
},
1316
resolve: {
1417
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
@@ -45,5 +48,8 @@ module.exports = {
4548
new HtmlWebpackPlugin({
4649
template: path.resolve(__dirname, '../public/index.html'),
4750
}),
51+
new webpack.DefinePlugin({
52+
'process.env.PUBLIC_PATH': JSON.stringify(PUBLIC_PATH),
53+
}),
4854
],
4955
};

site/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import HomePage from './containers/home';
1111
import GuidePage from './containers/guide';
1212
import ComponentsPage from './containers/components';
1313

14+
const basename = (process.env.PUBLIC_PATH || '/').replace(/\/$/, '');
15+
1416
const App = (): React.ReactElement => (
15-
<BrowserRouter>
17+
<BrowserRouter basename={basename}>
1618
<>
1719
<Header />
1820
<Routes>

0 commit comments

Comments
 (0)