Skip to content

Commit

Permalink
Use goreleaser for v1
Browse files Browse the repository at this point in the history
  • Loading branch information
9seconds committed Mar 21, 2022
1 parent 18a5234 commit a587f85
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*.out
mtg
vendor/
ccbuilds/
.bin/
dist/
65 changes: 65 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---

project_name: mtg

before:
hooks:
- go mod tidy
- go generate ./...

builds:
- binary: '{{ .ProjectName }}'
goos:
- darwin
- freebsd
- linux
- netbsd
- openbsd
goarch:
- 386
- amd64
- arm
- arm64
goarm:
- 6
- 7
env:
- CGO_ENABLED=0
flags:
- -trimpath
- -mod=readonly
ldflags: -s -w -X main.version={{ .Version }}
ignore:
- goos: darwin
goarch: 386
- goos: freebsd
goarch: arm64
- goos: netbsd
goarch: arm64
- goos: openbsd
goarch: arm64

archives:
- name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md
- SECURITY.md

gomod:
proxy: true

snapshot:
name_template: '{{ .Version }}'

checksum:
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'

source:
enabled: true
name_template: '{{ .ProjectName }}-sources'
31 changes: 12 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
IMAGE_NAME := mtg
APP_NAME := $(IMAGE_NAME)

CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")

GOLANGCI_LINT_VERSION := v1.45.0

VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru)
VERSION_TAG := $(shell git describe --tags --always)
COMMON_BUILD_FLAGS := -mod=readonly -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"

GOBIN := $(ROOT_DIR)/.bin
GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
Expand All @@ -29,18 +27,6 @@ $(APP_NAME): build
static:
@env CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"

$(APP_NAME)-%: GOOS=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f1 -d-)
$(APP_NAME)-%: GOARCH=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f2 -d-)
$(APP_NAME)-%: ccbuilds
@env "GOOS=$(GOOS)" "GOARCH=$(GOARCH)" \
go build \
$(COMMON_BUILD_FLAGS) \
-o "./ccbuilds/$(APP_NAME)-$(GOOS)-$(GOARCH)"

.PHONY: ccbuilds
ccbuilds:
@rm -rf ./ccbuilds && mkdir -p ./ccbuilds

vendor: go.mod go.sum
@$(MOD_ON) go mod vendor

Expand All @@ -52,9 +38,6 @@ test:
citest:
@go test -coverprofile=coverage.txt -covermode=atomic -race -v ./...

.PHONY: crosscompile
crosscompile: $(CC_BINARIES)

.PHONY: clean
clean:
@git clean -xfd && \
Expand All @@ -77,8 +60,14 @@ doc:
fmt:
@$(GOTOOL) gofumpt -w -extra "$(ROOT_DIR)"

.PHONY: release
release:
@$(GOTOOL) goreleaser release --snapshot --rm-dist && \
find "$(ROOT_DIR)/dist" -type d | grep -vP "dist$$" | xargs -r rm -rf && \
rm -f "$(ROOT_DIR)/dist/config.yaml"

.PHONY: install-tools
install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt
install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt install-tools-goreleaser

.PHONY: install-tools-lint
install-tools-lint:
Expand All @@ -95,6 +84,10 @@ install-tools-godoc:
install-tools-gofumpt: .bin
@$(GOTOOL) go install mvdan.cc/gofumpt@latest

.PHONY: goreleaser
install-tools-goreleaser: .bin
@$(GOTOOL) go install github.com/goreleaser/goreleaser@latest

.PHONY: update-deps
update-deps:
@go get -u && go mod tidy -go=1.18

0 comments on commit a587f85

Please sign in to comment.