Skip to content

Commit df25cc0

Browse files
evantorrieMrAlias
andauthored
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 <[email protected]> * use predeclared constant regex * Add comment about how/when Version() string is updated Co-authored-by: Tyler Yahn <[email protected]>
1 parent 9a03b4b commit df25cc0

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Top-level `Version()` and `SemVersion()` functions defining the current version of the contrib package. (#225)
14+
1115
## [0.10.1] - 2020-08-13
1216

1317
### Added

contrib.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package contrib contains common values used across all
16+
// instrumentation, exporter, and detector contributions.
17+
package contrib // import "go.opentelemetry.io/contrib"
18+
19+
// Version is the current release version of OpenTelemetry Contrib in use.
20+
func Version() string {
21+
return "0.10.1"
22+
// This string is updated by the pre_release.sh script during release
23+
}
24+
25+
// SemVersion is the semantic version to be supplied to tracer/meter creation.
26+
func SemVersion() string {
27+
return "semver:" + Version()
28+
}

pre_release.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ else
8888
CONTRIB_TAG=${OTEL_TAG} # if contrib_tag not specified, but OTEL_TAG is, then set it to OTEL_TAG
8989
fi
9090

91+
# Get version for contrib.go
92+
OTEL_CONTRIB_VERSION=$(echo "${CONTRIB_TAG}" | egrep -o "${SEMVER_REGEX}")
93+
# Strip leading v
94+
OTEL_CONTRIB_VERSION="${OTEL_CONTRIB_VERSION#v}"
95+
9196
cd "$(dirname "$0")"
9297

9398
if ! git diff --quiet; then \
@@ -97,6 +102,10 @@ if ! git diff --quiet; then \
97102
exit 1
98103
fi
99104

105+
# Update contrib.go version definition
106+
sed -i .bak "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_CONTRIB_VERSION}\"/" ./contrib.go
107+
rm -f ./contrib.go.bak
108+
100109
declare -r BRANCH_NAME=pre_release_${CONTRIB_TAG}
101110

102111
patch_gomods() {

0 commit comments

Comments
 (0)