Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version to commands #342

Merged
merged 2 commits into from
Jan 16, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
uses: actions/checkout@v4
- name: Build ECM Distro Tools
run: |
export VERSION=${GITHUB_REF_NAME}
make test
make package-binaries
- name: Publish Binaries
Expand Down
2 changes: 1 addition & 1 deletion cmd/backport/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ GO = go
BINDIR := bin
BINARY := backport

VERSION = v0.1.0
GIT_SHA = $(shell git rev-parse HEAD)
VERSION ?= snapshot-${GIT_SHA}
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings'
TAGS = "netgo osusergo no_stage static_build"
$(BINDIR)/$(BINARY): clean
Expand Down
11 changes: 7 additions & 4 deletions cmd/backport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/spf13/cobra"
)

var version = "development"

type BackportCmdOpts struct {
Repo string
Issue uint
Expand All @@ -24,10 +26,11 @@ var backportCmdOpts BackportCmdOpts

func main() {
cmd := &cobra.Command{
Use: "backport",
Short: "Generate backport issues and cherry pick commits to branches",
Long: "The backport utility needs to be executed inside the repository you want to perform the actions",
RunE: backport,
Use: "backport",
Short: "Generate backport issues and cherry pick commits to branches",
Long: "The backport utility needs to be executed inside the repository you want to perform the actions",
RunE: backport,
Version: version,
}

cmd.Flags().StringVarP(&backportCmdOpts.Repo, "repo", "r", "", "name of the repository to perform the backport (k3s, rke2)")
Expand Down
2 changes: 1 addition & 1 deletion cmd/release/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ GO = go
BINDIR := bin
BINARY := release

VERSION = v0.1.0
GIT_SHA = $(shell git rev-parse HEAD)
VERSION ?= snapshot-${GIT_SHA}
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings'
TAGS = "netgo osusergo no_stage static_build"

Expand Down
7 changes: 4 additions & 3 deletions cmd/release/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
Expand Down Expand Up @@ -30,6 +27,10 @@ func Execute() {
}
}

func SetVersion(version string) {
rootCmd.Version = version
}

func init() {
rootCmd.Flags().BoolP("debug", "d", false, "Debug")

Expand Down
3 changes: 3 additions & 0 deletions cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import "github.com/rancher/ecm-distro-tools/cmd/release/cmd"

var version = "development"

func main() {
cmd.SetVersion(version)
cmd.Execute()
}
Binary file removed cmd/release/release
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/semv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ GO = go
BINDIR := bin
BINARY := semv

VERSION = v0.1.0
GIT_SHA = $(shell git rev-parse HEAD)
VERSION ?= snapshot-${GIT_SHA}
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings'
TAGS = "netgo osusergo no_stage static_build"

Expand Down
2 changes: 1 addition & 1 deletion cmd/test_coverage/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ GO = go
BINDIR := bin
BINARY := test_coverage

VERSION = v0.1.0
GIT_SHA = $(shell git rev-parse HEAD)
VERSION ?= snapshot-${GIT_SHA}
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings'
TAGS = "netgo osusergo no_stage static_build"

Expand Down
2 changes: 2 additions & 0 deletions cmd/test_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

var (
version = "development"
rootFlags = []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Expand Down Expand Up @@ -45,6 +46,7 @@ func main() {
app.UseShortOptionHandling = true
app.Flags = rootFlags
app.Action = coverage
app.Version = version
err := app.Run(os.Args)
if err != nil {
logrus.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/upstream_go_version/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ GO = go
BINDIR := bin
BINARY := upstream_go_version

VERSION = v0.1.0
GIT_SHA = $(shell git rev-parse HEAD)
VERSION ?= snapshot-${GIT_SHA}
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings'
TAGS = "netgo osusergo no_stage static_build"

Expand Down