Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/cloudflare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Cloudflare

on:
pull_request:
branches: [main]
paths:
- 'website/**'
- '.github/workflows/cloudflare.yml'
push:
branches: [main]
paths:
- 'website/**'
- '.github/workflows/cloudflare.yml'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: cloudflare-${{ github.event.pull_request.number || 'production' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
name: Build Cloudflare website
runs-on: ubuntu-latest
timeout-minutes: 10
env:
ASTRO_TELEMETRY_DISABLED: '1'
WRANGLER_SEND_METRICS: 'false'
defaults:
run:
working-directory: website
steps:
- uses: actions/checkout@v7.0.1
- uses: pnpm/action-setup@v6.1.0
with:
version: 10.29.2
- uses: actions/setup-node@v7.1.0
with:
node-version: 24
cache: pnpm
cache-dependency-path: website/pnpm-lock.yaml
- name: 安装网站依赖
run: pnpm install --frozen-lockfile
- name: 检查、构建并验证 Workers 发布配置
run: pnpm deploy:cloudflare --dry-run

deploy:
name: Deploy Cloudflare website
needs: build
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: cloudflare-production
url: https://mpider.followto.us/
env:
ASTRO_TELEMETRY_DISABLED: '1'
WRANGLER_SEND_METRICS: 'false'
defaults:
run:
working-directory: website
steps:
- name: 确认部署凭证已配置
working-directory: ${{ github.workspace }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
run: |
if [ -z "$CLOUDFLARE_API_TOKEN" ] || [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then
echo '::error::请配置 CLOUDFLARE_API_TOKEN secret 和 CLOUDFLARE_ACCOUNT_ID variable。'
exit 1
fi
- uses: actions/checkout@v7.0.1
- uses: pnpm/action-setup@v6.1.0
with:
version: 10.29.2
- uses: actions/setup-node@v7.1.0
with:
node-version: 24
cache: pnpm
cache-dependency-path: website/pnpm-lock.yaml
- name: 安装网站依赖
run: pnpm install --frozen-lockfile
- name: 构建并发布到 Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
run: pnpm deploy:cloudflare
- name: 检查线上 HTTPS
run: curl --fail --silent --show-error --retry 3 --retry-delay 5 --retry-all-errors --max-time 30 --output /dev/null https://mpider.followto.us/
3 changes: 2 additions & 1 deletion tools/ci-changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

NON_BUILD_PREFIXES = (
"docs/",
# 官网由独立 Pages workflow 构建与校验,不触发桌面客户端构建。
# 官网由独立网站 workflow 构建与校验,不触发桌面客户端构建。
"website/",
".github/ISSUE_TEMPLATE/",
# 当前 CI 不启动这些本地模拟,也不构建移动端。
Expand All @@ -34,6 +34,7 @@

CI_FILES = {
".github/workflows/pages.yml",
".github/workflows/cloudflare.yml",
"tools/ci-changes.py", "tools/test_ci_changes.py",
"tools/check-ci-results.py", "tools/test_ci_results.py",
}
Expand Down
1 change: 1 addition & 0 deletions tools/test_ci_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_website_uses_its_independent_workflow(self):
self.assert_checks(["website/src/pages/index.astro", "website/pnpm-lock.yaml",
"website/src/content/blog/guide.md"])
self.assert_checks([".github/workflows/pages.yml"], "ci")
self.assert_checks([".github/workflows/cloudflare.yml"], "ci")
self.assert_checks(["website/src/pages/index.astro", "frontend/src/App.tsx"], "frontend")

def test_markdown_imported_by_frontend_is_checked(self):
Expand Down
1 change: 1 addition & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
dist/
.astro/
.wrangler/
.env
.env.*
26 changes: 26 additions & 0 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,30 @@ draft: true

`.github/workflows/pages.yml` 在网站 PR 中运行类型检查、构建和产物验证;相关变更合并到 `main` 后自动发布到 GitHub Pages,也可手动触发。PR 不会部署到正式网站。

## Cloudflare Workers 发布

同一份 Astro 源码也支持 Workers Static Assets,独立域名为 `https://mpider.followto.us/`,无需服务端适配器。

在 `website` 目录运行:

```sh
pnpm install --frozen-lockfile
pnpm exec wrangler login
pnpm deploy:cloudflare --dry-run
pnpm deploy:cloudflare
```

Wrangler 会先执行 `build:cloudflare`,固定使用上述域名运行类型检查、构建和产物验证,任何一步失败都会终止发布。也可单独运行 `pnpm build:cloudflare` 检查产物。每次部署都会重新生成 `dist`,不会复用 GitHub Pages 的子路径产物。

`wrangler.jsonc` 管理 Worker 名称、自定义域名与静态文件路由;目录页统一使用末尾 `/`,不存在的地址返回自定义 404 页和 HTTP 404。Cloudflare 会为自定义域名管理 DNS 与 HTTPS 证书。部署账户须拥有 `followto.us` 的管理权限;多账户环境可通过 `CLOUDFLARE_ACCOUNT_ID` 选择部署账户,凭证不写入仓库。

本地发布使用 Wrangler 登录凭证。`.github/workflows/cloudflare.yml` 在网站 PR 中执行发布预检查;相关变更合并到 `main` 后自动发布到 Workers,也支持在 `main` 上手动触发。PR 和其他分支不会发布到正式域名。GitHub Pages 与 Workers 使用各自的工作流构建和发布。

自动发布前,在 GitHub 仓库的 **Settings → Secrets and variables → Actions** 中配置:

- Secret `CLOUDFLARE_API_TOKEN`:专用于 CI 的 Cloudflare API token,允许发布 `mpider-website` 并管理 `followto.us` 的 Workers 路由。权限与作用范围参考 [Cloudflare Workers 权限说明](https://developers.cloudflare.com/workers/authorization/)。
- Variable `CLOUDFLARE_ACCOUNT_ID`:部署账户 ID。

凭证缺失时,正式发布任务会明确失败;PR 的构建校验无需凭证。不要复制本地 OAuth 登录文件,也不要把 token 写入源码或构建产物。

FAQ 存放在 `src/config/faqs.json`,第一条为“为什么开源?”,默认展开。可见答案和 FAQ 结构化数据使用同一份内容。
10 changes: 8 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
"version": "1.0.0",
"type": "module",
"packageManager": "pnpm@10.29.2",
"engines": { "node": ">=24", "pnpm": ">=10" },
"engines": {
"node": ">=24",
"pnpm": ">=10"
},
"scripts": {
"dev": "astro dev --host 127.0.0.1 --port 3000",
"build": "astro build",
"build:cloudflare": "node tools/build-cloudflare.mjs",
"deploy:cloudflare": "wrangler deploy",
"check": "astro check",
"verify": "node tools/verify-build.mjs",
"preview": "astro preview --host 127.0.0.1 --port 3000"
Expand All @@ -19,6 +24,7 @@
},
"devDependencies": {
"@astrojs/check": "0.9.12",
"typescript": "^6.0.0"
"typescript": "^6.0.0",
"wrangler": "4.155.0"
}
}
Loading
Loading