From 5867e412eba604d7136b12f90a84fd34b478cf45 Mon Sep 17 00:00:00 2001 From: Yuvraj <10830562+evalsocket@users.noreply.github.com> Date: Mon, 24 Aug 2020 22:21:11 +0530 Subject: [PATCH] release workflow added (#170) * release workflow added * run ci pipeline * lint fix --- .github/workflows/release.yaml | 24 ++++++++++++++ .goreleaser.yml | 59 ++++++++++++++++++++++++++++++++++ version/version.go | 28 ++++++++++++++++ version/version_test.go | 29 +++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yml create mode 100644 version/version.go create mode 100644 version/version_test.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..89e7dc1d0b --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,24 @@ +name: Release + +on: + push: + tags: + - 'v.*.*.*' + +jobs: + release-cli: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.bump-version.outputs.tag }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..9f256c703d --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,59 @@ +project_name: kubectl-flyte +before: + hooks: + - go mod download +builds: + - env: + - CGO_ENABLED=0 + main: ./cmd/kubectl-flyte/main.go + binary: kubectl-flyte + goos: + - linux + - windows + - darwin + ldflags: + - -s -w -X github.com/lyft/flytepropeller/version.Version={{.Version}} -X github.com/lyft/flytepropeller/version.Build={{.ShortCommit}} -X github.com/lyft/flytepropeller/version.BuildTime={{.Date}} +archives: + - replacements: + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +scoop: + # Default is "https://github.com///releases/download/{{ .Tag }}/{{ .ArtifactName }}" + # url_template: "http://github.mycompany.com/foo/bar/releases/{{ .Tag }}/{{ .ArtifactName }}" + + # Repository to push the app manifest to. + bucket: + owner: lyft + name: flytepropeller + + # Git author used to commit to the repository. + # Defaults are shown. + commit_author: + name: goreleaserbot + email: goreleaser@carlosbecker.com + + # Your app's homepage. + # Default is empty. + homepage: "https://godoc.org/github.com/lyft/flytepropeller" + + # Your app's description. + # Default is empty. + description: "kubectl-flyte is an command line tool that can be used as an extension to kubectl" + + # Your app's license + # Default is empty. + license: Apache-2.0 \ No newline at end of file diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000000..d311364d44 --- /dev/null +++ b/version/version.go @@ -0,0 +1,28 @@ +package version + +import ( + "time" + + "github.com/sirupsen/logrus" +) + +// This module provides the ability to inject Build (git sha) and Version information at compile time. +// To set these values invoke go build as follows +// go build -ldflags “-X github.com/lyft/flytepropeller/version.Build=xyz -X github.com/lyft/flytepropeller/version.Version=1.2.3" +// will provide the build and version information +var ( + // Specifies the GIT sha of the build + Build = "unknown" + // Version for the build, should follow a semver + Version = "unknown" + // Build timestamp + BuildTime = time.Now().String() +) + +// LogBuildInformation Use this method to log the build information for the current app. The app name should be provided. To inject the build +// and version information refer to the top-level comment in this file +func LogBuildInformation(appName string) { + logrus.Info("------------------------------------------------------------------------") + logrus.Infof("App [%s], Version [%s], BuildSHA [%s], BuildTS [%s]", appName, Version, Build, BuildTime) + logrus.Info("------------------------------------------------------------------------") +} diff --git a/version/version_test.go b/version/version_test.go new file mode 100644 index 0000000000..be7826ab76 --- /dev/null +++ b/version/version_test.go @@ -0,0 +1,29 @@ +package version + +import ( + "bytes" + "fmt" + "testing" + "time" + + "github.com/magiconair/properties/assert" + "github.com/sirupsen/logrus" +) + +type dFormat struct { +} + +func (dFormat) Format(e *logrus.Entry) ([]byte, error) { + return []byte(e.Message), nil +} + +func TestLogBuildInformation(t *testing.T) { + + n := time.Now() + BuildTime = n.String() + buf := bytes.NewBufferString("") + logrus.SetFormatter(dFormat{}) + logrus.SetOutput(buf) + LogBuildInformation("hello") + assert.Equal(t, buf.String(), fmt.Sprintf("------------------------------------------------------------------------App [hello], Version [unknown], BuildSHA [unknown], BuildTS [%s]------------------------------------------------------------------------", n.String())) +}