build: uses goreleaser

This commit is contained in:
Marvin Preuss 2023-03-30 07:28:51 +00:00
parent dc00175f01
commit a134755fab
2 changed files with 58 additions and 3 deletions

39
.goreleaser.yaml Normal file
View File

@ -0,0 +1,39 @@
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
ldflags:
- -s
- -w
- -extldflags '-static'
- -X main.version={{.Version}}
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
goos:
- linux
- windows
- darwin
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

22
main.go
View File

@ -8,16 +8,32 @@ import (
"go.xsfx.dev/amseltools/internal/dirtoexcel"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
var rootCmd = &cobra.Command{}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints version info",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("amseltools %s, commit %s, build at %s", version, commit, date)
},
}
var dirToExcelCmd = &cobra.Command{
Use: "dir-to-excel [directory]",
Run: dirtoexcel.Run,
Args: cobra.ExactArgs(1),
Use: "dir-to-excel [directory]",
Short: "Takes a directory and creates an excel from it",
Run: dirtoexcel.Run,
Args: cobra.ExactArgs(1),
}
func main() {
rootCmd.AddCommand(dirToExcelCmd)
rootCmd.AddCommand(versionCmd)
// Flags.
dirToExcelCmd.Flags().StringP("out", "o", "", "output file")