Fix and refactor Makefile and .goreleaser build commands.

The earlier goreleaser implementation was incorrect where every
build would trigger `make pack-release` with the list of all
cross-platform releases. Fix that to atomically run the packing
once per goreleaser build. In addition, add `make release-dry`
and `make release` for goreleaser.
This commit is contained in:
Kailash Nadh 2020-10-18 22:44:21 +05:30
parent 2e361c7371
commit cfe66bb29d
2 changed files with 27 additions and 16 deletions

View File

@ -1,7 +1,6 @@
env:
- GO111MODULE=on
- CGO_ENABLED=0
- RELEASE_BUILDS=dist/listmonk_darwin_amd64/listmonk dist/listmonk_linux_amd64/listmonk dist/listmonk_windows_amd64/listmonk.exe
before:
hooks:
@ -21,7 +20,7 @@ builds:
hooks:
# stuff executables with static assets.
post: make pack-releases
post: make pack-bin bin={{ .Path }}
archives:
- format: tar.gz

View File

@ -11,43 +11,55 @@ STATIC := config.toml.sample \
frontend/dist/favicon.png:/frontend/favicon.png \
frontend/dist/frontend:/frontend
# Dependencies.
# Install dependencies for building.
.PHONY: deps
deps:
go get -u github.com/knadh/stuffbin/...
cd frontend && yarn install
# Build steps.
# Build the backend to ./listmonk.
.PHONY: build
build:
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/*.go
.PHONY: build-frontend
build-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn build
# Run the backend.
.PHONY: run
run: build
./${BIN}
# Build the JS frontend into frontend/dist.
.PHONY: build-frontend
build-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn build
# Run the JS frontend server in dev mode.
.PHONY: run-frontend
run-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn serve
# Run Go tests.
.PHONY: test
test:
go test ./...
# dist builds the backend, frontend, and uses stuffbin to
# embed all frontend assets into the binary.
# Bundle all static assets including the JS frontend into the ./listmonk binary
# using stuffbin (installed with make deps).
.PHONY: dist
dist: build build-frontend
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
# pack-releases runns stuffbin packing on a given list of
# binaries. This is used with goreleaser for packing
# release builds for cross-build targets.
.PHONY: pack-releases
pack-releases:
$(foreach var,$(RELEASE_BUILDS),stuffbin -a stuff -in ${var} -out ${var} ${STATIC};)
# pack-releases runns stuffbin packing on the given binary. This is used
# in the .goreleaser post-build hook.
.PHONY: pack-bin
pack-bin:
stuffbin -a stuff -in $(bin) -out $(bin) ${STATIC}
# Use goreleaser to do a dry run producing local builds.
.PHONY: release-dry
release-dry:
goreleaser --parallelism 1 --rm-dist --snapshot --skip-validate --skip-publish
# Use goreleaser to build production releases and publish them.
.PHONY: release
release:
goreleaser --parallelism 1 --rm-dist --skip-validate