Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,42 @@ set -o pipefail
source $(dirname "$0")/../vendor/knative.dev/hack/library.sh

go_update_deps "$@"

# Sync semconv imports with the resolved OTEL module.
log.step "Syncing semconv imports"
OTEL_VERSION=$(go list -m -f '{{.Version}}' go.opentelemetry.io/otel 2>/dev/null || true)
if [ -n "$OTEL_VERSION" ]; then
group "Detected go.opentelemetry.io/otel ${OTEL_VERSION}"

# Semconv versions are package directories inside the OTEL module.
OTEL_DIR=$(GOFLAGS=-mod=mod go list -m -f '{{.Dir}}' go.opentelemetry.io/otel 2>/dev/null || true)
SEMCONV_VERSION=""
if [ -d "${OTEL_DIR}/semconv" ]; then
SEMCONV_VERSION=$(find "${OTEL_DIR}/semconv" -mindepth 1 -maxdepth 1 \
-type d -name 'v[0-9]*.[0-9]*.[0-9]*' -exec basename {} \; | sort -V | tail -1)
fi

if [ -n "$SEMCONV_VERSION" ]; then
group "Updating semconv imports to ${SEMCONV_VERSION}"
mapfile -t SEMCONV_FILES < <(
find observability -type f -name '*.go' -exec \
grep -lE 'go\.opentelemetry\.io/otel/semconv/v[0-9]+\.[0-9]+\.[0-9]+' {} + || true
)
SEMCONV_IMPORTS_CHANGED=false
for file in "${SEMCONV_FILES[@]}"; do
current_versions=$(grep -oE \
'go\.opentelemetry\.io/otel/semconv/v[0-9]+\.[0-9]+\.[0-9]+' "$file" | \
sed -E 's#.*(v[0-9]+\.[0-9]+\.[0-9]+)$#\1#' | sort -u)
if [ "$current_versions" != "$SEMCONV_VERSION" ]; then
group " ${file}"
sed -i -E "s|(go.opentelemetry.io/otel/semconv/)v[0-9]+\.[0-9]+\.[0-9]+|\1$SEMCONV_VERSION|g" "$file"
SEMCONV_IMPORTS_CHANGED=true
fi
done

[ "$SEMCONV_IMPORTS_CHANGED" = true ] && go_update_deps

else
group "Could not determine semconv version, skipping"
fi
fi
Loading