Skip to content
This repository has been archived by the owner on Jun 20, 2020. It is now read-only.

Commit

Permalink
Update build (#38)
Browse files Browse the repository at this point in the history
* Use goreleaser
* Fix version embedding for Go modules.

Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
SuperQ authored and josephlewis42 committed Jan 28, 2020
1 parent e16881b commit 7573cb1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pubsubbeat.test
build/
data/
logs/
dist/
dashboards/

# IntelliJ IDEA
.idea/
Expand Down
32 changes: 32 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
- make clean
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
hooks:
post: make dashboards
checksum:
name_template: 'checksums.txt'
project_name: pubsubbeat
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
archives:
- wrap_in_directory: true
files:
- README.md
- NOTICE
- LICENSE
- fields.yml
- pubsubbeat.yml
- pubsubbeat.reference.yml
- dashboards/**/*
33 changes: 11 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
BEAT_NAME=pubsubbeat
BUILD_DIR=bin
BEAT_PATH=github.com/GoogleCloudPlatform/pubsubbeat
GOBUILD_FLAGS=-ldflags "-X $(BEAT_PATH)/vendor/github.com/elastic/beats/libbeat/version.buildTime=$(NOW) -X $(BEAT_PATH)/vendor/github.com/elastic/beats/libbeat/version.commit=$(COMMIT_ID)"
EXES=linux windows darwin
RELEASE_TEMPLATE_DIR=${BUILD_DIR}/releases/template

NOW ?= $(shell date --iso-8601=seconds)
COMMIT_ID ?= $(shell git rev-parse HEAD)
VERSION_LDFLAGS := \
-X github.com/elastic/beats/libbeat/version.buildTime=$(NOW) \
-X github.com/elastic/beats/libbeat/version.commit=$(COMMIT_ID)
GOBUILD_FLAGS=-ldflags "$(VERSION_LDFLAGS)"

.PHONY: build
build:
Expand Down Expand Up @@ -34,23 +38,8 @@ update:
@echo "TODO: update deps"

.PHONY: release
release: $(EXES)

$(EXES): release-template
@echo "Generating release: " $@

mkdir -p ${BUILD_DIR}/releases/$@
cp -r ${RELEASE_TEMPLATE_DIR}/. ${BUILD_DIR}/releases/$@

GOOS=$@ GOARCH=amd64 go build -o ${BUILD_DIR}/releases/$@/${BEAT_NAME} ${GOBUILD_FLAGS}

tar -zcvf ${BUILD_DIR}/releases/[email protected] -C ${BUILD_DIR}/releases $@

.PHONY: release-template
release-template:
mkdir -p ${RELEASE_TEMPLATE_DIR}

cp {${BEAT_NAME}.yml,${BEAT_NAME}.reference.yml} ${RELEASE_TEMPLATE_DIR}
cp {README.md,NOTICE,LICENSE,fields.yml} ${RELEASE_TEMPLATE_DIR}
release: dashboards
goreleaser --snapshot --skip-publish --rm-dist

cp -r _meta/kibana ${RELEASE_TEMPLATE_DIR}/dashboards
dashboards:
cp -r _meta/kibana dashboards
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
github.com/go-sourcemap/sourcemap v2.1.2+incompatible // indirect
github.com/gofrs/uuid v3.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.4.0 // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/gorilla/mux v1.7.3 // indirect
Expand Down

0 comments on commit 7573cb1

Please sign in to comment.