Skip to content

Commit bbc75cf

Browse files
authored
Merge pull request #8 from ppc64le-cloud/version
version command
2 parents 41a4856 + 0c32482 commit bbc75cf

File tree

5 files changed

+90
-14
lines changed

5 files changed

+90
-14
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
push:
55
tags:
66
- '*'
7-
branches: [ master ]
8-
pull_request:
9-
branches: [ master ]
107

118
jobs:
129

@@ -32,24 +29,18 @@ jobs:
3229
dep ensure
3330
fi
3431
35-
- name: Go Formatting
36-
run: |
37-
unformatted=$(gofmt -l -e -d .)
38-
if [[ ! -z "${unformatted}" ]]; then
39-
echo "fix the formatting...."
40-
echo "${unformatted}"
41-
exit 1
42-
fi
43-
4432
- name: Build
4533
run: |
4634
mkdir -p bin
47-
export CGO_ENABLED=0
35+
# workaround for https://github.com/actions/checkout/issues/290
36+
git fetch --tags --force
37+
VERSION=$(git describe --tags --dirty)
38+
STATIC_FLAG='-w -extldflags "-static"'
4839
for platform in darwin/amd64 linux/amd64 linux/ppc64le
4940
do
5041
os_name=$(echo "$platform" | cut -d "/" -f 1)
5142
arch=$(echo "$platform" | cut -d "/" -f 2)
52-
CGO_ENABLED=0 GOOS=${os_name} GOARCH=${arch} go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o bin/pvsadm-${os_name}-${arch} .
43+
CGO_ENABLED=0 GOOS=${os_name} GOARCH=${arch} go build -a -tags netgo -ldflags "-X github.com/ppc64le-cloud/pvsadm/pkg/version.Version=${VERSION} ${STATIC_FLAG}" -o bin/pvsadm-${os_name}-${arch} .
5344
done
5445
tar -czvf pvsadm-binaries.tar.gz bin/
5546

.github/workflows/go_pr.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ^1.15
20+
id: go
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v2
24+
25+
- name: Get dependencies
26+
run: |
27+
go get -v -t -d ./...
28+
if [ -f Gopkg.toml ]; then
29+
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
30+
dep ensure
31+
fi
32+
33+
- name: Go Formatting
34+
run: |
35+
unformatted=$(gofmt -l -e -d .)
36+
if [[ ! -z "${unformatted}" ]]; then
37+
echo "fix the formatting...."
38+
echo "${unformatted}"
39+
exit 1
40+
fi
41+
42+
- name: Build
43+
run: |
44+
mkdir -p bin
45+
# workaround for https://github.com/actions/checkout/issues/290
46+
git fetch --tags --force
47+
VERSION=$(git rev-parse --short HEAD)
48+
STATIC_FLAG='-w -extldflags "-static"'
49+
for platform in darwin/amd64 linux/amd64 linux/ppc64le
50+
do
51+
os_name=$(echo "$platform" | cut -d "/" -f 1)
52+
arch=$(echo "$platform" | cut -d "/" -f 2)
53+
CGO_ENABLED=0 GOOS=${os_name} GOARCH=${arch} go build -a -tags netgo -ldflags "-X github.com/ppc64le-cloud/pvsadm/pkg/version.Version=${VERSION} ${STATIC_FLAG}" -o bin/pvsadm-${os_name}-${arch} .
54+
done
55+
tar -czvf pvsadm-binaries.tar.gz bin/
56+
57+
- name: Test
58+
run: go test -v ./...

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"github.com/ppc64le-cloud/pvsadm/cmd/get"
55
"github.com/ppc64le-cloud/pvsadm/cmd/purge"
6+
"github.com/ppc64le-cloud/pvsadm/cmd/version"
67
"github.com/ppc64le-cloud/pvsadm/pkg"
78
"github.com/ppc64le-cloud/pvsadm/pkg/audit"
89
"github.com/spf13/cobra"
@@ -23,6 +24,7 @@ This is a tool built for the Power Systems Virtual Server helps managing and mai
2324
func init() {
2425
rootCmd.AddCommand(purge.Cmd)
2526
rootCmd.AddCommand(get.Cmd)
27+
rootCmd.AddCommand(version.Cmd)
2628
rootCmd.PersistentFlags().StringVarP(&pkg.Options.APIKey, "api-key", "k", "", "IBMCLOUD API Key(env name: IBMCLOUD_API_KEY)")
2729
rootCmd.PersistentFlags().BoolVar(&pkg.Options.Debug, "debug", false, "Enable PowerVS debug option")
2830
rootCmd.PersistentFlags().StringVar(&pkg.Options.AuditFile, "audit-file", "pvsadm.log", "Audit logs for the tool")

cmd/version/version.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
"github.com/ppc64le-cloud/pvsadm/pkg/version"
6+
"runtime"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var Cmd = &cobra.Command{
12+
Use: "version",
13+
Short: "Print the version number",
14+
Run: func(cmd *cobra.Command, args []string) {
15+
fmt.Printf("Version: %s, GoVersion: %s\n", version.Get(), runtime.Version())
16+
},
17+
}

pkg/version/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package version
2+
3+
// set version while building the binary, otherwise unknown is the version
4+
var Version = "unknown"
5+
6+
func Get() string {
7+
return Version
8+
}

0 commit comments

Comments
 (0)