From 3304da9dbe2cc5604ba91f9ede36c93edf86609c Mon Sep 17 00:00:00 2001 From: Alexei Yuzhakov Date: Fri, 11 Jun 2021 18:41:17 +0700 Subject: [PATCH] Switch to goreleaser for release purposes --- .gitignore | 4 +--- .goreleaser.yml | 27 +++++++++++++++++++++++++++ Makefile | 20 +++++++------------- VERSION | 1 - build/linux/.keep | 0 build/mac/.keep | 0 build/win/.keep | 0 cmd/version.go | 4 ++-- go.mod | 2 +- go.sum | 4 +++- main.go | 12 ++++++------ 11 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 VERSION delete mode 100644 build/linux/.keep delete mode 100644 build/mac/.keep delete mode 100644 build/win/.keep diff --git a/.gitignore b/.gitignore index 9d7dcc0..0034b11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .vscode /plesk /.plesk -/plesk.exe -/build/*/plesk* -/build/*.tgz \ No newline at end of file +/dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..2ca36aa --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,27 @@ +project_name: plesk +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} +archives: + - name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}" + replacements: + darwin: mac + linux: linux + windows: win + amd64: x86_64 + format: tgz + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}" diff --git a/Makefile b/Makefile index 3dc35fb..d1cdbd7 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ # Copyright 1999-2021. Plesk International GmbH. OUTFILE=plesk -REVISON:=$(shell git rev-parse --short HEAD) -VERSION:=$(shell cat VERSION) -BUILD_TIME=$(shell date +'%Y-%m-%d_%T') -LDFLAGS=-X main.revision=$(REVISON) -X main.buildTime=$(BUILD_TIME) -X main.version=$(VERSION) -RELEASE_LDFLAGS=$(LDFLAGS) -s -w +COMMIT:=$(shell git rev-parse --short HEAD) +VERSION:=$(shell git describe --abbrev=0 --tags) +DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') +LDFLAGS=-X main.commit=$(COMMIT) -X main.date=$(DATE) -X main.version=$(VERSION) .PHONY: all build clean test @@ -13,20 +12,15 @@ build: test go build -ldflags "$(LDFLAGS)" release: test - GOOS=linux go build -ldflags "$(RELEASE_LDFLAGS)" -o ./build/linux/$(OUTFILE) - tar czf ./build/$(OUTFILE)-v$(VERSION)-linux.tgz --directory=build/linux $(OUTFILE) - GOOS=darwin go build -ldflags "$(RELEASE_LDFLAGS)" -o ./build/mac/$(OUTFILE) - tar czf ./build/$(OUTFILE)-v$(VERSION)-mac.tgz --directory=build/mac $(OUTFILE) - GOOS=windows go build -ldflags "$(RELEASE_LDFLAGS)" -o ./build/win/$(OUTFILE).exe - tar czf ./build/$(OUTFILE)-v$(VERSION)-win.tgz --directory=build/win $(OUTFILE).exe + goreleaser release run: go run main.go clean: - $(RM) $(OUTFILE) ./build/*/$(OUTFILE) ./build/*.tgz + $(RM) $(OUTFILE) test: go test -v -cover ./... -all: clean release build \ No newline at end of file +all: clean release build diff --git a/VERSION b/VERSION deleted file mode 100644 index bcab45a..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.0.3 diff --git a/build/linux/.keep b/build/linux/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/build/mac/.keep b/build/mac/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/build/win/.keep b/build/win/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/cmd/version.go b/cmd/version.go index 0c88d00..6328070 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -12,7 +12,7 @@ import ( // Version information var ( - Revision string + Commit string BuildTime string Version string ) @@ -22,7 +22,7 @@ var versionCmd = &cobra.Command{ Short: locales.L.Get("version.description"), RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("Client information") - fmt.Printf("Version:\t%s\nRevision:\t%s\nBuild time:\t%s\n", Version, Revision, BuildTime) + fmt.Printf("Version:\t%s\nRevision:\t%s\nBuild time:\t%s\n", Version, Commit, BuildTime) defaultServerName, err := config.DefaultServer() if err == nil { diff --git a/go.mod b/go.mod index 375ebd6..f1c89a0 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/jlaffaye/ftp v0.0.0-20210307004419-5d4190119067 github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 github.com/spf13/cobra v1.1.3 - github.com/stretchr/testify v1.7.0 // indirect + github.com/stretchr/testify v1.7.0 golang.org/x/net v0.0.0-20210505214959-0714010a04ed // indirect golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 // indirect golang.org/x/term v0.0.0-20210503060354-a79de5458b56 diff --git a/go.sum b/go.sum index 1de1118..cd38454 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,10 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -166,7 +168,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -296,6 +297,7 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/main.go b/main.go index fcad464..16b0283 100644 --- a/main.go +++ b/main.go @@ -12,15 +12,15 @@ import ( ) var ( - revision string - buildTime string - version string + commit string + date string + version string ) func init() { - cmd.Revision = revision - cmd.BuildTime = buildTime - cmd.Version = version + cmd.Commit = commit + cmd.BuildTime = date + cmd.Version = version[1:] } func main() {