From fc45fdc6a3e9a5c2b80ce45ece5f77e4e888d70f Mon Sep 17 00:00:00 2001 From: Derek Tamsen Date: Sun, 25 Apr 2021 15:22:08 -0700 Subject: [PATCH] use goreleaser to manage github release builds --- .circleci/config.yml | 11 +---------- .gitignore | 1 + .goreleaser.yml | 25 +++++++++++++++++++++++++ Makefile | 16 +++------------- cmd/luks2crypt/main.go | 10 +++++----- 5 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index bb81b4a..e905753 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ only-deploy-tags: &only-deploy-tags branches: ignore: /.*/ tags: - only: /^v\d+\.\d+\.\d+$/ + only: /v[0-9]+(\.[0-9]+)*(-.*)*/ version: 2.1 executors: @@ -33,19 +33,10 @@ jobs: steps: - setup-image - run: make build - - run: make deploytar - - persist_to_workspace: - root: . - paths: - - artifacts - - store_artifacts: - path: artifacts publish-github-release: executor: golang steps: - checkout - - attach_workspace: - at: . - run: make deploy workflows: diff --git a/.gitignore b/.gitignore index 8762a71..d3b29c0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ tmp *-cloudimg-console.log bin/ artifacts/ +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..a273cc6 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,25 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=1 + main: ./cmd/luks2crypt + goos: + - linux + goarch: + - amd64 +archives: + - replacements: + linux: Linux + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Makefile b/Makefile index cdd657d..8c4e004 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,5 @@ VERSION := $(shell git describe --tags) -OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') -ARCH := $(shell dpkg --print-architecture) - -GITTAG := $(shell git describe --tags) - BINPATH := ./bin GOCMD := go @@ -28,14 +23,9 @@ install: build: $(GOBUILD) $(LDFLAGS) -o $(BINPATH)/$(BINARY_NAME) -v ./cmd/$(BINARY_NAME) -deploytar: - mkdir -p tmp/$(BINARY_NAME) artifacts - cp bin/$(BINARY_NAME) README.md COPYING LICENSE.txt tmp/$(BINARY_NAME)/ - tar -C tmp -czvf artifacts/$(BINARY_NAME)-$(GITTAG)-$(OS)-$(ARCH).tar.gz $(BINARY_NAME) - deploy: - GO111MODULE=off go get github.com/tcnksm/ghr - ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./artifacts/ + go get github.com/goreleaser/goreleaser@latest + goreleaser release lint: GO111MODULE=off go get -u golang.org/x/lint/golint @@ -47,7 +37,7 @@ test: clean: $(GOCLEAN) - rm -r ./bin ./tmp ./artifacts + rm -r ./bin ./tmp ./artifacts ./dist deps: $(GOMOD) tidy diff --git a/cmd/luks2crypt/main.go b/cmd/luks2crypt/main.go index 3fb5613..25a0966 100644 --- a/cmd/luks2crypt/main.go +++ b/cmd/luks2crypt/main.go @@ -18,9 +18,9 @@ import ( ) var ( - // VERSION set during build - // go build -ldflags "-X main.VERSION=1.2.3" - VERSION = "0.0.1" + // version set during build + // go build -ldflags "-X main.version=1.2.3" + version = "0.0.1" ) // run setups up cli arg handling and executes luks2crypt @@ -28,7 +28,7 @@ func run(args []string) error { app := cli.NewApp() app.Name = "luks2crypt" app.Usage = "Generates a random luks password, escrows it, and rotates slot 0 on root." - app.Version = VERSION + app.Version = version app.Commands = []cli.Command{ { @@ -66,7 +66,7 @@ func run(args []string) error { // optVersion returns the application version. Typically, this is the git sha func optVersion(c *cli.Context) error { - fmt.Println(VERSION) + fmt.Println(version) return nil }