name: Deploy to GitHub Pages # 部署必须等 Regression 通过 —— 用 `workflow_run` 而不是 `push`: # 这样既把测试变成了部署的硬门槛,又不必把 Regression 拆成可复用工作流、 # 也不会让同一套测试在每次推 main 时跑两遍。手动部署仍走 workflow_dispatch(有意保留的逃生口)。 on: workflow_run: workflows: ["Regression"] types: [completed] branches: [main] workflow_dispatch: permissions: contents: read actions: read # 跨工作流下载 Regression 的 report 产物需要 pages: write id-token: write concurrency: group: pages cancel-in-progress: true jobs: deploy: # workflow_run 触发时必须测试通过;手动触发不受此限。 if: >- github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: persist-credentials: false # workflow_run 的 github.sha 指向默认分支头,必须显式取"被测试的那个提交" ref: ${{ github.event.workflow_run.head_sha || github.sha }} - name: Configure Pages uses: actions/configure-pages@v5 # 首页通过率卡片读的是 tests/report.json。那份文件是入库的,直接用它等于让页面显示 # "提交里的数字"而不是"刚刚验过的数字"。改为取本次 Regression 产出的那份; # 取不到(如手动触发、产物过期)就回退到提交版,不让部署因此变脆。 - name: Fetch the report produced by the Regression run if: github.event_name == 'workflow_run' continue-on-error: true uses: actions/download-artifact@v4 with: name: regression-report run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.GITHUB_TOKEN }} path: ci-report - name: Assemble minimal Pages package shell: bash run: | set -euo pipefail rm -rf site-dist mkdir -p site-dist/site site-dist/frameworks site-dist/.design_library/kole-ui cp index.html sitemap.xml site-dist/ cp -a site/. site-dist/site/ cp -a frameworks/. site-dist/frameworks/ # The documentation routes are History-API paths with no "#" # (/site/component/button/h5): there is no such file on disk, and Pages has no # rewrite config, so it answers unknown paths with /404.html from the publish root. # A copy of the SPA shell therefore keeps deep links and in-page refreshes working — # the shell derives its site root from the URL, so it loads correctly from there. cp site/index.html site-dist/404.html # The live documentation reads these token, aggregate CSS and contract assets. cp .design_library/kole-ui/colors_and_type.css site-dist/.design_library/kole-ui/ cp .design_library/kole-ui/components.css site-dist/.design_library/kole-ui/ cp .design_library/kole-ui/css.json site-dist/.design_library/kole-ui/ cp -a .design_library/kole-ui/components site-dist/.design_library/kole-ui/ # Pages excludes repository-only tests, raw specifications, metadata and reports. rm -rf site-dist/.git site-dist/.github site-dist/.design_library/kole-ui/specs \ site-dist/.design_library/kole-ui/agent-reports site-dist/.design_library/kole-ui/preview \ site-dist/.design_library/kole-ui/ui_kits site-dist/tests # Exception: the homepage pass-rate card fetches ../tests/report.json. Without this # single file the card silently renders nothing (the fetch 404s and is swallowed), # so it must be copied back after the tests/ purge above. # 优先用 Regression 本次产出的报告,取不到才回退到提交里的那份。 REPORT=tests/report.json if [ -f ci-report/tests/report.json ]; then REPORT=ci-report/tests/report.json echo "report source: this Regression run's artifact" else echo "::warning::report source: committed tests/report.json (Regression artifact unavailable)" fi mkdir -p site-dist/tests cp "$REPORT" site-dist/tests/report.json find site-dist -type f \( -name '*.ps1' -o -name '*.yml' -o -name '*.yaml' \) -delete test -f site-dist/404.html test -f site-dist/site/index.html test -f site-dist/site/data.json test -f site-dist/site/tokens/tokens.css test -f site-dist/tests/report.json test "$(find site-dist/site/components -maxdepth 1 -name '*.html' | wc -l)" -eq 79 du -sh site-dist - name: Upload Pages artifact uses: actions/upload-pages-artifact@v3 with: path: site-dist - id: deployment uses: actions/deploy-pages@v4