Skip to content

Commit f9375be

Browse files
authored
Update go.mod and go.sum for the sherpa-onnx-go package. (#3516)
1 parent 1150f2f commit f9375be

1 file changed

Lines changed: 82 additions & 2 deletions

File tree

scripts/go/release.sh

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,47 @@ echo "SHERPA_ONNX_DIR: $SHERPA_ONNX_DIR"
1414
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" $SHERPA_ONNX_DIR/CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
1515
echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
1616

17+
GO_PROXY_WAIT_SECS=30
18+
GO_PROXY_MAX_RETRIES=20
19+
20+
# Wait for Go proxy to index newly published packages.
21+
# The Go module proxy (proxy.golang.org) needs time to fetch and index
22+
# new versions after a git push + tag. This function polls until the
23+
# packages are available or the retry limit is reached.
24+
wait_for_go_proxy() {
25+
local pkg="$1"
26+
local version="$2"
27+
local i
28+
for i in $(seq 1 $GO_PROXY_MAX_RETRIES); do
29+
echo "Attempt $i/$GO_PROXY_MAX_RETRIES: checking $pkg@$version ..."
30+
if go list -m -versions "$pkg" 2>/dev/null | grep -q "$version"; then
31+
echo " -> $pkg@$version is available on Go proxy"
32+
return 0
33+
fi
34+
echo " -> not ready yet, sleeping ${GO_PROXY_WAIT_SECS}s ..."
35+
sleep $GO_PROXY_WAIT_SECS
36+
done
37+
echo "ERROR: $pkg@$version not available after $GO_PROXY_MAX_RETRIES attempts"
38+
return 1
39+
}
40+
41+
# Run go mod tidy with retries. Sometimes the proxy has the module metadata
42+
# but the zip download is still being processed.
43+
run_go_mod_tidy() {
44+
local i
45+
for i in $(seq 1 $GO_PROXY_MAX_RETRIES); do
46+
echo "Attempt $i/$GO_PROXY_MAX_RETRIES: running go mod tidy ..."
47+
if go mod tidy 2>&1; then
48+
echo " -> go mod tidy succeeded"
49+
return 0
50+
fi
51+
echo " -> go mod tidy failed, sleeping ${GO_PROXY_WAIT_SECS}s ..."
52+
sleep $GO_PROXY_WAIT_SECS
53+
done
54+
echo "ERROR: go mod tidy failed after $GO_PROXY_MAX_RETRIES attempts"
55+
return 1
56+
}
57+
1758
function linux() {
1859
echo "Process linux"
1960
git clone git@github.com:k2-fsa/sherpa-onnx-go-linux.git
@@ -178,6 +219,41 @@ function basic() {
178219

179220
python3 ./generate.py -s ./sherpa_onnx.go -o ./sherpa-onnx-go
180221

222+
cd sherpa-onnx-go
223+
224+
# Update go.mod to reference the new platform package versions.
225+
# The platform packages (linux/macos/windows) have already been published
226+
# and tagged with v$SHERPA_ONNX_VERSION.
227+
local ver="v$SHERPA_ONNX_VERSION"
228+
sed -i.bak \
229+
-e "s|github.com/k2-fsa/sherpa-onnx-go-linux .*|github.com/k2-fsa/sherpa-onnx-go-linux $ver|" \
230+
-e "s|github.com/k2-fsa/sherpa-onnx-go-macos .*|github.com/k2-fsa/sherpa-onnx-go-macos $ver|" \
231+
-e "s|github.com/k2-fsa/sherpa-onnx-go-windows .*|github.com/k2-fsa/sherpa-onnx-go-windows $ver|" \
232+
go.mod
233+
rm -f go.mod.bak
234+
235+
echo "--- Updated go.mod ---"
236+
cat go.mod
237+
echo "--- end go.mod ---"
238+
239+
# Wait for the Go module proxy to index all three platform packages,
240+
# then regenerate go.sum. The proxy (proxy.golang.org) may take
241+
# several minutes after a git tag push before the module is downloadable.
242+
local pkg
243+
for pkg in sherpa-onnx-go-linux sherpa-onnx-go-macos sherpa-onnx-go-windows; do
244+
wait_for_go_proxy "github.com/k2-fsa/$pkg" "$ver"
245+
done
246+
247+
# go remove stale go.sum entries, then re-resolve with the new versions
248+
rm -f go.sum
249+
run_go_mod_tidy
250+
251+
echo "--- Updated go.sum ---"
252+
cat go.sum
253+
echo "--- end go.sum ---"
254+
255+
cd ..
256+
181257
echo "------------------------------"
182258
cd sherpa-onnx-go
183259
git status
@@ -190,9 +266,13 @@ function basic() {
190266
rm -rf sherpa-onnx-go
191267
}
192268

193-
basic
194-
windows
269+
# Publishing order matters:
270+
# 1. Platform packages first (linux, windows, osx) — they have no inter-dependencies
271+
# 2. Wait for Go proxy to index them
272+
# 3. sherpa-onnx-go last — it depends on all three platform packages
195273
linux
274+
windows
196275
osx
276+
basic
197277

198278
rm -fv ~/.ssh/github

0 commit comments

Comments
 (0)