diff --git a/.gitignore b/.gitignore index be4c37e..ae10096 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,6 @@ Temporary Items .apdisk # End of https://www.gitignore.io/api/go,linux,macos + bin +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..0f24772 --- /dev/null +++ b/.goreleaser.yaml @@ -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 diff --git a/Makefile b/Makefile index 52b283b..a31e4c6 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 #