Skip to content

Commit

Permalink
add gorleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
cage1016 committed May 24, 2023
1 parent 4679e84 commit dc70e16
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 2 deletions.
82 changes: 82 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- darwin
goarch:
- amd64
- arm
- arm64
goarm:
- "5"
- "6"
- "7"
ignore:
- goos: darwin
goarch: arm
- goos: darwin
goarch: ppc64le
- goos: darwin
goarch: s390x
- goos: windows
goarch: ppc64le
- goos: windows
goarch: s390x
- goos: windows
goarch: arm
goarm: "5"
- goos: windows
goarch: arm
goarm: "6"
- goos: windows
goarch: arm
goarm: "7"
- goos: windows
goarch: arm64
- goos: freebsd
goarch: ppc64le
- goos: freebsd
goarch: s390x
- goos: freebsd
goarch: arm
goarm: "5"
- goos: freebsd
goarch: arm
goarm: "6"
- goos: freebsd
goarch: arm
goarm: "7"
- goos: freebsd
goarch: arm64
flags:
- -trimpath
ldflags:
- -s -w
- -X github.com/cage1016/ak/cmd.Version={{.Version}}
- -X github.com/cage1016/ak/cmd.Commit={{.ShortCommit}}
binary: >-
{{ .ProjectName }}-
{{- if .IsSnapshot }}{{ .Branch }}-
{{- else }}{{- .Version }}-{{ end }}
{{- .Os }}-
{{- if eq .Arch "amd64" }}amd64
{{- else if eq .Arch "amd64_v1" }}amd64
{{- else if eq .Arch "386" }}386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}-{{ .Arm }}{{ end }}
no_unique_dist_dir: true

archives:
- format: binary
name_template: "{{ .Binary }}"
allow_different_binary_count: true

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}"
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
GO ?= go
EXECUTABLE := ak
GOFILES := $(shell find . -type f -name "*.go")
TAGS ?=
LDFLAGS ?= -X 'github.com/cage1016/ak/cmd.Version=$(VERSION)' -X 'github.com/cage1016/ak/cmd.Commit=$(COMMIT)'

ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
else
EXTLDFLAGS =
endif

ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
COMMIT ?= $(shell git rev-parse --short HEAD)

# Regenerates OPA data from rego files
HAVE_GO_BINDATA := $(shell command -v go-bindata 2> /dev/null)
generate: ## go generate
Expand All @@ -8,6 +27,9 @@ else
go generate ./...
endif

.PHONY: release
release: ## release
goreleaser release --skip-publish --rm-dist

.PHONY: help
help: ## this help
Expand Down
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 KAI CHU CHUNG <[email protected]>
*/
package cmd

Expand All @@ -22,7 +21,6 @@ var rootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Version: "0.3.0",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
24 changes: 24 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
Version string = ""
Commit string = ""
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("version:", Version, "commit:", Commit)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}

0 comments on commit dc70e16

Please sign in to comment.