Skip to content

Commit 0a9bd04

Browse files
committed
build(project): add script to manage Go versions
1 parent a1d815e commit 0a9bd04

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

scripts/bump-module.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
major_version=$(cut -d. -f1 < version)
6+
7+
if [ "${major_version}" -gt 1 ]; then
8+
module_name=$(go mod edit -json | jq -r '.Module.Path')
9+
module_name_unversioned=$(echo "${module_name}" | sed -E 's|/v[0-9]+$||')
10+
module_name_versioned="${module_name_unversioned}/v${major_version}"
11+
echo "🔬 major version detected, updating module path to ${module_name_versioned}"
12+
13+
go mod edit -module "${module_name_versioned}"
14+
echo "✅ module name updated to ${module_name_versioned} in go.mod"
15+
16+
if [ "$(uname)" = "Darwin" ]; then
17+
find . -type f -name "*.go" -exec \
18+
sed -i '' "s|\"${module_name}|\"${module_name_versioned}|g" {} \;
19+
else
20+
find . -type f -name "*.go" -exec \
21+
sed -i "s|\"${module_name}|\"${module_name_versioned}|g" {} \;
22+
fi
23+
echo "✅ packages updated to ${module_name_versioned} in source files"
24+
25+
echo "🧹 cleaning up go.sum"
26+
go mod tidy
27+
else
28+
echo "🙅version is not greater than 1, no need to update module path"
29+
fi

0 commit comments

Comments
 (0)