Skip to content

Commit

Permalink
Add version to commands (#342)
Browse files Browse the repository at this point in the history
* add version information

* set version on release action

---------

Co-authored-by: Pedro Tashima <[email protected]>
  • Loading branch information
tashima42 and tashima42 authored Jan 16, 2024
1 parent 81fe047 commit 2068a71
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 12 deletions.
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

0 comments on commit 2068a71

Please sign in to comment.