-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
45 lines (39 loc) · 1.41 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
BINARY=trams
LDFLAGS="-s -w -X main.version=${VERSION}"
PREVIOUSTAG:=$(shell git describe --tags --abbrev=0)
PREVIOUSTAGDATE:=$(shell git log -1 --format=%as $(PREVIOUSTAG))
TMPCHANGES=/tmp/changes.tmp
TODAYDATE:=$(shell date +'%Y-%m-%d')
VERSION=$(shell git describe --tags --long)
build: binaries
test: clean
go test ./...
binaries: test
@mkdir -p dist/linux dist/darwin dist/windows
GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o dist/linux/$(BINARY) ./cmd/trams
GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o dist/darwin/$(BINARY) ./cmd/trams
GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -o dist/windows/$(BINARY).exe ./cmd/trams
changelog: clean
@echo Previous tag = $(PREVIOUSTAG)
@echo Previous tag date = $(PREVIOUSTAGDATE)
@echo "# Changelog" > $(TMPCHANGES)
@echo "" >> $(TMPCHANGES)
@echo "## $(NEWTAG) ($(TODAYDATE))" >> $(TMPCHANGES)
@git log $(PREVIOUSTAG)..HEAD --pretty=format:"%h %s" | grep -v 'build:' | grep -v 'Release v' >> $(TMPCHANGES)
@echo "" >> $(TMPCHANGES)
@touch CHANGELOG.md
@sed '/# Changelog/d' CHANGELOG.md >> $(TMPCHANGES)
@mv $(TMPCHANGES) CHANGELOG.md
release: changelog
ifndef NEWTAG
$(error Please set NEWTAG value first, e.g make release NEWTAG=v0.1.)
endif
@git add CHANGELOG.md
@git commit -m "Release $(NEWTAG) ($(TODAYDATE))"
@git tag $(NEWTAG)
@git push
@git push --tags
clean:
@rm -rf $(TMPCHANGES)
@rm -rf dist
@go clean -testcache