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