返回 CodeWhale
CNB_MIRROR.md
根目录 / docs / CNB_MIRROR.md
1 # CNB Cool mirror
2
3 > 阅读简体中文版:[zh_hans/CNB_MIRROR.md](zh_hans/CNB_MIRROR.md)。
4
5 `cnb.cool/codewhale.net/codewhale` is a one-way mirror of this
6 GitHub repository for users on networks where GitHub is slow or blocked
7 (primarily mainland China). The mirror receives every push to `main` and
8 each `v*` release tag after its complete GitHub Release is published. The
9 GitCode mirror (`gitcode.com/HunterBown/Codewhale`) receives the same `main`
10 and release tags from [`Sync to GitCode`](../.github/workflows/sync-gitcode.yml);
11 it carries source only, with no binary releases.
12
13 ## Source and downloads are separate checks
14
15 Check source identity separately from the actual versioned release, assets,
16 and checksum manifest. A successful GitHub mirror workflow or a mirrored source
17 tag does not guarantee binary availability on CNB: CNB builds Linux x64
18 artifacts from the pushed tag, and if that build fails or has not completed,
19 its checksum manifest will return 404. Re-pushing an existing tag does not
20 create a fresh tag-push build; maintainers must recover the build/publication
21 separately and verify the result while preserving published tags.
22
23 ## Provenance
24
25 **GitHub is the sole canonical source.** All releases, tags, and source code
26 originate at `github.com/codewhale-hq/CodeWhale`. The CNB mirror is a read-only
27 replica maintained by the `Sync to CNB` workflow — it exists solely to serve
28 users behind GFW-blocked or slow GitHub connections.
29
30 Every CNB release includes `codewhale-artifacts-sha256.txt` — a SHA256 manifest
31 of the CNB-built Linux x64 binaries, generated from the same source commit that
32 is tagged on GitHub. (CNB builds from source, so these checksums cover the
33 CNB-built artifacts, not GitHub's release assets.) Verify a downloaded binary
34 against it:
35
36 ```bash
37 # Verify a downloaded CNB binary against the CNB manifest
38 sha256sum -c codewhale-artifacts-sha256.txt --ignore-missing
39 ```
40
41 ## How it works
42
43 The mirror is maintained by the [`Sync to CNB`](../.github/workflows/sync-cnb.yml)
44 GitHub Actions workflow:
45
46 - **Trigger:** `push` to `main`, the release workflow after canonical publication,
47 the `release: published` event for a release published outside it, a
48 schedule at :17 and :47 past each hour, or `workflow_dispatch` for manual
49 recovery. The schedule re-mirrors `main` (catching pushes that started no
50 workflow) and pushes the latest GitHub Release tag when CNB lacks it, after
51 the same release-inventory check (GitCode does the same without the
52 inventory check); it fails when that tag differs on CNB or
53 its CNB checksum manifest is unreachable. It never creates a tag or
54 release: it only copies ones already published on GitHub. A tag push alone does not mirror a release tag. Manual tag recovery
55 also verifies the complete public GitHub asset inventory and immutable source.
56 - **Auth:** HTTPS basic auth as user `cnb` with the `CNB_GIT_TOKEN`
57 repository secret as the password. Forks never inherit the secret, so the
58 `sync` job runs only when the repository owner is `codewhale-hq`; on a fork
59 it is skipped instead of failing. In this repository a missing or misspelled
60 secret still fails the push step.
61 - **Scope:** only the ref that triggered the run is pushed. Tag pushes
62 push exactly that tag; branch syncs push `main`. Other branches and
63 dependabot refs are intentionally *not* mirrored.
64 - **Concurrency:** `cnb-sync-${{ github.ref }}` serializes each ref separately.
65 Distinct release tags cannot replace one another in a global pending slot;
66 only a newer push of the same branch supersedes its pending branch sync.
67 - **Retry:** each push is retried up to three times with linear
68 backoff (5s, 10s) before the workflow gives up.
69
70 CNB pipeline configuration is also source-controlled in GitHub at
71 [`/.cnb.yml`](../.cnb.yml). This is deliberate: the sync workflow force-mirrors
72 GitHub refs to CNB, so pipeline files created only on the CNB side will be
73 overwritten. Submit `.cnb.yml` changes through GitHub and let the one-way
74 mirror carry them to CNB.
75
76 ## CNB tag releases
77
78 When CNB receives a `v*` tag, the root `.cnb.yml` tag pipeline builds Linux x64
79 release assets from source and publishes a CNB release with:
80
81 - `codewhale-linux-x64`
82 - `codew-linux-x64`
83 - `codewhale-tui-linux-x64` (compatibility-only release filename; not a third
84 installed command)
85 - `codewhale-artifacts-sha256.txt`
86
87 This gives users who can reach CNB but not GitHub a CNB-native release path.
88 GitHub remains the canonical macOS/Windows release matrix; the CNB tag pipeline
89 is the China-friendly Linux x64 fallback.
90 The GitHub release workflow calls the mirror only after publishing its complete,
91 verified asset set. CNB cannot publish a version whose canonical release failed.
92 An existing CNB tag must match; recovery never force-updates a release tag.
93
94 ## CNB Linux CI and release preflight
95
96 First-party `fix/*` and `rebrand/*` branches are mirrored to CNB so the heavy
97 Linux Rust gates run on Tencent-hosted runners instead of GitHub Actions:
98
99 - `./scripts/release/check-versions.sh`
100 - `cargo fmt --all -- --check`
101 - `cargo check --workspace --all-targets --locked`
102 - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`
103 - `cargo test --workspace --all-features --locked`
104 - `cargo build --release --locked -p codewhale-cli --bin codewhale`
105 - `node scripts/release/npm-wrapper-smoke.js`
106
107 Release branches matching `work/v*` also run
108 `./scripts/release/publish-crates.sh dry-run`. GitHub Actions keeps the cheap
109 drift/fmt statuses plus the macOS and Windows jobs that CNB cannot replace.
110
111 ## Verifying the mirror after a release
112
113 After `release.yml` completes for a `vX.Y.Z` tag, the CNB mirror
114 should have both the new commit on `main` and the new tag:
115
116 ```bash
117 # Quick check: does the new tag exist on CNB?
118 git ls-remote https://cnb.cool/codewhale.net/codewhale.git \
119 refs/tags/vX.Y.Z
120
121 # Quick check: is CNB's main at the same commit as origin/main?
122 gh_main=$(git ls-remote https://github.com/codewhale-hq/CodeWhale.git refs/heads/main | awk '{print $1}')
123 cnb_main=$(git ls-remote https://cnb.cool/codewhale.net/codewhale.git refs/heads/main | awk '{print $1}')
124 test "$gh_main" = "$cnb_main" && echo "in sync" || echo "DIVERGED: gh=$gh_main cnb=$cnb_main"
125 ```
126
127 Or check the workflow run directly:
128
129 ```bash
130 gh run list --workflow=sync-cnb.yml --repo codewhale-hq/CodeWhale --limit 5
131 ```
132
133 If the most recent run for the release tag is `success`, the mirror
134 caught it. If it's `failure`, fix or re-run the mirror workflow before
135 directing users to the mirrored tag.
136
137 ## Manual fallback
138
139 Manual mirror repair is maintainer-only. Do not put PATs in remote URLs or
140 publish force-push recipes in contributor-facing docs. Use the configured
141 GitHub Actions secret and the workflow dispatch path whenever possible.
142
143 ### Re-trigger the workflow manually
144
145 If the workflow is healthy but happened to fail on the release run
146 (e.g. a transient CNB outage that's since cleared), retrigger it
147 without pushing anything:
148
149 ```bash
150 # Prefer rerunning the existing failed tag run when one exists.
151 gh run rerun <failed-tag-run-id> --repo codewhale-hq/CodeWhale
152
153 # If no tag run exists, dispatch from the exact existing release tag.
154 gh workflow run sync-cnb.yml --repo codewhale-hq/CodeWhale --ref vX.Y.Z
155 ```
156
157 Do not omit `--ref` when repairing a tag: a default-branch dispatch syncs
158 `main`, not `refs/tags/vX.Y.Z`. Afterward, prove the tag and its Linux x64
159 release assets exist before directing users to CNB.
160
161 ## Rotating `CNB_GIT_TOKEN`
162
163 If the workflow starts failing with auth errors and the token has
164 expired:
165
166 1. Log in to `cnb.cool` and generate a new personal access token
167 with `repo` (push) scope.
168 2. Update the `CNB_GIT_TOKEN` repository secret:
169 ```bash
170 gh secret set CNB_GIT_TOKEN --repo codewhale-hq/CodeWhale
171 ```
172 3. Re-trigger the workflow on a recent commit:
173 ```bash
174 gh workflow run sync-cnb.yml --repo codewhale-hq/CodeWhale
175 ```
176 4. Confirm the run succeeds via `gh run list --workflow=sync-cnb.yml`.
177
178 ## Binary release assets and `codewhale update`
179
180 CNB now builds Linux x64 assets for `v*` tags from the source-controlled
181 `.cnb.yml` pipeline. GitHub remains the canonical macOS/Windows release matrix.
182
183 ### Automatic source selection (Linux x64)
184
185 On Linux x64, `codewhale update` picks its asset source before it downloads
186 anything large. Once the target tag is known, it requests
187 `codewhale-artifacts-sha256.txt` for that exact tag from GitHub Releases and
188 from the CNB release **at the same time**, and takes the first source that
189 answers with a manifest listing `codewhale-linux-x64`. The straggler's answer is
190 discarded.
191
192 Three properties this relies on:
193
194 - **The manifest is the probe.** It is a few hundred bytes, so a blocked or slow
195 source loses in about the time its connection takes to fail — the user never
196 waits out a stalled multi-megabyte asset download, and no timeout is doing the
197 choosing.
198 - **Manifest and binary come from the same source.** CNB builds its own
199 artifacts from the tagged source (musl-static, not GitHub's glibc build), so
200 the two manifests describe different bytes and are not interchangeable. The
201 winning source supplies both, and a checksum mismatch fails the update rather
202 than falling back to the loser.
203 - **Selection never changes which release is installed.** The tag still comes
204 from GitHub's stable-release or beta-release lookup, so `--beta` keeps its
205 meaning; only where the bytes for that tag are fetched from is decided by the
206 probe.
207
208 `codewhale update` and `codewhale update --check` both print the result as a
209 `Release source:` line, and the post-install summary repeats it, so the source a
210 given binary came from is recoverable after the fact.
211
212 Every other target keeps a single canonical source: CNB publishes Linux x64 and
213 nothing else, so macOS, Windows, Android, and Linux arm64 do not race CNB;
214 Linux riscv64 remains explicitly unsupported. All supported self-update paths
215 are nevertheless checksum-required: the chosen source must publish a valid
216 `codewhale-artifacts-sha256.txt` entry for the exact platform binary, or
217 `codewhale update` stops before downloading that binary. There is no
218 unverified-install fallback.
219
220 Setting `CODEWHALE_RELEASE_BASE_URL` (or a legacy alias) or
221 `CODEWHALE_USE_CNB_MIRROR` turns selection off entirely — an explicitly named
222 source is used as named, including its own checksum manifest, with
223 `CODEWHALE_RELEASE_BASE_URL` outranking `CODEWHALE_USE_CNB_MIRROR`.
224
225 ### Manual paths
226
227 Users behind GitHub-blocking networks can also select a source explicitly:
228
229 - **`cargo install`** from the CNB mirror:
230 ```bash
231 cargo install --git https://cnb.cool/codewhale.net/codewhale --tag vX.Y.Z codewhale-cli --locked
232 ```
233 The current `codewhale` binary runs the TUI in-process. Cargo users who want
234 the optional short command can add a `codew` symlink beside it; a separate
235 `codewhale-tui` install is not required.
236 Linux build-time dependencies (`build-essential`, `pkg-config`,
237 `libdbus-1-dev` on Debian/Ubuntu) are required — see
238 [INSTALL.md](INSTALL.md#5-cargo-and-building-from-source).
239
240 - **CNB release assets** for Linux x64, when the matching CNB tag pipeline has
241 completed successfully. Download `codewhale-linux-x64`, `codew-linux-x64`,
242 and `codewhale-artifacts-sha256.txt` from the CNB release for `vX.Y.Z`, then
243 verify the binaries against the manifest. The published
244 `codewhale-tui-linux-x64` file is a legacy-client bridge and is not required
245 by current installs. On Linux x64 and OpenHarmony x64 the npm wrapper probes
246 that CNB checksum manifest concurrently with GitHub Releases for the exact
247 package version and locks onto the first source whose HTTP response and
248 manifest validate — it does not wait for a slow GitHub binary download. Set
249 `CODEWHALE_USE_CNB_MIRROR=1` to force CNB only, or
250 `CODEWHALE_RELEASE_BASE_URL` to skip the race. Other platforms must use
251 GitHub or a complete `CODEWHALE_RELEASE_BASE_URL` mirror.
252
253 - **`CODEWHALE_RELEASE_BASE_URL`** environment variable, if a CDN mirror of
254 release assets exists. The npm wrapper installer and `codewhale update` read
255 this variable to redirect binary downloads. For `codewhale update`, also set
256 `CODEWHALE_VERSION=X.Y.Z` so the updater can label the mirrored
257 release without contacting GitHub. The directory pointed to must contain
258 `codewhale-artifacts-sha256.txt` and the platform binaries; format matches
259 a GitHub Release asset directory. The earlier `DEEPSEEK_TUI_*` names remain
260 accepted as compatibility aliases.
261
262 ## Clone from CNB
263
264 For a stable install, clone `main` or a release tag from:
265
266 ```bash
267 https://cnb.cool/codewhale.net/codewhale.git
268 ```
269
270 The mirror receives `main` and release tags. GitHub
271 is the fallback when the CNB workflow or credentials are unhealthy.
272
273 The bilingual self-hosting guide is
274 [`scripts/tencent-lighthouse/README.md`](../scripts/tencent-lighthouse/README.md).
275 CNB deploy-button examples live in
276 [`deploy/tencent-lighthouse/cnb/`](../deploy/tencent-lighthouse/cnb/README.md). They are
277 not active until copied into `.cnb.yml` and `.cnb/tag_deploy.yml`, because live
278 deploy jobs require a Lighthouse deploy key, target host, and explicit CNB
279 quota/billing policy.
280
280 lines MARKDOWN