Skip to content

Commit fe5087c

Browse files
committed
添加GitHub Actions自动部署到GitHub Pages
- 创建.github/workflows/deploy.yml工作流文件 - 配置自动构建和部署流程 - 更新vite.config.ts适配GitHub Pages路径 - 修复TypeScript编译错误 - 添加部署说明文档DEPLOYMENT.md
1 parent f85a624 commit fe5087c

File tree

7 files changed

+156
-20
lines changed

7 files changed

+156
-20
lines changed

.github/workflows/deploy.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: 部署到 GitHub Pages
2+
3+
on:
4+
# 在推送到 main 分支时触发
5+
push:
6+
branches: [ "main" ]
7+
8+
# 允许手动触发工作流
9+
workflow_dispatch:
10+
11+
# 设置 GITHUB_TOKEN 的权限以允许部署到 GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# 只允许一个并发部署,跳过正在运行和最新排队之间的运行
18+
# 但是,不要取消正在进行的运行,因为我们希望让这些生产部署完成
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
23+
jobs:
24+
# 构建作业
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: 检出代码
29+
uses: actions/checkout@v4
30+
31+
- name: 设置 Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '20'
35+
cache: 'npm'
36+
37+
- name: 安装依赖
38+
run: npm ci
39+
40+
- name: 构建项目
41+
run: npm run build
42+
43+
- name: 设置 Pages
44+
uses: actions/configure-pages@v5
45+
46+
- name: 上传构建产物
47+
uses: actions/upload-pages-artifact@v3
48+
with:
49+
path: './dist'
50+
51+
# 部署作业
52+
deploy:
53+
environment:
54+
name: github-pages
55+
url: ${{ steps.deployment.outputs.page_url }}
56+
runs-on: ubuntu-latest
57+
needs: build
58+
steps:
59+
- name: 部署到 GitHub Pages
60+
id: deployment
61+
uses: actions/deploy-pages@v4

DEPLOYMENT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# GitHub Pages 自动部署配置
2+
3+
本项目已配置为使用 GitHub Actions 自动部署到 GitHub Pages。
4+
5+
## 配置说明
6+
7+
### 1. GitHub Actions 工作流
8+
9+
工作流文件位于 `.github/workflows/deploy.yml`,包含以下功能:
10+
11+
- **触发条件**
12+
- 推送到 `main` 分支时自动触发
13+
- 支持手动触发(workflow_dispatch)
14+
15+
- **构建过程**
16+
- 使用 Node.js 20
17+
- 安装依赖:`npm ci`
18+
- 构建项目:`npm run build`
19+
- 上传构建产物到 GitHub Pages
20+
21+
- **部署过程**
22+
- 自动部署到 GitHub Pages
23+
- 使用 GitHub 提供的官方 Actions
24+
25+
### 2. Vite 配置
26+
27+
`vite.config.ts` 已配置为适配 GitHub Pages:
28+
29+
- **base 路径**:设置为 `/coze-plugin-curl-filter/` 以匹配仓库名
30+
- **构建输出**:输出到 `dist` 目录
31+
- **源映射**:启用源映射文件用于调试
32+
33+
### 3. GitHub Pages 设置
34+
35+
需要在 GitHub 仓库中进行以下设置:
36+
37+
1. 进入仓库的 **Settings** 页面
38+
2. 找到 **Pages** 部分
39+
3.**Source** 中选择 **GitHub Actions**
40+
4. 保存设置
41+
42+
### 4. 部署流程
43+
44+
1. 将代码推送到 `main` 分支
45+
2. GitHub Actions 自动触发构建
46+
3. 构建成功后自动部署到 GitHub Pages
47+
4. 网站将在 `https://open-api-hub.github.io/coze-plugin-curl-filter/` 可访问
48+
49+
### 5. 本地测试
50+
51+
在推送前可以本地测试构建:
52+
53+
```bash
54+
# 安装依赖
55+
npm install
56+
57+
# 构建项目
58+
npm run build
59+
60+
# 预览构建结果
61+
npm run preview
62+
```
63+
64+
### 6. 故障排除
65+
66+
- **构建失败**:检查 Actions 页面的构建日志
67+
- **页面无法访问**:确认 GitHub Pages 设置正确
68+
- **资源加载失败**:检查 `base` 路径配置是否正确
69+
70+
## 注意事项
71+
72+
- 确保所有代码更改都推送到 `main` 分支
73+
- 构建过程中的任何 TypeScript 错误都会导致部署失败
74+
- 首次部署可能需要几分钟时间生效

src/components/HistoryManager/HistoryManager.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ import {
3737
ContentCopy,
3838
Visibility,
3939
Edit,
40-
FilterList,
4140
History as HistoryIcon,
42-
Star,
43-
StarBorder
41+
Star
4442
} from '@mui/icons-material';
4543
import type { HistoryEntry, HistoryQueryOptions, HistoryStats } from '../../types/filterRules';
4644
import { indexedDBStorageManager } from '../../utils/indexedDBStorage';

src/utils/indexedDBStorage.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class IndexedDBStorageManager {
9595

9696
// 创建备份存储
9797
if (!db.objectStoreNames.contains(STORES.BACKUP)) {
98-
const backupStore = db.createObjectStore(STORES.BACKUP, { keyPath: 'timestamp' });
98+
db.createObjectStore(STORES.BACKUP, { keyPath: 'timestamp' });
9999
}
100100
};
101101
});
@@ -502,7 +502,7 @@ export class IndexedDBStorageManager {
502502

503503
if (favoriteOnly) {
504504
const index = historyStore.index('favorite');
505-
request = index.getAll(true);
505+
request = index.getAll(1);
506506
} else {
507507
request = historyStore.getAll();
508508
}
@@ -513,30 +513,30 @@ export class IndexedDBStorageManager {
513513
// 应用过滤条件
514514
if (searchText) {
515515
const searchLower = searchText.toLowerCase();
516-
results = results.filter(entry =>
516+
results = results.filter((entry: HistoryEntry) =>
517517
entry.inputCurl.toLowerCase().includes(searchLower) ||
518518
entry.outputCurl.toLowerCase().includes(searchLower) ||
519519
(entry.title && entry.title.toLowerCase().includes(searchLower))
520520
);
521521
}
522522

523523
if (tags && tags.length > 0) {
524-
results = results.filter(entry =>
525-
entry.tags && entry.tags.some(tag => tags.includes(tag))
524+
results = results.filter((entry: HistoryEntry) =>
525+
entry.tags && entry.tags.some((tag: string) => tags.includes(tag))
526526
);
527527
}
528528

529529
if (dateRange) {
530530
const startTime = new Date(dateRange.start).getTime();
531531
const endTime = new Date(dateRange.end).getTime();
532-
results = results.filter(entry => {
532+
results = results.filter((entry: HistoryEntry) => {
533533
const entryTime = new Date(entry.timestamp).getTime();
534534
return entryTime >= startTime && entryTime <= endTime;
535535
});
536536
}
537537

538538
// 排序
539-
results.sort((a, b) => {
539+
results.sort((a: HistoryEntry, b: HistoryEntry) => {
540540
let aValue: any, bValue: any;
541541
if (sortBy === 'timestamp') {
542542
aValue = new Date(a.timestamp).getTime();
@@ -811,7 +811,7 @@ export class IndexedDBStorageManager {
811811
*/
812812
async clearStorage(): Promise<void> {
813813
try {
814-
const db = await this.ensureDB();
814+
await this.ensureDB();
815815
const storeNames = [STORES.CONFIG, STORES.RULES, STORES.HISTORY, STORES.BACKUP];
816816

817817
await this.executeTransaction(storeNames, 'readwrite', (stores) => {

src/utils/ruleStorage.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22

33
import type {
44
FilterRule,
5-
StoredConfig,
6-
ImportedConfig
5+
StoredConfig
76
} from '../types/filterRules';
8-
import {
9-
DEFAULT_SETTINGS,
10-
CONFIG_VERSION,
11-
STORAGE_KEYS
12-
} from '../types/filterRules';
13-
import { validateRules } from './ruleValidation';
147
import {
158
indexedDBStorageManager,
169
saveRules as saveRulesToIndexedDB,

src/utils/storageMigration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// 存储迁移工具
2-
import type { FilterRule, StoredConfig } from '../types/filterRules';
2+
import type { StoredConfig } from '../types/filterRules';
33
import { STORAGE_KEYS, CONFIG_VERSION, DEFAULT_SETTINGS } from '../types/filterRules';
44
import { indexedDBStorageManager } from './indexedDBStorage';
55
import { validateRules } from './ruleValidation';

vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ import react from '@vitejs/plugin-react'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
// 设置基础路径为仓库名,适配GitHub Pages
8+
base: '/coze-plugin-curl-filter/',
79
server: {
810
port: 25519,
911
host: true
12+
},
13+
build: {
14+
// 确保构建输出目录为 dist
15+
outDir: 'dist',
16+
// 生成源映射文件用于调试
17+
sourcemap: true,
18+
// 清理输出目录
19+
emptyOutDir: true
1020
}
1121
})

0 commit comments

Comments
 (0)