Skip to content

Commit

Permalink
feautre: bedag#36 adding github actions go release
Browse files Browse the repository at this point in the history
Signed-off-by: Klopfenstein Kevin <kk@sudo-i.net>
  • Loading branch information
chifu1234 committed Apr 14, 2021
1 parent ccb7068 commit e6bdd04
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 33 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
tags:
- '*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:

jobs:
goreleaser-test:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
main
kusible
coverage/
release/
release/dist/
37 changes: 37 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com

env:
- GO111MODULE=on
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
ldflags:
- -s -w -X github.com/bedag/kusible/cmd.version={{.Version}} -X github.com/bedag/kusible/cmd.commit={{.Commit}} -X github.com/bedag/kusible/cmd.date={{.Date}}
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
84 changes: 53 additions & 31 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,73 @@ package cmd
import (
"fmt"

"encoding/json"
goVersion "go.hein.dev/go-version"

"github.com/spf13/cobra"
)

const appName = "kusible"

// Version is the application version. It will be overriden during the build process.
// See https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications
var Version = "development"
// // Version is the application version. It will be overriden during the build process.
// // See https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications
// var Version = "development"

// BuildTime is the date/time when the binary was build. It should be set by the build process and will not be
// displayed if it is empty.
var BuildTime string
// // BuildTime is the date/time when the binary was build. It should be set by the build process and will not be
// // displayed if it is empty.
// var BuildTime string

// GitRev is the Git revision of the code the binary is build from. It should be set by the build process and will not be
// displayed if it is empty.
var GitRev string
// // GitRev is the Git revision of the code the binary is build from. It should be set by the build process and will not be
// // displayed if it is empty.
// var GitRev string

// GitTreeState indicates if the git tree had uncommited changes when the binary was build. It should be set by the build
// process and will not be displayed if it is empty.
var GitTreeState string
// // GitTreeState indicates if the git tree had uncommited changes when the binary was build. It should be set by the build
// // process and will not be displayed if it is empty.
// var GitTreeState string

type BuildInfo struct {
Version string `json:"Version,omitempty"`
GitRev string `json:"GitRev,omitempty"`
BuildTime string `json:"BuildTime,omitempty"`
GitTreeState string `json:"GitTreeState,omitempty"`
}
// type BuildInfo struct {
// Version string `json:"Version,omitempty"`
// GitRev string `json:"GitRev,omitempty"`
// BuildTime string `json:"BuildTime,omitempty"`
// GitTreeState string `json:"GitTreeState,omitempty"`
// }

// func newVersionCmd() *cobra.Command {
// cmd := &cobra.Command{
// Use: "version",
// Short: fmt.Sprint("Print the version number of ", appName),
// Run: func(cmd *cobra.Command, args []string) {
// bi := BuildInfo{
// Version: Version,
// GitRev: GitRev,
// BuildTime: BuildTime,
// GitTreeState: GitTreeState,
// }

// version, _ := json.MarshalIndent(bi, "", " ")
// fmt.Println(string(version))
// },
// }
// return cmd
// }


var (
shortened = false
version = "dev"
commit = "none"
date = "unknown"
output = "json"
)
func newVersionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: fmt.Sprint("Print the version number of ", appName),
Run: func(cmd *cobra.Command, args []string) {
bi := BuildInfo{
Version: Version,
GitRev: GitRev,
BuildTime: BuildTime,
GitTreeState: GitTreeState,
}

version, _ := json.MarshalIndent(bi, "", " ")
fmt.Println(string(version))
Short: "Version will output the current build information",
Long: ``,
Run: func(_ *cobra.Command, _ []string) {
resp := goVersion.FuncWithOutput(shortened, version, commit, date, output)
fmt.Print(resp)
return
},
}
return cmd
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
go.hein.dev/go-version v0.1.0
gotest.tools v2.2.0+incompatible
helm.sh/helm/v3 v3.5.3
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/apiserver v0.20.2
k8s.io/cli-runtime v0.20.2
k8s.io/client-go v0.20.2
sigs.k8s.io/yaml v1.2.0
Expand Down
Loading

0 comments on commit e6bdd04

Please sign in to comment.