Repository navigation
ONE-539: 同步 CONTRIBUTING.md「官方」→「自研」文案 #24
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| # 本工作流只做校验,不做发布:部署(CF Pages / GitHub Pages)由部署子单落地。 | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| checks: | |
| name: 校验与构建 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| # git describe 注入页脚版本号需要完整历史 | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - uses: pnpm/action-setup@v6 | |
| - uses: actions/setup-node@v7 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: pnpm | |
| - name: 安装依赖 | |
| run: pnpm install --frozen-lockfile | |
| - name: 数据文件 schema 校验(§4.1 / §7:非法数据直接失败并点名字段) | |
| run: pnpm validate:data | |
| - name: 投稿数据校验(§7:repo 存在且 public / 外链可达性 / 截图规格) | |
| run: pnpm validate:submission | |
| env: | |
| # 只读公开数据足够;不要求、也不允许任何 PAT 入仓(§9.2) | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Lint 与类型检查 | |
| run: pnpm lint | |
| - name: 测试(含降级演练与 schema 守卫) | |
| run: pnpm test | |
| env: | |
| # 只读公开数据足够;不要求、也不允许任何 PAT 入仓(§9.2) | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 构建(§9.1:一条命令产出 dist/) | |
| run: pnpm build | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 构建产物检查 | |
| run: | | |
| test -f dist/index.html | |
| echo "dist/index.html 已生成" | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: dist | |
| path: dist | |
| retention-days: 7 | |
| drills: | |
| name: 降级与守卫演练 | |
| runs-on: ubuntu-latest | |
| needs: checks | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - uses: pnpm/action-setup@v6 | |
| - uses: actions/setup-node@v7 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: pnpm | |
| - run: pnpm install --frozen-lockfile | |
| - name: 演练 1|GitHub API 不可达 + 无缓存 → 站点仍构建成功(§12 第 3 条) | |
| run: | | |
| GITHUB_API_BASE=http://127.0.0.1:9 \ | |
| HUB_PROJECTS_DIR=tests/fixtures/projects-run \ | |
| HUB_META_CACHE=tests/.tmp/drill-cache.json \ | |
| HUB_META_REPORT=tests/.tmp/drill-report.json \ | |
| HUB_SKIP_OG=1 \ | |
| pnpm build | |
| test -f dist/index.html | |
| grep -q '"degradedToEmpty": 2' tests/.tmp/drill-report.json | |
| echo "降级演练通过:自动字段置空、页面正常产出" | |
| - name: 演练 2|非法数据必须让构建失败(§12 第 1 条) | |
| run: | | |
| mkdir -p tests/.tmp/bad-projects | |
| sed -e 's/category: devops/category: not-a-category/' \ | |
| -e 's/slug: example-listed/slug: bad-one/' \ | |
| tests/fixtures/projects/example-listed.yaml > tests/.tmp/bad-projects/bad-one.yaml | |
| if HUB_SKIP_FETCH=1 HUB_PROJECTS_DIR=tests/.tmp/bad-projects pnpm build; then | |
| echo "::error::非法数据竟然构建成功了,schema 守卫失效" | |
| exit 1 | |
| fi | |
| echo "守卫演练通过:非法数据构建失败" | |
| - name: 演练 3|不存在的 repo 必须让 CI 失败并点名(§7) | |
| run: | | |
| if HUB_PROJECTS_DIR=tests/fixtures/submission/repos pnpm check:repos; then | |
| echo "::error::不存在的 repo 竟然通过了核验,§7 门槛失效" | |
| exit 1 | |
| fi | |
| echo "repo 核验演练通过:不存在的仓库被拦下" | |
| - name: 演练 4|第三方外链失败只警告,官方/演示站失败硬拦(§7) | |
| run: | | |
| HUB_PROJECTS_DIR=tests/fixtures/submission/links/third-party pnpm check:links | |
| echo "第三方外链失败仅警告:CI 未失败,符合 §7" | |
| if HUB_PROJECTS_DIR=tests/fixtures/submission/links/official pnpm check:links; then | |
| echo "::error::官方/演示站外链失败竟然放行了,§7 硬拦失效" | |
| exit 1 | |
| fi | |
| echo "官方/演示站外链失败硬拦:符合 §7" | |
| - name: 演练 5|不合规截图必须让 CI 失败并逐条点名(§7) | |
| run: | | |
| if HUB_PROJECTS_DIR=tests/fixtures/submission/screenshots \ | |
| HUB_SCREENSHOTS_DIR=tests/fixtures/screenshots \ | |
| pnpm check:screenshots; then | |
| echo "::error::不合规截图竟然通过了,截图规格校验失效" | |
| exit 1 | |
| fi | |
| echo "截图规格演练通过:宽不足 / 超体积 / 假 webp 均被拦下" | |
| - name: 演练 6|投稿 PR 越界改代码必须失败(§7) | |
| run: | | |
| if HUB_PR_BODY='<!-- hub-submission-pr -->' \ | |
| HUB_PR_CHANGED_FILES=$'src/data/projects/demo.yaml\nsrc/lib/project-schema.ts' \ | |
| pnpm check:pr-scope; then | |
| echo "::error::投稿 PR 越界改代码竟然放行了,变更范围校验失效" | |
| exit 1 | |
| fi | |
| HUB_PR_BODY='<!-- hub-submission-pr -->' \ | |
| HUB_PR_CHANGED_FILES='src/data/projects/demo.yaml' pnpm check:pr-scope | |
| echo "变更范围演练通过:越界被拦、合规放行" | |
| submission-scope: | |
| name: 投稿 PR 变更范围 | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| # 需要与目标分支的 merge-base 做三点 diff | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - uses: pnpm/action-setup@v6 | |
| - uses: actions/setup-node@v7 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: pnpm | |
| - run: pnpm install --frozen-lockfile | |
| - name: 投稿 PR 只允许改数据文件与截图(§7) | |
| run: pnpm check:pr-scope | |
| env: | |
| HUB_PR_BODY: ${{ github.event.pull_request.body }} | |
| HUB_PR_BASE_REF: ${{ github.base_ref }} |