返回 CodeWhale
.cnb.yml
根目录 / .cnb.yml
1 # CNB is a one-way mirror from GitHub. Keep this file source-controlled here;
2 # CNB-side edits will be overwritten by the GitHub -> CNB sync workflow.
3
4 .feishu_bridge_tests: &feishu_bridge_tests
5 name: feishu bridge tests
6 runner:
7 tags: cnb:arch:amd64
8 cpus: 8
9 docker:
10 image: node:22-bookworm
11 stages:
12 - name: feishu bridge tests
13 script: |
14 set -eu
15 cd integrations/feishu-bridge
16 npm ci
17 npm run check
18 npm test
19
20 .rust_workspace_gates_stage: &rust_workspace_gates_stage
21 name: rust workspace gates
22 # The all-feature TUI test crate is large enough that concurrent rustc and
23 # clippy processes or disposable test debug metadata can exceed the shared
24 # CNB runner's memory. Keep the full gate surface, but serialize Cargo,
25 # omit test-only debug tables, and use the established workspace-test stack
26 # size so deep runtime API tests do not abort on the platform default.
27 timeout: 45m
28 script: |
29 set -eu
30 export CARGO_BUILD_JOBS=1
31 export CARGO_PROFILE_TEST_DEBUG=0
32 ./scripts/release/check-versions.sh
33 ./scripts/release/check-ohos-deps.sh
34 cargo fmt --all -- --check
35 cargo check --workspace --all-targets --locked
36 cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
37 # Use the shared test HOME boundary while retaining the real toolchain.
38 RUST_MIN_STACK=16777216 sh scripts/with-hermetic-test-home.sh cargo test --workspace --all-features --locked
39 # Parity gates as first-class steps so drift surfaces as a named failure,
40 # not a buried workspace-test entry. Mirrors release.yml's parity job.
41 sh scripts/with-hermetic-test-home.sh cargo test -p codewhale-protocol --test parity_protocol --locked
42 sh scripts/with-hermetic-test-home.sh cargo test -p codewhale-state --test parity_state --locked
43
44 .linux_rust_gates: &linux_rust_gates
45 name: linux rust gates
46 runner:
47 tags: cnb:arch:amd64
48 cpus: 16
49 docker:
50 image: rust:1.88-bookworm
51 # codewhale-cnb-bridge GitHub App credentials from the CNB KeyStore
52 # (codewhale.net/codewhale-ci-secrets, github-bridge.yml), injected as
53 # environment variables. Values are never printed.
54 # https://docs.cnb.cool/en/repo/secret.html
55 imports:
56 - https://cnb.cool/codewhale.net/codewhale-ci-secrets/-/blob/main/github-bridge.yml
57 stages:
58 - name: install linux dependencies
59 script: |
60 set -eu
61 apt-get update
62 apt-get install -y git libdbus-1-dev nodejs npm pkg-config
63 if command -v rustup >/dev/null 2>&1; then
64 rustup component add rustfmt clippy
65 fi
66
67 - *rust_workspace_gates_stage
68
69 - name: linux npm wrapper smoke
70 # Full LTO can link silently for longer than CNB's default 10-minute
71 # no-output window. Keep the production profile and give the job enough
72 # time to emit its version and wrapper receipts.
73 timeout: 45m
74 script: |
75 set -eu
76 # The release profile uses full LTO and one codegen unit. Bound Cargo's
77 # parallelism so the final links cannot exhaust a shared CNB runner.
78 cargo build --jobs 2 --release --locked -p codewhale-cli
79 cp target/release/codewhale target/release/codew
80 export PATH="$PWD/target/release:$PATH"
81 node scripts/release/npm-wrapper-smoke.js
82 ./target/release/codewhale --version
83 ./target/release/codew --version
84
85 # Shadow-parity bridge (ops design: CNB-PRIMARY-CI-DESIGN-20260830). Post one
86 # non-required "-cnb" Check Run on the exact GitHub SHA being built so the
87 # CNB verdict is visible on GitHub while GitHub Actions stays the canonical,
88 # required CI. endStages always run and cannot fail the pipeline, so a
89 # bridge outage never turns a green CNB build red (and vice versa: the CNB
90 # verdict is reported from CNB_PIPELINE_STATUS, not from this stage).
91 endStages:
92 - name: github shadow check run
93 script: |
94 set -eu
95 case "${CNB_PIPELINE_STATUS:-error}" in
96 success) conclusion="success" ;;
97 cancel) conclusion="cancelled" ;;
98 *) conclusion="failure" ;;
99 esac
100 node scripts/ci/cnb-github-checkrun.mjs \
101 --name "linux rust gates -cnb" \
102 --sha "${CNB_COMMIT}" \
103 --status completed \
104 --conclusion "${conclusion}" \
105 --details-url "${CNB_BUILD_WEB_URL:-https://cnb.cool/${CNB_REPO_SLUG}}" \
106 --summary "CNB pipeline '${CNB_PIPELINE_NAME:-linux rust gates}' finished with status ${CNB_PIPELINE_STATUS:-unknown} on ${CNB_BRANCH:-unknown branch} (${CNB_COMMIT}). Shadow lane per the CNB-primary CI design: GitHub Actions remains canonical and required; nothing is gated on this check."
107
108 .linux_release_preflight: &linux_release_preflight
109 name: linux release preflight
110 runner:
111 tags: cnb:arch:amd64
112 cpus: 16
113 docker:
114 image: rust:1.88-bookworm
115 stages:
116 - name: install release dependencies
117 script: |
118 set -eu
119 apt-get update
120 apt-get install -y curl git libdbus-1-dev nodejs npm pkg-config
121 if command -v rustup >/dev/null 2>&1; then
122 rustup component add rustfmt clippy
123 fi
124
125 - *rust_workspace_gates_stage
126
127 - name: crate publish dry-run
128 script: |
129 set -eu
130 ./scripts/release/publish-crates.sh dry-run
131
132 - name: release binary smoke
133 # Full LTO can link silently for longer than CNB's default 10-minute
134 # no-output window. Keep the production profile and give the job enough
135 # time to emit its version and wrapper receipts.
136 timeout: 45m
137 script: |
138 set -eu
139 # Keep the production release profile intact while avoiding a burst of
140 # concurrent rustc/linker processes on the shared release runner.
141 cargo build --jobs 2 --release --locked -p codewhale-cli
142 cp target/release/codewhale target/release/codew
143 export PATH="$PWD/target/release:$PATH"
144 node scripts/release/npm-wrapper-smoke.js
145 ./target/release/codewhale --version
146 ./target/release/codew --version
147
148 main:
149 push:
150 - *feishu_bridge_tests
151 - *linux_rust_gates
152
153 "(fix/*|rebrand/*)":
154 push:
155 - *linux_rust_gates
156
157 "work/v*":
158 push:
159 - *feishu_bridge_tests
160 - *linux_release_preflight
161
162 $:
163 tag_push:
164 - docker:
165 image: rust:1.88-bookworm
166 stages:
167 - name: build linux x64 release assets (static)
168 # The static full-LTO link can also outlive CNB's default no-output
169 # window. Do not weaken the release profile to keep the runner alive.
170 timeout: 45m
171 script: |
172 set -eu
173
174 apt-get update
175 apt-get install -y git musl-tools nodejs pkg-config
176 rustup target add x86_64-unknown-linux-musl
177
178 ./scripts/release/check-versions.sh --require-dated-release
179 ./scripts/release/check-ohos-deps.sh
180 checkout_sha="$(git rev-parse 'HEAD^{commit}')"
181 commit_sha="${CNB_COMMIT:-${checkout_sha}}"
182 if [ "$commit_sha" != "$checkout_sha" ]; then
183 echo "ERROR: CNB_COMMIT ${commit_sha} does not match checkout ${checkout_sha}" >&2
184 exit 1
185 fi
186 export CODEWHALE_BUILD_SHA="$commit_sha"
187 cargo build --jobs 2 --release --locked \
188 --target x86_64-unknown-linux-musl \
189 -p codewhale-cli # single binary
190
191 mkdir -p target/cnb-release
192 BIN_DIR="target/x86_64-unknown-linux-musl/release"
193 cp "$BIN_DIR/codewhale" target/cnb-release/codewhale-linux-x64
194 cp "$BIN_DIR/codewhale" target/cnb-release/codew-linux-x64
195 cp "$BIN_DIR/codewhale" target/cnb-release/codewhale-tui-linux-x64
196 strip \
197 target/cnb-release/codewhale-linux-x64 \
198 target/cnb-release/codew-linux-x64 \
199 target/cnb-release/codewhale-tui-linux-x64 \
200 || true
201
202 (
203 cd target/cnb-release
204 sha256sum \
205 codewhale-linux-x64 \
206 codew-linux-x64 \
207 codewhale-tui-linux-x64 \
208 > codewhale-artifacts-sha256.txt
209 )
210
211 tag_name="${CNB_BRANCH:-}"
212 if [ -z "$tag_name" ]; then
213 tag_name="$(git describe --tags --exact-match 2>/dev/null || true)"
214 fi
215 version="${tag_name#v}"
216 cargo_version="$(grep -E '^version = "' Cargo.toml | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')"
217 if [ -n "$tag_name" ] && [ "$version" != "$cargo_version" ]; then
218 echo "ERROR: tag ${tag_name} does not match Cargo.toml version ${cargo_version}" >&2
219 exit 1
220 fi
221 {
222 echo "# ${tag_name:-CNB release}"
223 echo
224 awk -v version="${version}" '
225 index($0, "## [" version "]") == 1 { in_section = 1; next }
226 in_section && /^## \[/ { exit }
227 in_section { print }
228 ' CHANGELOG.md
229 echo
230 echo "Built by CNB from ${commit_sha}."
231 echo
232 echo "Assets:"
233 echo "- codewhale-linux-x64"
234 echo "- codew-linux-x64"
235 echo "- codewhale-tui-linux-x64 (v0.9.4 compatibility alias)"
236 echo "- codewhale-artifacts-sha256.txt"
237 } > target/cnb-release/CNB_RELEASE.md
238
239 - name: create cnb release
240 type: git:release
241 options:
242 descriptionFromFile: target/cnb-release/CNB_RELEASE.md
243 latest: true
244
245 - name: upload linux x64 release assets
246 image: cnbcool/attachments:latest
247 settings:
248 attachments:
249 - target/cnb-release/codewhale-linux-x64
250 - target/cnb-release/codew-linux-x64
251 - target/cnb-release/codewhale-tui-linux-x64
252 - target/cnb-release/codewhale-artifacts-sha256.txt
253
253 lines YAML