-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·194 lines (177 loc) · 6.83 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·194 lines (177 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
# Per-phase wall-clock timing. Every long phase below wraps in `phase`
# so the orchestrator log surfaces a `[phase: NAME] took Ns` line that
# makes "why is the build slow today" answerable from log alone.
BUILD_T0=$SECONDS
phase() {
local name="$1"; shift
local t0=$SECONDS
echo "[phase: $name] start"
if ! "$@"; then
echo "[phase: $name] FAILED after $((SECONDS - t0))s"
return 1
fi
echo "[phase: $name] took $((SECONDS - t0))s"
}
# Load NVM and use project-pinned Node.js version
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm use
if [ "$PARTIAL_BUILD" != "true" ]; then
echo "Creating directories..."
mkdir -p src/static/generated
mkdir -p src/static/generated/image-cache
mkdir -p src/static/css
mkdir -p src/static/csv
mkdir -p src/static/images
mkdir -p src/static/js
mkdir -p index
# `npm ci` is faster than `npm install` (uses package-lock.json
# verbatim, skips the resolver) and guarantees the lockfile is
# respected so a transitive-dep float can't slip into a build. Falls
# back to `npm install` when the lockfile is missing (eg. fresh
# local dev). content-sidecar uses highlight.js; jscpd lives in
# devDependencies for the dup-code gate below.
npm_install() {
if [ -f package-lock.json ]; then
npm ci --no-audit --no-fund
else
npm install --no-audit --no-fund
fi
}
if ! phase "npm" npm_install; then
echo "ERROR: npm install failed"
exit 1
fi
cargo_build() {
cargo build --release --manifest-path rust/Cargo.toml
}
if ! phase "cargo build" cargo_build; then
echo "ERROR: Rust build failed. Install rustup from https://rustup.rs/ if missing."
exit 1
fi
# Sanity check: run.sh and rust/target/release/indexer reference the
# default cargo target dir. If a dev has CARGO_TARGET_DIR set, copy
# the binaries into the expected location so the rest of build.sh +
# the service entrypoint still find them.
CARGO_TARGET="${CARGO_TARGET_DIR:-rust/target}"
if [ "$CARGO_TARGET" != "rust/target" ]; then
mkdir -p rust/target/release
cp -f "$CARGO_TARGET/release/server" rust/target/release/server
cp -f "$CARGO_TARGET/release/indexer" rust/target/release/indexer
cp -f "$CARGO_TARGET/release/sitegen" rust/target/release/sitegen 2>/dev/null || true
cp -f "$CARGO_TARGET/release/sdkgen" rust/target/release/sdkgen 2>/dev/null || true
cp -f "$CARGO_TARGET/release/trans" rust/target/release/trans 2>/dev/null || true
fi
for bin in server indexer sitegen sdkgen trans; do
if [ ! -x "rust/target/release/$bin" ]; then
echo "ERROR: rust/target/release/$bin missing after cargo build"
exit 1
fi
done
echo "Rust build complete."
# Rust duplicate-code gate. Threshold + scope configured in
# .jscpd.json; the wrapper script handles jscpd 4.2.3's broken
# exit-code behavior on threshold breach.
jscpd_check() {
node scripts/check-dup-rust.js
}
if ! phase "jscpd" jscpd_check; then
echo "ERROR: Rust duplicate-code threshold exceeded (see jscpd output above)"
exit 1
fi
rm -f src/static/generated/*.* # when reusing workspaces on the build server, don't let generated index nodes build up over time. -f flag to ignore errors.
# SDK documentation. Rust sdkgen owns the full pipeline:
# README parser, OpenAPI generator (fails on missing methods/return
# types), 4 AI generators (typescript/rust/cpp/nim) sharing LlmClient
# against src/sdk-ai-cache/, and meta.json emission.
sdkgen_run() { ./rust/target/release/sdkgen; }
if ! phase "sdkgen" sdkgen_run; then
echo "ERROR: SDK documentation generation failed"
exit 1
fi
if [ -n "$(git status --porcelain src/sdk-ai-cache 2>/dev/null)" ]; then
echo "Committing SDK AI cache changes..."
git add -A src/sdk-ai-cache
if ! git commit -m "Automated SDK AI cache update"; then
echo "ERROR: SDK AI cache commit failed"
exit 1
fi
echo "Pushing SDK AI cache changes..."
if ! git push; then
echo "ERROR: SDK AI cache push failed"
exit 1
fi
echo "SDK AI cache changes pushed."
else
echo "No SDK AI cache changes to commit."
fi
styling_run() { ./rust/target/release/sitegen custom-styling; }
if ! phase "custom-styling" styling_run; then
echo "ERROR: Custom styling guide generation failed"
exit 1
fi
# Translation pipeline. Rust trans owns all three phases (markdown
# items, UI strings, meta.json - see rust/trans/src/main.rs).
# `trans check` flags any gap as a non-zero exit; on miss we branch
# into `trans run` which translates+writes back.
trans_check_t0=$SECONDS
echo "[phase: trans check] start"
./rust/target/release/trans check
translation_check_result=$?
echo "[phase: trans check] took $((SECONDS - trans_check_t0))s"
if [ $translation_check_result -ne 0 ]; then
trans_run_run() { ./rust/target/release/trans run; }
if ! phase "trans run" trans_run_run; then
echo "ERROR: Translation failed"
exit 1
fi
# Check if there are changes to commit. translate covers
# src/content (markdown items + meta_translated/), src/translations.json
# (UI strings), src/translation-cache.json (markdown + meta hashes),
# and src/ui-translation-cache.json (UI hashes).
if [ -n "$(git status --porcelain src/content src/translations.json src/translation-cache.json src/ui-translation-cache.json 2>/dev/null)" ]; then
echo "Committing translation changes..."
git add -A src/content
git add src/translations.json
git add src/translation-cache.json
git add src/ui-translation-cache.json
if ! git commit -m "Automated translation update"; then
echo "ERROR: Git commit failed"
exit 1
fi
echo "Translation changes committed."
echo "Pushing translation changes..."
if ! git push; then
echo "ERROR: Git push failed"
exit 1
fi
echo "Translation changes pushed."
else
echo "No translation changes to commit."
fi
else
echo "All translations up to date."
fi
# MAX_BROWSERS=1 caps chromiumoxide concurrency for the screenshot marker.
sitegen_build() { MAX_BROWSERS=1 ./rust/target/release/sitegen build; }
if ! phase "sitegen build" sitegen_build; then
echo "ERROR: Content build failed"
exit 1
fi
# Static file copies.
sitegen_static() { ./rust/target/release/sitegen build-static; }
if ! phase "sitegen build-static" sitegen_static; then
echo "ERROR: Static build failed"
exit 1
fi
# Search indexes. Use the prebuilt binary directly so we don't pay
# cargo's resolve+check cost on every prod run. The Rust server in
# run.sh reads exactly these `index/<locale>/` dirs.
indexer_run() { ./rust/target/release/indexer; }
if ! phase "indexer" indexer_run; then
echo "ERROR: Search index build failed"
exit 1
fi
echo "Build Complete in $((SECONDS - BUILD_T0))s!"
fi