From df25cc007e2c72d5b55f83a6f9ee9886d54378e4 Mon Sep 17 00:00:00 2001 From: ET Date: Sun, 16 Aug 2020 08:50:09 -0700 Subject: [PATCH] Introduce a top-level `Version()` and `SemVersion()` function (#225) * Introduce a top-level `Version()` and `SemVersion()` function. These are intended to be used by submodules within the repo that need to specify an "instrumentation version" when creating a tracer or meter. * Included PR number in CHANGELOG * Update contrib.go Co-authored-by: Tyler Yahn * use predeclared constant regex * Add comment about how/when Version() string is updated Co-authored-by: Tyler Yahn --- CHANGELOG.md | 4 ++++ contrib.go | 28 ++++++++++++++++++++++++++++ pre_release.sh | 9 +++++++++ 3 files changed, 41 insertions(+) create mode 100644 contrib.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4cfab4c1c..33c06ecfbcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Added + +- Top-level `Version()` and `SemVersion()` functions defining the current version of the contrib package. (#225) + ## [0.10.1] - 2020-08-13 ### Added diff --git a/contrib.go b/contrib.go new file mode 100644 index 00000000000..c9bec63aa3a --- /dev/null +++ b/contrib.go @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package contrib contains common values used across all +// instrumentation, exporter, and detector contributions. +package contrib // import "go.opentelemetry.io/contrib" + +// Version is the current release version of OpenTelemetry Contrib in use. +func Version() string { + return "0.10.1" + // This string is updated by the pre_release.sh script during release +} + +// SemVersion is the semantic version to be supplied to tracer/meter creation. +func SemVersion() string { + return "semver:" + Version() +} diff --git a/pre_release.sh b/pre_release.sh index e6eaeb5bce3..06b540f2c32 100755 --- a/pre_release.sh +++ b/pre_release.sh @@ -88,6 +88,11 @@ else CONTRIB_TAG=${OTEL_TAG} # if contrib_tag not specified, but OTEL_TAG is, then set it to OTEL_TAG fi +# Get version for contrib.go +OTEL_CONTRIB_VERSION=$(echo "${CONTRIB_TAG}" | egrep -o "${SEMVER_REGEX}") +# Strip leading v +OTEL_CONTRIB_VERSION="${OTEL_CONTRIB_VERSION#v}" + cd "$(dirname "$0")" if ! git diff --quiet; then \ @@ -97,6 +102,10 @@ if ! git diff --quiet; then \ exit 1 fi +# Update contrib.go version definition +sed -i .bak "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_CONTRIB_VERSION}\"/" ./contrib.go +rm -f ./contrib.go.bak + declare -r BRANCH_NAME=pre_release_${CONTRIB_TAG} patch_gomods() {