Skip to content
36 changes: 31 additions & 5 deletions ops/gmpctl/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,54 @@ release-lib::gomod_vulnfix() {
return 1
fi

if [[ "${vuln_file}" != /* ]]; then
vuln_file="$(pwd)/${vuln_file}"
fi

# Read the vulnerability file line by line.
# The `|| [[ -n "$line" ]]` part handles the case where the last line doesn't have a newline.
pushd "${dir}"
Comment thread
bwplotka marked this conversation as resolved.
while IFS= read -r line || [[ -n "$line" ]]; do
# Skip any empty lines in the input file.
if [ -z "$line" ]; then
continue
fi

mod=$(echo "$line" | awk '{print $2}')
mod=$(echo "$line" | awk '{print $1}')
mod_path=$(echo "${mod}" | cut -d'@' -f1)
desired_version=$(echo "${mod}" | cut -d'@' -f2)
desired_version=$(echo "${mod}" | cut -s -d'@' -f2)

if [[ -z "${mod_path}" ]] || [[ -z "${desired_version}" ]]; then
echo "⚠️ Skipping malformed line: $line"
continue
fi

echo "🔄 Updating module '${mod_path}' to version '${desired_version}'..."
${SED} -i "s|\( ${mod_path} \).*|\1${desired_version}|" "${dir}/go.mod"
if [[ "${mod_path}" == go.opentelemetry.io/otel* ]]; then
# OpenTelemetry core API/SDK modules share versions and schema URLs across packages (e.g. otel, otel/sdk, otel/trace, otel/metric).
# Upgrade core otel modules present in the module graph together to avoid conflicting schema URL errors.
otel_mods=$(go list -m all 2>/dev/null | awk '/^go\.opentelemetry\.io\/otel($|\/)/ && !/^go\.opentelemetry\.io\/otel\/(contrib|semconv)/ {print $1}')
all_otel=$(echo "${mod_path} ${otel_mods}" | tr ' ' '\n' | sort -u)
otel_args=""
for m in $(echo "${all_otel}" | tr ' ' '\n'); do
if go list -m "${m}@${desired_version}" >/dev/null 2>&1; then
otel_args="${otel_args} ${m}@${desired_version}"
fi
done
if [[ -n "${otel_args// /}" ]]; then
Comment thread
bwplotka marked this conversation as resolved.
echo "🔄 Updating OpenTelemetry modules simultaneously:${otel_args}..."
go get ${otel_args}

@bwplotka bwplotka Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: sed was on purpose here -- it limits the chained updates related to this dep. go mod tidy after sed-ing scopes updates only to things that truly are needed.

e.g. client_golang update does not need latest 0.x common, and breaking changes on those occur.

${SED} -i "s|\(	${mod_path} \).*|\1${desired_version}|" "${dir}/go.mod"

Something to keep in mind, but we could try with this, especially AI is forcing this all the time ;p

else
log_err "Could not resolve any OpenTelemetry modules matching version '${desired_version}'"
popd
return 1
fi

else
echo "🔄 Updating module '${mod_path}' to version '${desired_version}'..."
go get "${mod_path}@${desired_version}"
fi
done <"${vuln_file}"
echo "🔄 Resolving ${dir}/go.mod..."
pushd "${dir}"
go mod tidy
popd
}
Expand Down
Loading