diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..204368d --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,35 @@ +name: release + +on: + push: + tags: + - "v*.*" + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Configure git to use a PAT when cloning + run: | + git config --global url."https://api:${{ secrets.PAT }}@github.com/".insteadOf "https://github.com/" + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload assets + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/* diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..cd3a4b9 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,24 @@ +universal_binaries: + - replace: true +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + - freebsd + goarch: + - amd64 + - arm64 + ignore: + - goos: freebsd + goarch: arm64 + - goos: windows + goarch: arm64 + flags: + - -trimpath + ldflags: + - -s -w -X github.com/kong/deck/cmd.VERSION={{ .Tag }} -X github.com/kong/deck/cmd.COMMIT={{ .ShortCommit }} +snapshot: + name_template: "{{ .Tag }}" diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..7cbeeb2 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// VERSION is the current version of decK. +// This should be substituted by git tag during the build process. +var VERSION = "dev" + +// COMMIT is the short hash of the source tree. +// This should be substituted by Git commit hash during the build process. +var COMMIT = "unknown" + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the kceD version", + Long: `The version command prints the version of kceD along with a Git short +commit hash of the source tree.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("kceD %s (%s) \n", VERSION, COMMIT) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +}