Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GIT_REV:= $(shell git rev-parse --short HEAD 2>/dev/null)
VERSION:= $(shell git describe --tags --exact-match 2>/dev/null || (echo $(GIT_REV) | cut -c1-12))
endif
# insert here the go module where to add the version metadata
VERSION_MODULE_NAME:= github.com/mia-platform/miactl/internal/cmd
VERSION_MODULE_NAME:= github.com/mia-platform/miactl/internal/version

# supported platforms for container creation, these are a subset of the supported
# platforms of the base image.
Expand Down
5 changes: 5 additions & 0 deletions internal/clioptions/clioptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/mia-platform/miactl/internal/cliconfig"
"github.com/mia-platform/miactl/internal/client"
"github.com/mia-platform/miactl/internal/logger"
"github.com/mia-platform/miactl/internal/version"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -363,6 +364,10 @@ func defaultUserAgent() string {
command = filepath.Base(osCommand)
}

if version.Version != "" {
command = fmt.Sprintf("%s@%s", command, version.Version)
}

os := runtime.GOOS
arch := runtime.GOARCH
return fmt.Sprintf("%s (%s/%s)", command, os, arch)
Expand Down
9 changes: 2 additions & 7 deletions internal/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ import (
"github.com/spf13/cobra"

"github.com/mia-platform/miactl/internal/clioptions"
"github.com/mia-platform/miactl/internal/version"
)

// Version is dynamically set by the ci or overridden by the Makefile.
var Version = ""

// BuildDate is dynamically set at build time by the cli or overridden in the Makefile.
var BuildDate = "" // YYYY-MM-DD

func VersionCmd(_ *clioptions.CLIOptions) *cobra.Command {
versionOutput := versionFormat(Version, BuildDate)
versionOutput := versionFormat(version.Version, version.BuildDate)
// Version subcommand
cmd := &cobra.Command{
Use: "version",
Expand Down
22 changes: 22 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Mia srl
// SPDX-License-Identifier: Apache-2.0
//
// 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 version

// Version is dynamically set by the ci or overridden by the Makefile.
var Version = ""

// BuildDate is dynamically set at build time by the cli or overridden in the Makefile.
var BuildDate = "" // YYYY-MM-DD
Loading