e2e.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. name: E2E (real DeepSeek API)
  2. # Real-API end-to-end suite (`pnpm run test:e2e`). Unlike ci.yml this job
  3. # consumes the DEEPSEEK_API_KEY_EXTERNAL secret (mapped to the env var
  4. # DEEPSEEK_API_KEY the tests read) and hits the external API at
  5. # https://api.deepseek.com (DEEPSEEK_BASE_URL is pinned to it explicitly so a
  6. # stray repo-root .env can't redirect the run).
  7. #
  8. # pull_request IS a trigger, but GitHub withholds repo secrets from BOTH forked
  9. # PRs and Dependabot PRs (the latter are same-repo, fork==false, but still
  10. # keyless). The job-level `if:` below skips the whole job for those untrusted
  11. # PRs. The Dependabot test keys on the PR AUTHOR (pull_request.user.login), not
  12. # github.actor (the run trigger) — a maintainer reopening a Dependabot PR would
  13. # make github.actor human while the PR is still keyless. When the job runs, the
  14. # secret is expected, so the preflight hard-fails if it's missing (a missing
  15. # secret would otherwise make the self-skipping suite report a false green). A
  16. # job skipped by a job-level `if:` reports as a SUCCESSFUL check, so this
  17. # workflow is safe to use as a required status check if desired.
  18. #
  19. # SECURITY — NEVER change this trigger to `pull_request_target`. `pull_request`
  20. # checks out and runs the PR's HEAD code WITHOUT secrets for forks, which is what
  21. # keeps an untrusted fork from exfiltrating the key. `pull_request_target` runs
  22. # in the BASE repo's context WITH secrets while still able to check out untrusted
  23. # fork code — a textbook key-leak vector, especially once this repo is public.
  24. # The fork/secret model and its public-repo implications are recorded in
  25. # docs/rfc/implemented/testing/2026-06-19-real-api-e2e-ci.md.
  26. #
  27. # Note: scheduled triggers are auto-disabled after 60 days of repo inactivity;
  28. # push/pull_request/workflow_dispatch act as backstops.
  29. on:
  30. workflow_dispatch:
  31. push:
  32. branches: [main, master]
  33. pull_request:
  34. schedule:
  35. # 00:17 UTC nightly = 08:17 Asia/Shanghai — off the top-of-hour cron stampede.
  36. - cron: '17 0 * * *'
  37. # Cancel a superseded PR run (it is on a stale commit); never cancel a
  38. # push/schedule run — it is already producing the post-merge/nightly signal.
  39. concurrency:
  40. group: ${{ github.workflow }}-${{ github.ref }}
  41. cancel-in-progress: ${{ github.event_name == 'pull_request' }}
  42. # Least privilege: this job only reads the repo to run tests.
  43. permissions:
  44. contents: read
  45. jobs:
  46. e2e:
  47. runs-on: ubuntu-latest
  48. # Run on every trusted event. Skip untrusted PRs (forks + Dependabot) where
  49. # the secret is withheld — they would otherwise hard-fail the preflight.
  50. if: >-
  51. github.event_name != 'pull_request'
  52. || !(github.event.pull_request.head.repo.fork || github.event.pull_request.user.login == 'dependabot[bot]')
  53. # Serial files (fileParallelism: false), 120s/test, retry 2. 45m bounds a
  54. # wedged run while leaving headroom for retry storms against a slow API.
  55. timeout-minutes: 45
  56. steps:
  57. - uses: actions/checkout@v6
  58. - uses: actions/setup-node@v6
  59. with:
  60. node-version: 24
  61. - name: Enable corepack (pnpm)
  62. run: corepack enable
  63. - name: Install (immutable)
  64. run: pnpm install --frozen-lockfile
  65. # Guard against a false green: the e2e suites self-skip when the key is
  66. # absent, so a missing/misconfigured secret would otherwise pass as
  67. # "all skipped". This job only runs on trusted events (the `if:` above
  68. # excludes keyless PRs), so the secret MUST be present — fail loudly if not.
  69. - name: Preflight (require DEEPSEEK_API_KEY)
  70. env:
  71. # Repo secret DEEPSEEK_API_KEY_EXTERNAL holds the external-API key;
  72. # the tests read process.env.DEEPSEEK_API_KEY, so map it across here.
  73. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  74. run: |
  75. set -euo pipefail
  76. if [ -z "${DEEPSEEK_API_KEY:-}" ]; then
  77. echo "::error::DEEPSEEK_API_KEY is empty. The e2e suite would self-skip and"
  78. echo "::error::report a false green. Configure the repo secret DEEPSEEK_API_KEY_EXTERNAL."
  79. exit 1
  80. fi
  81. echo "DEEPSEEK_API_KEY present."
  82. # Real-API end-to-end tests only. The keyless gates (lint/typecheck/
  83. # coverage/snapshot/build/etc.) already run in ci.yml on every push/PR;
  84. # no need to repeat them or build first (tests run unbuilt via tsx).
  85. # DEEPSEEK_BASE_URL is pinned to the external API; the secret is scoped to
  86. # this step (and preflight) only — never exposed to checkout/setup/install.
  87. - name: E2E tests (real DeepSeek API)
  88. env:
  89. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  90. DEEPSEEK_BASE_URL: https://api.deepseek.com
  91. run: pnpm run test:e2e