Skip to content

Commit

Permalink
use goreleaser to manage github release builds (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
derektamsen committed Apr 25, 2021
1 parent faf0efa commit 854d9d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
11 changes: 1 addition & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tmp
*-cloudimg-console.log
bin/
artifacts/
dist/
25 changes: 25 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:'
16 changes: 3 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -47,7 +37,7 @@ test:

clean:
$(GOCLEAN)
rm -r ./bin ./tmp ./artifacts
rm -r ./bin ./tmp ./artifacts ./dist

deps:
$(GOMOD) tidy
Expand Down
10 changes: 5 additions & 5 deletions cmd/luks2crypt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ 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
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{
{
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 854d9d7

Please sign in to comment.