Skip to content

Commit

Permalink
Fix and refactor Makefile and .goreleaser build commands.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
knadh committed Oct 18, 2020
1 parent 2e361c7 commit cfe66bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
40 changes: 26 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cfe66bb

Please sign in to comment.