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

View File

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