Skip to content

Commit 43db623

Browse files
authored
Merge pull request #11 from xmudrii/non-v0-tags-fix-3
Modify go mod replace to account for module version
2 parents 66678c5 + f1f8f18 commit 43db623

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

artifacts/scripts/util.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,16 @@ update-deps-in-gomod() {
827827
for (( i=0; i<${dep_count}; i++ )); do
828828
local dep="${deps_array[i]%%:*}"
829829
local dep_commit=$(cd ../${dep}; gomod-pseudo-version)
830-
echo "Updating ${base_package}/${dep} to point to ${dep_commit}"
831-
GO111MODULE=on go mod edit -fmt -require "${base_package}/${dep}@${dep_commit}"
832-
GO111MODULE=on go mod edit -fmt -replace "${base_package}/${dep}=${base_package}/${dep}@${dep_commit}"
830+
local mod_major=$(cd ../${dep}; gomod-module-major)
831+
local go_pkg="${base_package}/${dep}"
832+
833+
if [ "${mod_major}" != "v0" ] && [ "${mod_major}" != "v1" ]; then
834+
go_pkg="${go_pkg}/${mod_major}"
835+
fi
836+
837+
echo "Updating ${go_pkg} to point to ${dep_commit}"
838+
GO111MODULE=on go mod edit -fmt -require "${go_pkg}@${dep_commit}"
839+
GO111MODULE=on go mod edit -fmt -replace "${go_pkg}=${go_pkg}@${dep_commit}"
833840
done
834841

835842
GO111MODULE=on go mod edit -json | jq -r '.Replace[]? | select(.New.Path | startswith("../")) | "-dropreplace \(.Old.Path)"' | GO111MODULE=on xargs -L 100 go mod edit -fmt
@@ -880,6 +887,10 @@ update-deps-in-gomod() {
880887
ensure-clean-working-dir
881888
}
882889

890+
gomod-module-major() {
891+
grep '^module ' go.mod | sed -E 's|^module .*/(v[0-9]+)$|\1|; t; s|.*|v0|'
892+
}
893+
883894
gomod-pseudo-version() {
884895
local commit_sha
885896
commit_sha="$(git rev-parse --short=12 HEAD)"
@@ -906,7 +917,7 @@ gomod-pseudo-version() {
906917
fi
907918

908919
local module_major
909-
module_major="$(grep '^module ' go.mod | sed -E 's|^module .*/(v[0-9]+)$|\1|; t; s|.*|v0|')"
920+
module_major="$(gomod-module-major)"
910921

911922
# head is not a tag ->
912923
# - the latest available tag is vX.Y.Z -> vX.Y.(Z+1)-0.<timestamp>-<hash>

0 commit comments

Comments
 (0)