Skip to content

Commit d93ed68

Browse files
committed
scripts: Add helper script to update Nomad's module suffix
1 parent d97e32d commit d93ed68

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
# Copyright IBM Corp. 2024, 2026
3+
# SPDX-License-Identifier: BUSL-1.1
4+
5+
set -euo pipefail
6+
7+
if [ -z "${1:-}" ]; then
8+
echo "usage: $0 MODULE_VERSION"
9+
echo "(run in project directory)"
10+
echo "For example: $0 v2"
11+
exit 1
12+
fi
13+
14+
mod_version="$1"
15+
16+
# Read current module path from go.mod
17+
current_module=$(grep '^module ' go.mod | awk '{print $2}')
18+
if [ -z "${current_module}" ]; then
19+
echo "unable to find current module in go.mod"
20+
exit 1
21+
fi
22+
23+
new_module="github.com/hashicorp/nomad/${mod_version}"
24+
base_module="github.com/hashicorp/nomad"
25+
26+
echo "--> Replacing ${current_module} with ${new_module} ..."
27+
28+
# Update go.mod
29+
go mod edit -module "${new_module}"
30+
31+
# Update Go source files.
32+
#
33+
# The API package has its own go module, so ignore that directory. Do not touch
34+
# the generated proto files, this will be handled by code generation later on
35+
# via the makefile target.
36+
#
37+
# The sed command uses a double-pass, so that changes to Nomad packages that
38+
# import the API package do not include the new version identifier. The API
39+
# module does not get tagged and is not subject to the versioning change.
40+
find . -name '*.go' \
41+
-not -path './api/*' \
42+
-not -name '*.pb.go' \
43+
-exec sed -i '' \
44+
-e "s|\"${current_module}/|\"${new_module}/|g" \
45+
-e "s|\"${new_module}/api|\"${base_module}/api|g" \
46+
{} +
47+
48+
# Update buf.gen.yaml proto module mappings
49+
sed -i '' -e "s|${current_module}/|${new_module}/|g" tools/buf/buf.gen.yaml
50+
51+
# Update embedded Go import path in the raftutil message type generator. If more
52+
# scripts are identified in the future that need updating, they should be added
53+
# here.
54+
sed -i '' \
55+
-e "s|${current_module}/|${new_module}/|g" \
56+
helper/raftutil/generate_msgtypes.sh
57+
58+
# The proto files need to be generated in this instance before the structs.
59+
make proto
60+
make generate-structs

0 commit comments

Comments
 (0)