Skip to content

Commit

Permalink
build: Add goreleaser
Browse files Browse the repository at this point in the history
Automates binary builds for multiple platforms. More info on this tool
is at https://goreleaser.com.

There is also a Github action for GoReleaser. I might add it later.

The config file may also set env vars, but it doesn't meet my needs for
setting up LDFLAGS, so I'm keeping that in the Makefile. For
consistency's sake, the other env vars are also in the Makefile.
  • Loading branch information
rafaelespinoza committed Jul 11, 2024
1 parent ac48d69 commit 8712d12
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ Temporary Items
.apdisk

# End of https://www.gitignore.io/api/go,linux,macos

bin
dist/
100 changes: 100 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
project_name: godfish

version: 2

# env vars are put together with the Makefile.
#
# For each build item (https://goreleaser.com/customization/builds/), it'd be
# nice if we could set the common values for "ldflags" somewhere, such as this
# env section, and then tack on any driver-specific values, such as
# .versionDriver, for each driver. As of goreleaser v2.0.1, it does not look
# possible to access common Name Template values (https://goreleaser.com/customization/templates)
# from this env section. An alternative approach would be to set the ldflags
# value for each build item, which can access both Name Template, and
# Environment variable values. Example:
#
# ldflags:
# ->
# -X {{ .ModulePath }}/internal/cmd.versionBranchName={{ .Branch }}
# -X {{ .ModulePath }}/internal/cmd.versionBuildTime={{ .CommitDate }}
# -X {{ .ModulePath }}/internal/cmd.versionCommitHash={{ .ShortCommit }}
# -X {{ .ModulePath }}/internal/cmd.versionGoVersion={{ .Env.GOVERSION }}
# -X {{ .ModulePath }}/internal/cmd.versionTag={{ .Tag }}
# -X {{ .ModulePath }}/internal/cmd.versionDriver=name_of_driver_here
#
# But I'd prefer to not repeat that same structure for each driver to build at
# this time.
env:

builds:
-
id: cassandra
dir: ./drivers/cassandra/godfish
binary: ./godfish_cassandra
goarch:
- amd64
- arm64
goos:
- darwin
- linux
- windows
ldflags:
- >
{{ .Env.LDFLAGS }} -X {{ .Env.PKG_IMPORT_PATH }}/internal/cmd.versionDriver=cassandra
-
id: mysql
dir: ./drivers/mysql/godfish
binary: ./godfish_mysql
goarch:
- amd64
- arm64
goos:
- darwin
- linux
- windows
ldflags:
- >
{{ .Env.LDFLAGS }} -X {{ .Env.PKG_IMPORT_PATH }}/internal/cmd.versionDriver=mysql
-
id: postgres
dir: ./drivers/postgres/godfish
binary: ./godfish_postgres
goarch:
- amd64
- arm64
goos:
- darwin
- linux
- windows
ldflags:
- >
{{ .Env.LDFLAGS }} -X {{ .Env.PKG_IMPORT_PATH }}/internal/cmd.versionDriver=postgres
-
id: sqlite3
dir: ./drivers/sqlite3/godfish
binary: ./godfish_sqlite3
goarch:
- amd64
- arm64
goos:
- darwin
- linux
- windows
ldflags:
- >
{{ .Env.LDFLAGS }} -X {{ .Env.PKG_IMPORT_PATH }}/internal/cmd.versionDriver=sqlite3
-
id: sqlserver
dir: ./drivers/sqlserver/godfish
binary: ./godfish_sqlserver
goarch:
- amd64
- arm64
goos:
- darwin
- linux
- windows
ldflags:
- >
{{ .Env.LDFLAGS }} -X {{ .Env.PKG_IMPORT_PATH }}/internal/cmd.versionDriver=sqlserver
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ POSTGRES_PATH=$(PKG_IMPORT_PATH)/drivers/postgres
SQLITE3_PATH=$(PKG_IMPORT_PATH)/drivers/sqlite3

# inject this metadata when building a binary.
GO_VERSION := $(shell $(GO) version | awk '{ print $$3 }')
define LDFLAGS
-X $(PKG_IMPORT_PATH)/internal/cmd.versionBranchName=$(shell git rev-parse --abbrev-ref HEAD) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionBuildTime=$(shell date --utc +%FT%T%z) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionCommitHash=$(shell git rev-parse --short=7 HEAD) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionGoVersion=$(shell $(GO) version | awk '{ print $$3 }') \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionGoVersion=$(GO_VERSION) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionTag=$(shell git describe --tag)
endef

Expand All @@ -42,6 +43,17 @@ _mkdir:
gosec:
$(GOSEC) $(ARGS) . ./internal/... ./drivers/...

# Automates binary building on many platforms. This Makefile won't install the
# tool for you. Read more at https://goreleaser.com.
#
# This target is set up to keep effects local by default, via the --snapshot
# flag. Use the Makefile variable, ARGS, to override that:
# $ make release ARGS='--snapshot=false'
GORELEASER ?= goreleaser
release:
GOVERSION=$(GO_VERSION) PKG_IMPORT_PATH=$(PKG_IMPORT_PATH) LDFLAGS='$(LDFLAGS)' \
$(GORELEASER) release --clean --snapshot $(ARGS)

#
# Cassandra
#
Expand Down

0 comments on commit 8712d12

Please sign in to comment.