Skip to content

Commit ef891c6

Browse files
authored
Merge pull request #24 from sriumcp/assets
Assets
2 parents a5b7276 + 7b8e647 commit ef891c6

23 files changed

+217
-30
lines changed

.github/workflows/assets.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish binaries
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
name: Publish binaries
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Install Go
14+
uses: actions/setup-go@v2
15+
with:
16+
go-version: 1.17
17+
- uses: actions/checkout@v2
18+
- name: Build binaries
19+
run: |
20+
VERSION=${GITHUB_REF#refs/*/}
21+
echo "Version: ${VERSION}"
22+
make dist
23+
- name: Upload binaries to release
24+
uses: svenstaro/upload-release-action@v2
25+
with:
26+
repo_token: ${{ secrets.GITHUB_TOKEN }}
27+
file: _dist/iter8-*.tar.gz
28+
tag: ${{ github.ref }}
29+
overwrite: true
30+
file_glob: true

.github/workflows/release-drafter.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ on:
33
push:
44
# branches to consider in the event; optional, defaults to all
55
branches:
6-
- master
6+
- master
7+
78
jobs:
89
update_release_draft:
910
runs-on: ubuntu-latest

Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ BINDIR := $(CURDIR)/bin
22
INSTALL_PATH ?= /usr/local/bin
33
DIST_DIRS := find * -type d -exec
44
TARGETS := darwin/amd64 darwin/arm64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x windows/amd64
5-
65
BINNAME ?= iter8
76
ITER8_IMG ?= iter8/iter8:latest
87

@@ -23,7 +22,9 @@ SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
2322
# Required for globs to work correctly
2423
SHELL = /usr/bin/env bash
2524

25+
GIT_COMMIT = $(shell git rev-parse HEAD)
2626
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
27+
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
2728

2829
ifdef VERSION
2930
BINARY_VERSION = $(VERSION)
@@ -32,10 +33,18 @@ BINARY_VERSION ?= ${GIT_TAG}
3233

3334
# Only set Version if building a tag or VERSION is set
3435
ifneq ($(BINARY_VERSION),)
35-
LDFLAGS += -X github.com/iter8-tools/iter8/basecli/RootCmd.Version=${BINARY_VERSION}
36+
LDFLAGS += -X github.com/iter8-tools/iter8/basecli.version=${BINARY_VERSION}
37+
endif
38+
39+
VERSION_METADATA = unreleased
40+
# Clear the "unreleased" string in BuildMetadata
41+
ifneq ($(GIT_TAG),)
42+
VERSION_METADATA =
3643
endif
3744

38-
LDFLAGS += $(EXT_LDFLAGS)
45+
LDFLAGS += -X github.com/iter8-tools/iter8/basecli.metadata=${VERSION_METADATA}
46+
LDFLAGS += -X github.com/iter8-tools/iter8/basecli.gitCommit=${GIT_COMMIT}
47+
LDFLAGS += -X github.com/iter8-tools/iter8/basecli.gitTreeState=${GIT_DIRTY}
3948

4049
.PHONY: all
4150
all: build
@@ -76,16 +85,15 @@ $(GOX):
7685
.PHONY: build-cross
7786
build-cross: LDFLAGS += -extldflags "-static"
7887
build-cross: $(GOX)
79-
GOFLAGS="-trimpath" GO111MODULE=on CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./
88+
GOFLAGS="-trimpath" GO111MODULE=on CGO_ENABLED=0 $(GOX) -parallel=9 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./
8089

8190
.PHONY: dist
8291
dist: build-cross
8392
( \
8493
cd _dist && \
8594
$(DIST_DIRS) cp ../LICENSE {} \; && \
8695
$(DIST_DIRS) cp ../README.md {} \; && \
87-
$(DIST_DIRS) tar -zcf iter8-${VERSION}-{}.tar.gz {} \; && \
88-
$(DIST_DIRS) zip -r iter8-${VERSION}-{}.zip {} \; \
96+
$(DIST_DIRS) tar -zcf iter8-{}.tar.gz {} \; \
8997
)
9098

9199
.PHONY: clean

basecli/k8s.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func RenderTpl(k8sExp k8sExperiment, filePath string) (*bytes.Buffer, error) {
9797
// ensure it is a valid template
9898
tmpl, err = template.New("tpl").Funcs(template.FuncMap{
9999
"toYAML": toYAML,
100-
"defaultImage": func() string { return "iter8/iter8:" + (RootCmd.Version)[1:] },
101-
"iter8MajorMinorVersion": func() string { return RootCmd.Version },
100+
"defaultImage": func() string { return "iter8/iter8:" + majorMinor[1:] },
101+
"iter8MajorMinorVersion": func() string { return majorMinor },
102102
}).Option("missingkey=error").Funcs(sprig.TxtFuncMap()).Parse(string(tplBytes))
103103
if err != nil {
104104
log.Logger.WithStackTrace(err.Error()).Error("unable to parse template file")

basecli/root.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ Environment variables:
1515

1616
// RootCmd represents the base command when called without any subcommands
1717
var RootCmd = &cobra.Command{
18-
Use: "iter8",
19-
Short: "Metrics driven experiments",
20-
Long: globalUsage,
21-
Version: "v0.8",
18+
Use: "iter8",
19+
Short: "Metrics driven experiments",
20+
Long: globalUsage,
2221
}
2322

2423
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -30,5 +29,4 @@ func Execute() {
3029
func init() {
3130
// disable completion command for now
3231
RootCmd.CompletionOptions.DisableDefaultCmd = true
33-
RootCmd.InitDefaultVersionFlag()
3432
}

basecli/version.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package basecli
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var short bool
11+
12+
var (
13+
// version is the semantic version of Iter8
14+
// this variable is intended to be set using LDFLAGS at build time
15+
version = "v0.8.8"
16+
// version is the current major/minor version of Iter8
17+
// set this manually whenever the major or minor version changes
18+
majorMinor = "v0.8"
19+
// metadata is extra build time data
20+
metadata = ""
21+
// gitCommit is the git sha1
22+
gitCommit = ""
23+
// gitTreeState is the state of the git tree
24+
gitTreeState = ""
25+
)
26+
27+
// BuildInfo describes the compile time information.
28+
type BuildInfo struct {
29+
// Version is the current semver.
30+
Version string `json:"version,omitempty"`
31+
// GitCommit is the git sha1.
32+
GitCommit string `json:"git_commit,omitempty"`
33+
// GitTreeState is the state of the git tree.
34+
GitTreeState string `json:"git_tree_state,omitempty"`
35+
// GoVersion is the version of the Go compiler used to compile Iter8.
36+
GoVersion string `json:"go_version,omitempty"`
37+
}
38+
39+
// versionCmd represents the version command
40+
var versionCmd = &cobra.Command{
41+
Use: "version",
42+
Short: "Print Iter8 version information",
43+
Long: `
44+
Show the version for Iter8.
45+
46+
The output will look something like this:
47+
48+
version.BuildInfo{Version:"v0.8.10", GitCommit:"fe51cd1e31e6a202cba7aliv9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.16.10"}
49+
50+
- Version is the semantic version of the release.
51+
- GitCommit is the SHA for the commit that this version was built from.
52+
- GitTreeState is "clean" if there are no local code changes when this binary was
53+
built, and "dirty" if the binary was built from locally modified code.
54+
- GoVersion is the version of Go that was used to compile Iter8.
55+
`,
56+
Run: func(cmd *cobra.Command, args []string) {
57+
v := get()
58+
if short {
59+
if len(v.GitCommit) >= 7 {
60+
fmt.Printf("%s+g%s", v.Version, v.GitCommit[:7])
61+
fmt.Println()
62+
return
63+
}
64+
fmt.Println(getVersion())
65+
return
66+
}
67+
fmt.Printf("%#v", v)
68+
fmt.Println()
69+
},
70+
}
71+
72+
// getVersion returns the semver string of the version
73+
func getVersion() string {
74+
if metadata == "" {
75+
return version
76+
}
77+
return version + "+" + metadata
78+
}
79+
80+
// get returns build info
81+
func get() BuildInfo {
82+
v := BuildInfo{
83+
Version: getVersion(),
84+
GitCommit: gitCommit,
85+
GitTreeState: gitTreeState,
86+
GoVersion: runtime.Version(),
87+
}
88+
return v
89+
}
90+
91+
func init() {
92+
RootCmd.AddCommand(versionCmd)
93+
f := versionCmd.Flags()
94+
f.BoolVar(&short, "short", false, "print the version number")
95+
}

basecli/version_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package basecli
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestVersion(t *testing.T) {
8+
versionCmd.Run(nil, nil)
9+
short = true
10+
versionCmd.Run(nil, nil)
11+
}

mkdocs/docs/user-guide/commands/iter8.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Environment variables:
2323
### Options
2424

2525
```
26-
-h, --help help for iter8
27-
-v, --version version for iter8
26+
-h, --help help for iter8
2827
```
2928

3029
### SEE ALSO
@@ -35,5 +34,6 @@ Environment variables:
3534
* [iter8 k](iter8_k.md) - Work with experiments running in Kubernetes
3635
* [iter8 report](iter8_report.md) - Generate report from experiment result
3736
* [iter8 run](iter8_run.md) - Run an experiment
37+
* [iter8 version](iter8_version.md) - Print Iter8 version information
3838

39-
###### Auto generated by spf13/cobra on 6-Jan-2022
39+
###### Auto generated by spf13/cobra on 7-Jan-2022

mkdocs/docs/user-guide/commands/iter8_assert.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ iter8 assert -c completed,nofailures,slosby=0 -t 5s
5555

5656
* [iter8](iter8.md) - Metrics driven experiments
5757

58-
###### Auto generated by spf13/cobra on 6-Jan-2022
58+
###### Auto generated by spf13/cobra on 7-Jan-2022

mkdocs/docs/user-guide/commands/iter8_gen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ Render templates with values
3030
* [iter8 gen exp](iter8_gen_exp.md) - Render experiment.yaml file by combining an experiment chart with values.
3131
* [iter8 gen k8s](iter8_gen_k8s.md) - Generate manifest for running experiment in Kubernetes
3232

33-
###### Auto generated by spf13/cobra on 6-Jan-2022
33+
###### Auto generated by spf13/cobra on 7-Jan-2022

0 commit comments

Comments
 (0)