.goreleaser.yml: use make in GoReleaser
Teach GoReleaser to use make for our nightly releases.
Untested--we'll know better tomorrow whether this works.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s4d8aed2fbf3aae3fk
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 58f5bb6..352d675 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -4,26 +4,32 @@
# Build configuration
before:
hooks:
- - "npm ci --prefix webui"
- - "npm run build --prefix webui"
+ - make clean
builds:
- id: sketch
+ # Note: this build corresponds to 'make outie'; please keep them in sync.
main: ./cmd/sketch
- env:
- - CGO_ENABLED=0
+ binary: sketch
goos:
- linux
- darwin
goarch:
- amd64
- arm64
+ tags:
+ - outie
ldflags:
- - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
+ - -X main.version={{.Version}}
+ - -X main.commit={{.Commit}}
+ - -X main.date={{.Date}}
+ - -X main.makefile=goreleaser
+ hooks:
+ pre:
+ - ./.goreleaser/build-target.sh
archives:
- id: releaseArchive
- format: tar.gz
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- README.md
diff --git a/.goreleaser/build-target.sh b/.goreleaser/build-target.sh
new file mode 100755
index 0000000..37a64dc
--- /dev/null
+++ b/.goreleaser/build-target.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+set -e
+
+# This script is called by GoReleaser for each target
+# GOOS and GOARCH are set by GoReleaser
+# We prepare the embedded assets, then let GoReleaser do the final go build
+
+echo "Preparing embedded assets for GOOS=$GOOS GOARCH=$GOARCH"
+
+# Build webui assets (only once)
+if [ ! -d "embedded/webui-dist" ]; then
+ echo "Building webui assets..."
+ make webui-assets
+fi
+
+# Build innie binaries (only once)
+if [ ! -f "embedded/sketch-linux/sketch-linux-amd64" ] || [ ! -f "embedded/sketch-linux/sketch-linux-arm64" ]; then
+ echo "Building innie binaries..."
+ make innie
+fi
+
+echo "Assets prepared. GoReleaser will now build the outie binary."
diff --git a/Makefile b/Makefile
index 69192e6..088cbf0 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,10 @@
VERSION := $(shell git describe --tags --dirty --always 2>/dev/null || echo "dev")
LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(BUILD_TIME) -X main.makefile=true
+# Support for cross-compilation, used by GoReleaser
+GOOS ?= $(shell go env GOOS)
+GOARCH ?= $(shell go env GOARCH)
+
.PHONY: all clean help
.PHONY: outie innie
.PHONY: webui-assets
@@ -16,7 +20,8 @@
all: outie
outie: innie
- go build -ldflags="$(LDFLAGS)" -tags=outie -o sketch ./cmd/sketch
+ # Note: This incantation is duplicated in .goreleaser.yml; please keep them in sync.
+ GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="$(LDFLAGS)" -tags=outie -o sketch ./cmd/sketch
innie: webui-assets
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -tags=innie -o embedded/sketch-linux/sketch-linux-amd64 ./cmd/sketch
@@ -24,7 +29,7 @@
webui-assets:
rm -rf embedded/webui-dist
- go run ./cmd/genwebui -- embedded/webui-dist
+ unset GOOS GOARCH && go run ./cmd/genwebui -- embedded/webui-dist
clean:
@echo "Cleaning build artifacts..."