Skip to content

Commit a62ad2f

Browse files
committed
fix
1 parent 6392826 commit a62ad2f

2 files changed

Lines changed: 96 additions & 2 deletions

File tree

.github/workflows/deploy.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
concurrency:
16+
group: "pages"
17+
cancel-in-progress: false
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
cache: 'npm'
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Build
36+
run: npm run build -- --configuration production --base-href /
37+
env:
38+
NODE_OPTIONS: '--max_old_space_size=4096'
39+
40+
- name: Find build output directory
41+
id: find_build_dir
42+
run: |
43+
if [ -d "dist/4oftools/browser" ]; then
44+
echo "BUILD_DIR=dist/4oftools/browser" >> $GITHUB_OUTPUT
45+
elif [ -d "dist/4oftools" ]; then
46+
echo "BUILD_DIR=dist/4oftools" >> $GITHUB_OUTPUT
47+
else
48+
echo "Error: Build output directory not found"
49+
ls -la dist/ || true
50+
exit 1
51+
fi
52+
53+
- name: Create 404.html for SPA routing
54+
run: |
55+
cp "${{ steps.find_build_dir.outputs.BUILD_DIR }}/index.html" "${{ steps.find_build_dir.outputs.BUILD_DIR }}/404.html"
56+
echo "Created 404.html for SPA routing support"
57+
58+
- name: Setup Pages
59+
uses: actions/configure-pages@v4
60+
61+
- name: Upload artifact
62+
uses: actions/upload-pages-artifact@v3
63+
with:
64+
path: ${{ steps.find_build_dir.outputs.BUILD_DIR }}
65+
66+
deploy:
67+
environment:
68+
name: github-pages
69+
url: ${{ steps.deployment.outputs.page_url }}
70+
runs-on: ubuntu-latest
71+
needs: build
72+
steps:
73+
- name: Deploy to GitHub Pages
74+
id: deployment
75+
uses: actions/deploy-pages@v4

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,26 @@ src/
6262

6363
编辑 `src/app/services/tool.service.ts` 文件,在 `tools` 数组中添加您的工具和应用数据。
6464

65-
## 许可证
65+
## 部署到 GitHub Pages
6666

67-
MIT
67+
### 自动部署
6868

69+
项目已配置 GitHub Actions 自动部署。当您推送代码到 `main``master` 分支时,会自动构建并部署到 GitHub Pages。
70+
71+
### 手动触发部署
72+
73+
1. 前往 GitHub 仓库的 Actions 页面
74+
2. 选择 "Deploy to GitHub Pages" workflow
75+
3. 点击 "Run workflow" 按钮
76+
77+
### 配置 GitHub Pages
78+
79+
1. 前往仓库的 Settings > Pages
80+
2. 在 Source 部分,选择 "GitHub Actions"
81+
3. 保存设置
82+
83+
### 注意事项
84+
85+
- 如果您的仓库名是 `username.github.io`,base-href 会自动设置为 `/`
86+
- 如果您的仓库名是其他名称(如 `4oftools`),需要修改 `.github/workflows/deploy.yaml` 中的 `--base-href` 参数为 `/仓库名/`
87+
- 项目会自动创建 `404.html` 文件以支持 Angular SPA 路由

0 commit comments

Comments
 (0)