Skip to content

Commit 2b89cb2

Browse files
committed
feat: add github variables
1 parent 3ea59b0 commit 2b89cb2

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

.github/DEPLOYMENT_SETUP.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@
66

77
## 需要配置的环境变量
88

9+
### GitHub Secrets(必需)
10+
911
在 GitHub 仓库的 Settings > Secrets and variables > Actions 中配置以下密钥:
1012

11-
### 必需的 Secrets
13+
| 变量名 | 说明 | 示例 | 必需 |
14+
| -------------------- | ---------------------------- | --------------------------- | ---- |
15+
| `TENCENT_SECRET_ID` | 腾讯云 API 密钥 ID | `AKIDxxxxxxxxxxxxxxxxxxxxx` ||
16+
| `TENCENT_SECRET_KEY` | 腾讯云 API 密钥 Key | `xxxxxxxxxxxxxxxxxxxxxxxx` ||
17+
| `TENCENT_COS_BUCKET` | COS 存储桶名称 | `my-website-1234567890` ||
18+
| `TENCENT_COS_REGION` | COS 存储桶区域 | `ap-shanghai` ||
19+
| `TENCENT_CDN_PREFIX` | CDN 域名前缀(可选) | `https://cdn.example.com/` ||
20+
| `GH_PAT` | GitHub Personal Access Token | `ghp_xxxxxxxxxxxxxxxxxxxx` ||
21+
22+
### GitHub Variables(可选功能控制)
23+
24+
在 GitHub 仓库的 Settings > Secrets and variables > Actions > Variables 中配置:
1225

13-
| 变量名 | 说明 | 示例 |
14-
| -------------------- | ---------------------------- | --------------------------- |
15-
| `TENCENT_SECRET_ID` | 腾讯云 API 密钥 ID | `AKIDxxxxxxxxxxxxxxxxxxxxx` |
16-
| `TENCENT_SECRET_KEY` | 腾讯云 API 密钥 Key | `xxxxxxxxxxxxxxxxxxxxxxxx` |
17-
| `TENCENT_COS_BUCKET` | COS 存储桶名称 | `my-website-1234567890` |
18-
| `TENCENT_COS_REGION` | COS 存储桶区域 | `ap-shanghai` |
19-
| `TENCENT_CDN_PREFIX` | CDN 域名前缀(可选) | `https://cdn.example.com/` |
20-
| `GH_PAT` | GitHub Personal Access Token | `ghp_xxxxxxxxxxxxxxxxxxxx` |
26+
| 变量名 | 说明 | 默认值 | 可选值 |
27+
| ------------------------- | ----------------------- | ------- | --------------- |
28+
| `ENABLE_SUBMODULE_UPDATE` | 是否启用子模块自动更新 | `false` | `true`, `false` |
29+
| `ENABLE_TYPE_CHECK` | 是否启用类型检查和 lint | `true` | `true`, `false` |
30+
31+
## 腾讯云配置
2132

2233
### 腾讯云密钥获取方法
2334

@@ -66,15 +77,20 @@
6677
- **CDN 刷新**:自动刷新 CDN 缓存,确保用户看到最新内容
6778
- **原子性部署**:构建成功后才进行部署
6879

80+
### 可选功能控制
81+
82+
- **子模块更新**:通过 `ENABLE_SUBMODULE_UPDATE` 控制是否自动更新子模块
83+
- **类型检查**:通过 `ENABLE_TYPE_CHECK` 控制是否进行类型检查和 lint
84+
6985
### 触发条件
7086

71-
- 推送到 `main` 分支时自动触发
87+
- 推送到 `main` `deploy` 分支时自动触发
7288
- 支持手动触发(workflow_dispatch)
7389
- 支持通过 repository_dispatch 触发(用于子模块更新)
7490

7591
## 监控和通知
7692

77-
部署完成后,可以在 GitHub Actions 页面查看详细的构建和部署日志。每个步骤都有清晰的名称和状态指示。
93+
部署完成后,可以在 GitHub Actions 页面查看详细的构建和部署日志。每个步骤都有清晰的名称和状态指示。健康检查失败时会正确设置失败状态。
7894

7995
## 故障排除
8096

@@ -84,6 +100,7 @@
84100
2. **存储桶不存在**:确认存储桶名称和区域是否正确
85101
3. **CDN 刷新失败**:检查 CDN 域名配置是否正确
86102
4. **构建失败**:检查代码是否有语法错误,依赖是否正确
103+
5. **健康检查失败**:健康检查失败会导致工作流失败状态
87104

88105
### 调试方法
89106

.github/workflows/deploy-tencent-cos.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ env:
1919
# 使用项目要求的 Node.js 版本
2020
NODE_VERSION: '20'
2121
PNPM_VERSION: '10.7.0'
22+
# 添加环境变量控制可选功能
23+
ENABLE_SUBMODULE_UPDATE: ${{ vars.ENABLE_SUBMODULE_UPDATE || 'false' }}
24+
ENABLE_TYPE_CHECK: ${{ vars.ENABLE_TYPE_CHECK || 'true' }}
2225

2326
jobs:
2427
build-and-deploy:
@@ -34,11 +37,12 @@ jobs:
3437
uses: actions/checkout@v4
3538
with:
3639
token: ${{ secrets.GH_PAT }}
37-
submodules: true
40+
submodules: ${{ env.ENABLE_SUBMODULE_UPDATE == 'true' }}
3841
fetch-depth: 0
3942

4043
# 2. 更新子模块(如果需要)
4144
- name: Update submodules
45+
if: env.ENABLE_SUBMODULE_UPDATE == 'true'
4246
run: |
4347
git submodule update --remote
4448
git config --global user.name "github-actions[bot]"
@@ -94,6 +98,7 @@ jobs:
9498

9599
# 9. 运行类型检查和代码质量检查
96100
- name: Type check and lint
101+
if: env.ENABLE_TYPE_CHECK == 'true'
97102
run: |
98103
pnpm astro check
99104
pnpm lint
@@ -184,6 +189,7 @@ jobs:
184189
else
185190
echo "⚠️ 网站健康检查失败 (HTTP $HTTP_STATUS)"
186191
echo "这可能是 CDN 缓存还未刷新完成,请稍后再试"
192+
exit 1
187193
fi
188194
else
189195
echo "ℹ️ 跳过健康检查:未配置 CDN 域名"

0 commit comments

Comments
 (0)