Skip to content

Commit

Permalink
Using goreleaser to build binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Larson authored and Eric Larson committed Nov 27, 2023
1 parent 1e4f6d6 commit 8b4d38e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
53 changes: 53 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

version: 1

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
goos:
- linux
- windows
- darwin
ignore:
- goos: windows
goarch: 386

main: ./cmd/we

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

release:
github:
owner: ionrock
name: we

prerelease: auto

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
59 changes: 3 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,59 +41,6 @@ $(BINDIR):
mkdir -p build


### Release / deploy targets
GH_RELEASE=$(GOPATH)/bin/github-release
UPLOAD_CMD = ./we -e .release.yml $(GH_RELEASE) upload -t $(LAST_TAG) -n $(subst /,-,$(FILE)) -f $(FILE)

OSLIST = darwin freebsd linux
PLATS = amd64

EXE_TMPL = bin/$(OS)-$(PLAT)-$(EXECUTABLE)
EXE_TMPL_BZ2 = $(FN).tar.bz2

UNIX_EXECUTABLES = $(foreach OS,$(OSLIST),$(foreach PLAT,$(PLATS),$(EXE_TMPL)))
WIN_EXECUTABLES = bin/windows-amd64-$(EXECUTABLE).exe

COMPRESSED_EXECUTABLES = $(UNIX_EXECUTABLES:%=%.tar.bz2) $(WIN_EXECUTABLES).zip
COMPRESSED_EXECUTABLE_TARGETS = $(COMPRESSED_EXECUTABLES:%=%)

all: $(UNIX_EXECUTABLES) $(WIN_EXECUTABLES)

compress-all: $(COMPRESSED_EXECUTABLES)

# compressed artifacts, makes a huge difference (Go executable is ~9MB,
# after compressing ~2MB)
%.tar.bz2: %
tar -jcvf "$<.tar.bz2" "$<"
%.exe.zip: %.exe
zip "$@" "$<"

# amd64
bin/freebsd-amd64-$(EXECUTABLE): $(GLIDE) $(SOURCES)
GOARCH=amd64 GOOS=freebsd go build $(LDFLAGS) -o "$@" $(WEPKG)
bin/darwin-amd64-$(EXECUTABLE): $(GLIDE) $(SOURCES)
GOARCH=amd64 GOOS=darwin go build $(LDFLAGS) -o "$@" $(WEPKG)
bin/linux-amd64-$(EXECUTABLE): $(GLIDE) $(SOURCES)
GOARCH=amd64 GOOS=linux go build $(LDFLAGS) -o "$@" $(WEPKG)

bin/windows-amd64-$(EXECUTABLE).exe: $(GLIDE) $(SOURCES)
GOARCH=amd64 GOOS=windows go build $(LDFLAGS) -o "$@" $(WEPKG)


$(GH_RELEASE):
go get github.com/aktau/github-release
go install github.com/aktau/github-release

release: $(GH_RELEASE) $(EXECUTABLE) $(COMPRESSED_EXECUTABLES)
@echo "All targets $(COMPRESSED_EXECUTABLES)"
./we -e .release.yml $(GH_RELEASE) release -t $(LAST_TAG) -n $(LAST_TAG) || true
$(foreach FILE,$(COMPRESSED_EXECUTABLES),$(UPLOAD_CMD);)

$(BUMP):
virtualenv $(VENV)
$(VENV)/bin/pip install --upgrade pip
$(VENV)/bin/pip install bumpversion

bump: $(BUMP)
$(VENV)/bin/bumpversion $(BUMPTYPE)
git push && git push --tags
.PHONY: goreleaser
goreleaser:
go install github.com/goreleaser/goreleaser@latest

0 comments on commit 8b4d38e

Please sign in to comment.