From 9811830023e648c8b56008c28bf5459cf1135d38 Mon Sep 17 00:00:00 2001 From: "John L. Peterson (Jack)" Date: Tue, 24 Sep 2024 15:23:07 -0400 Subject: [PATCH] Re-add version code to cmd/builder (#11208) Revert "[chore] delete code to set a version and date, as it it not used (#10715)" Remove date string but re-add functions that check for version number This (mostly) reverts commit b53f57d. #### Description This re-enables the functionality to set a version number for ocb binary (cmd/builder). It was erroneously removed. It also adds unit tests for this functionality, as a warning is given on CI with no code coverage. #### Link to tracking issue Relates to https://github.com/open-telemetry/opentelemetry-collector-releases/issues/664. Closes #11220 along with https://github.com/open-telemetry/opentelemetry-collector-releases/pull/665 #### Testing ran build and release cycles inside personal fork repositories (jackgopack4/opentelemetry-collector and jackgopack4/opentelemetry-collector-releases) #### Documentation .chloggen file --- ...jackgopack4-re-add-ocb-version-number.yaml | 25 +++++++++++++++++++ cmd/builder/internal/version.go | 6 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 .chloggen/jackgopack4-re-add-ocb-version-number.yaml diff --git a/.chloggen/jackgopack4-re-add-ocb-version-number.yaml b/.chloggen/jackgopack4-re-add-ocb-version-number.yaml new file mode 100644 index 00000000000..1a8bd5595d0 --- /dev/null +++ b/.chloggen/jackgopack4-re-add-ocb-version-number.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: cmd/builder + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: re-adds function to properly set and view version number of OpenTelemetry Collector Builder (ocb) binaries + +# One or more tracking issues or pull requests related to the change +issues: [11208] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/cmd/builder/internal/version.go b/cmd/builder/internal/version.go index 2e1f39e9f44..9aa5e1511b7 100644 --- a/cmd/builder/internal/version.go +++ b/cmd/builder/internal/version.go @@ -16,8 +16,10 @@ var ( func init() { // the second returned value is a boolean, which is true if the binaries are built with module support. - info, _ := debug.ReadBuildInfo() - version = info.Main.Version + if version == "" { + info, _ := debug.ReadBuildInfo() + version = info.Main.Version + } } func versionCommand() *cobra.Command {