返回 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 script: |
23 set -eu
24 ./scripts/release/check-versions.sh
25 ./scripts/release/check-ohos-deps.sh
26 cargo fmt --all -- --check
27 cargo check --workspace --all-targets --locked
28 cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
29 cargo test --workspace --all-features --locked
30 # Parity gates as first-class steps so drift surfaces as a named failure,
31 # not a buried workspace-test entry. Mirrors release.yml's parity job.
32 cargo test -p codewhale-protocol --test parity_protocol --locked
33 cargo test -p codewhale-state --test parity_state --locked
34
35 .linux_rust_gates: &linux_rust_gates
36 name: linux rust gates
37 runner:
38 tags: cnb:arch:amd64
39 cpus: 16
40 docker:
41 image: rust:1.88-bookworm
42 stages:
43 - name: install linux dependencies
44 script: |
45 set -eu
46 apt-get update
47 apt-get install -y git libdbus-1-dev nodejs npm pkg-config
48 if command -v rustup >/dev/null 2>&1; then
49 rustup component add rustfmt clippy
50 fi
51
52 - *rust_workspace_gates_stage
53
54 - name: linux npm wrapper smoke
55 # Full LTO can link silently for longer than CNB's default 10-minute
56 # no-output window. Keep the production profile and give the job enough
57 # time to emit its version and wrapper receipts.
58 timeout: 45m
59 script: |
60 set -eu
61 # The release profile uses full LTO and one codegen unit. Bound Cargo's
62 # parallelism so the final links cannot exhaust a shared CNB runner.
63 cargo build --jobs 2 --release --locked -p codewhale-cli -p codewhale-tui
64 export PATH="$PWD/target/release:$PATH"
65 node scripts/release/npm-wrapper-smoke.js
66 ./target/release/codewhale --version
67 ./target/release/codew --version
68 ./target/release/codewhale-tui --version
69
70 .linux_release_preflight: &linux_release_preflight
71 name: linux release preflight
72 runner:
73 tags: cnb:arch:amd64
74 cpus: 16
75 docker:
76 image: rust:1.88-bookworm
77 stages:
78 - name: install release dependencies
79 script: |
80 set -eu
81 apt-get update
82 apt-get install -y curl git libdbus-1-dev nodejs npm pkg-config
83 if command -v rustup >/dev/null 2>&1; then
84 rustup component add rustfmt clippy
85 fi
86
87 - *rust_workspace_gates_stage
88
89 - name: crate publish dry-run
90 script: |
91 set -eu
92 ./scripts/release/publish-crates.sh dry-run
93
94 - name: release binary smoke
95 # Full LTO can link silently for longer than CNB's default 10-minute
96 # no-output window. Keep the production profile and give the job enough
97 # time to emit its version and wrapper receipts.
98 timeout: 45m
99 script: |
100 set -eu
101 # Keep the production release profile intact while avoiding a burst of
102 # concurrent rustc/linker processes on the shared release runner.
103 cargo build --jobs 2 --release --locked -p codewhale-cli -p codewhale-tui
104 export PATH="$PWD/target/release:$PATH"
105 node scripts/release/npm-wrapper-smoke.js
106 ./target/release/codewhale --version
107 ./target/release/codew --version
108 ./target/release/codewhale-tui --version
109
110 main:
111 push:
112 - *feishu_bridge_tests
113 - *linux_rust_gates
114
115 "(fix/*|rebrand/*)":
116 push:
117 - *linux_rust_gates
118
119 "work/v*":
120 push:
121 - *feishu_bridge_tests
122 - *linux_release_preflight
123
124 $:
125 tag_push:
126 - docker:
127 image: rust:1.88-bookworm
128 stages:
129 - name: build linux x64 release assets (static)
130 # The static full-LTO link can also outlive CNB's default no-output
131 # window. Do not weaken the release profile to keep the runner alive.
132 timeout: 45m
133 script: |
134 set -eu
135
136 apt-get update
137 apt-get install -y git musl-tools nodejs pkg-config
138 rustup target add x86_64-unknown-linux-musl
139
140 ./scripts/release/check-versions.sh
141 ./scripts/release/check-ohos-deps.sh
142 cargo build --jobs 2 --release --locked \
143 --target x86_64-unknown-linux-musl \
144 -p codewhale-cli -p codewhale-tui
145
146 mkdir -p target/cnb-release
147 BIN_DIR="target/x86_64-unknown-linux-musl/release"
148 cp "$BIN_DIR/codewhale" target/cnb-release/codewhale-linux-x64
149 cp "$BIN_DIR/codew" target/cnb-release/codew-linux-x64
150 cp "$BIN_DIR/codewhale-tui" target/cnb-release/codewhale-tui-linux-x64
151 strip \
152 target/cnb-release/codewhale-linux-x64 \
153 target/cnb-release/codew-linux-x64 \
154 target/cnb-release/codewhale-tui-linux-x64 \
155 || true
156
157 (
158 cd target/cnb-release
159 sha256sum \
160 codewhale-linux-x64 \
161 codew-linux-x64 \
162 codewhale-tui-linux-x64 \
163 > codewhale-artifacts-sha256.txt
164 )
165
166 tag_name="${CNB_BRANCH:-}"
167 if [ -z "$tag_name" ]; then
168 tag_name="$(git describe --tags --exact-match 2>/dev/null || true)"
169 fi
170 version="${tag_name#v}"
171 cargo_version="$(grep -E '^version = "' Cargo.toml | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')"
172 if [ -n "$tag_name" ] && [ "$version" != "$cargo_version" ]; then
173 echo "ERROR: tag ${tag_name} does not match Cargo.toml version ${cargo_version}" >&2
174 exit 1
175 fi
176 commit_sha="${CNB_COMMIT:-$(git rev-parse HEAD)}"
177 {
178 echo "# ${tag_name:-CNB release}"
179 echo
180 awk -v version="${version}" '
181 index($0, "## [" version "]") == 1 { in_section = 1; next }
182 in_section && /^## \[/ { exit }
183 in_section { print }
184 ' CHANGELOG.md
185 echo
186 echo "Built by CNB from ${commit_sha}."
187 echo
188 echo "Assets:"
189 echo "- codewhale-linux-x64"
190 echo "- codew-linux-x64"
191 echo "- codewhale-tui-linux-x64"
192 echo "- codewhale-artifacts-sha256.txt"
193 } > target/cnb-release/CNB_RELEASE.md
194
195 - name: create cnb release
196 type: git:release
197 options:
198 descriptionFromFile: target/cnb-release/CNB_RELEASE.md
199 latest: true
200
201 - name: upload linux x64 release assets
202 image: cnbcool/attachments:latest
203 settings:
204 attachments:
205 - target/cnb-release/codewhale-linux-x64
206 - target/cnb-release/codew-linux-x64
207 - target/cnb-release/codewhale-tui-linux-x64
208 - target/cnb-release/codewhale-artifacts-sha256.txt
209
209 lines YAML