Skip to content

EN CI Automation

dongle edited this page Nov 16, 2026 · 7 revisions

CI & PR Automation

SniShaper uses a single build workflow (microsoft/winget-pkgs style) to drive all CI and PR bots. There is no workflow_run chain and no separate status-listener workflow.

Workflow overview

File Responsibility
.github/workflows/build.yml The only build workflow: direct pushes to main build, PRs get the CLA gate + full matrix + bot invocation
.github/workflows/cla.yml Contributor agreement: sign guidance on PR open, /agree handling, reviewer assignment, CI restart
.github/workflows/review-status.yml Human review state → labels (CHANGES_REQUESTED / APPROVED)
.github/scripts/bots/common.sh Shared library: exemption list, gh_retry, sync_labels mutex groups, bot_comment anchor upsert
.github/scripts/bots/ci-diagnose.sh CI failure diagnosis: downloads failed job logs and produces the five-element diagnosis
.github/scripts/bots/labels.sh Label utilities
.github/workflows/sync-forks.yml Weekly fork audit: opens upstream sync PRs for stale forks, skips forks with an existing linked PR

Removed: pr-ci.yml, ci-status.yml (the old workflow_run chain, collapsed into build.yml).

build.yml trigger matrix

Event Behavior
push to main Build only (no bots)
pull_request (opened / synchronize / reopened) CLA gate → build → bots
workflow_dispatch (manual) Build only

Key points:

  • Gate: the matrix only runs when the PR author is exempt or the PR carries the cla-signed label; otherwise everything is skipped (neutral grey, not a red X).
  • Concurrency: one build per PR (build-<PR-number> group); a newer push cancels the stale matrix.
  • tests job: reintroduced as the test & vet job (windows-latest, parallel to the build matrix): go vet -tags with_gvisor ./... + go test -tags with_gvisor ./... + frontend npm ci then tsc --noEmit, wired into the ci summary job's needs; a failure turns the ci check red. -race and benchmarks still run locally by developers (docs/regression-tests_EN.md, docs/benchmarks.md in the repository).
  • Performance benchmarks: CI does not run benchmarks (shared runners are too noisy); developers validate performance changes on their own machines with benchstat — methodology in docs/benchmarks_EN.md in the repository.
  • ci job: a stable single-point summary check name for branch protection.
  • bot-report job: after the build, the syntax-review-bot posts comments and writes labels.

CLA flow (cla.yml + policy-bot)

  1. PR opened → the policy-bot posts a sign-guidance comment and the cla-pending label.
  2. The PR author comments anything containing agree → cla-signed label + confirmation reply + reviewer assignment (Snishaper, skipping the author) + reviewers-assigned label.
  3. After signing, cla.yml reruns the PR's pull_request build run (not workflow_dispatch — dispatched checks never show up in the PR merge box; a rerun keeps the original event so the checks land in the merge box in place).

State-machine labels

Nine labels; sync_labels enforces the mutex groups:

  • {cla-pending, cla-signed} mutually exclusive
  • {ci-running, ci-failed, ci-passed} mutually exclusive
  • {changes-requested, approved} mutually exclusive
  • A new CI round (adding ci-running) also clears syntax-review, changes-requested and approved

One round: push → ci-running → (success: ci-passed + syntax-review / failure: ci-failed + changes-requested) → stop.

CI failure diagnosis

On CI failure the syntax-review-bot posts a fresh diagnosis comment per round (anchor <!-- snishaper-bot:ci-diagnostic:<run_id> -->) with five elements per failed job: pipeline/platform/arch, error type, location, summary (raw log line), and job/run links. Diagnostic logs are downloaded with the workflow's GITHUB_TOKEN (actions: read) via curl; do not add an Accept: text/plain header (the logs endpoint returns 415).

Weekly fork sync (sync-forks.yml)

Runs every Monday at 04:19 UTC and can also be triggered manually with workflow_dispatch; dry_run=true reports without creating PRs.

  • Enumerates every fork via GET /repos/SnishaperTeam/SniShaper/forks, skipping archived and disabled repositories.
  • Uses the compare API on fork default branch...SnishaperTeam:main; ahead_by == 0 means the fork is up to date.
  • For stale forks it opens a PR with head=SnishaperTeam:main and base=<fork default branch>. A fork with an open PR whose head repository is the upstream repository (or whose head repository was deleted but whose label is SnishaperTeam:main) is skipped.
  • The PR head is the upstream default branch, so later upstream commits land in the same PR automatically; after a merge the fork is current and the next run opens nothing.
  • Credential priority: FORK_SYNC_TOKEN -> RENOVATE_TOKEN -> GITHUB_TOKEN. Cross-repository PR creation needs a classic PAT with public_repo; with only GITHUB_TOKEN the job is forced into report-only mode.
  • Forks whose history was rewritten (No common ancestor from compare) and repositories that are no longer reachable are skipped. If a large compare response cannot be read, the job falls back to comparing branch SHAs, which still detects stale forks.
  • A single fork's API failure is a warning, not a job failure; the run ends with checked / created / skipped counts.
  • SnishaperTeam/SniShaper-Fast is not a GitHub fork (no fork relationship), so cross-repository PRs do not apply and it is out of scope.

Known GitHub behaviors (pitfalls)

  • A push that carries workflow-file changes drops its own synchronize trigger — the new workflow definition only takes effect from the next push.
  • Dependabot-triggered runs receive no repo secrets — pull_request runs initiated by Dependabot get no secrets injected, so the syntax-bot App credentials are empty. The mark CI running and bot-report jobs therefore carry github.actor != 'dependabot[bot]' in their if: Dependabot runs skip these two steps (the build matrix still runs), while human-triggered runs drive the state machine normally.
  • Fork PRs' pull_request runs likewise receive no repo secrets — mark CI running and bot-report therefore also carry a !github.event.pull_request.head.repo.fork guard: fork PRs skip those two jobs while build and test still run.
  • The secrets context is not available in job-level if (fails with Unrecognized named-value: 'secrets'; the workflow dies with zero jobs) — branching on secret presence must be done at step level, or via conditions like github.actor.
  • When a PR branch's merge-base is old, parallel cherry-picks against main dirty the merge ref and synchronize triggers get dropped. Always base test/feature branches on the latest main.
  • Bot label writes never re-trigger the build (labeled is not a trigger type), so there is no label → workflow → label feedback loop.

AI-localized release announcements (_release_pipeline.yml)

After publishing a release, the pipeline posts an in-app announcement to the notice service (/api/notices). The announcement bodies are AI-summarized: .github/scripts/generate-notice-summaries.ps1 uses an LLM (the OpenAI-compatible API behind LLM_API_KEY first, falling back to local Ollama) to summarize the Changes section of the release notes into three plain-text summaries — Chinese, English and Russian — written to notice-summaries.md (## zh / ## en / ## ru sections). The announcement step parses that file into body / body_en / body_ru. When the LLM is unavailable or its output is invalid, the step falls back to the raw Changes text; the announcement steps are continue-on-error and never block a release.

Clone this wiki locally