Skip to content

Commit 5f98f96

Browse files
committed
make: add build and release commands
1 parent 43f5ff1 commit 5f98f96

File tree

4 files changed

+328
-1
lines changed

4 files changed

+328
-1
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ https.cert
33
https.key
44

55
# local environment vars to ignore
6-
.env*.local
6+
.env*.local
7+
8+
shushtar-debug
9+
/shushtar-*
10+
11+
# go code generated by statik
12+
/statik/statik.go

Makefile

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
PKG := github.com/lightninglabs/shushtar
2+
ESCPKG := github.com\/lightninglabs\/shushtar
3+
LND_PKG := github.com/lightningnetwork/lnd
4+
5+
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
6+
GOVERALLS_PKG := github.com/mattn/goveralls
7+
GOACC_PKG := github.com/ory/go-acc
8+
STATIK_PKG := github.com/rakyll/statik
9+
10+
GO_BIN := ${GOPATH}/bin
11+
GOVERALLS_BIN := $(GO_BIN)/goveralls
12+
LINT_BIN := $(GO_BIN)/golangci-lint
13+
GOACC_BIN := $(GO_BIN)/go-acc
14+
STATIK_BIN := $(GO_BIN)/statik
15+
16+
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
17+
18+
LINT_COMMIT := v1.18.0
19+
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
20+
21+
DEPGET := cd /tmp && GO111MODULE=on go get -v
22+
GOBUILD := GO111MODULE=on go build -v
23+
GOINSTALL := GO111MODULE=on go install -v
24+
GOTEST := GO111MODULE=on go test -v
25+
GOMOD := GO111MODULE=on go mod
26+
27+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
28+
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
29+
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
30+
31+
RM := rm -f
32+
CP := cp
33+
MAKE := make
34+
XARGS := xargs -L 1
35+
36+
LINT = $(LINT_BIN) run -v
37+
38+
include make/release_flags.mk
39+
40+
# We only return the part inside the double quote here to avoid escape issues
41+
# when calling the external release script. The second parameter can be used to
42+
# add additional ldflags if needed (currently only used for the release).
43+
make_ldflags = $(2) -X $(LND_PKG)/build.Commit=$(COMMIT) \
44+
-X $(LND_PKG)/build.CommitHash=$(COMMIT_HASH) \
45+
-X $(LND_PKG)/build.GoVersion=$(GOVERSION) \
46+
-X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g')
47+
48+
LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS))
49+
50+
# For the release, we want to remove the symbol table and debug information (-s)
51+
# and omit the DWARF symbol table (-w). Also we clear the build ID.
52+
RELEASE_LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS), -s -w -buildid=)
53+
54+
GREEN := "\\033[0;32m"
55+
NC := "\\033[0m"
56+
define print
57+
echo $(GREEN)$1$(NC)
58+
endef
59+
60+
default: scratch
61+
62+
all: scratch check install
63+
64+
# ============
65+
# DEPENDENCIES
66+
# ============
67+
68+
$(GOVERALLS_BIN):
69+
@$(call print, "Fetching goveralls.")
70+
go get -u $(GOVERALLS_PKG)
71+
72+
$(LINT_BIN):
73+
@$(call print, "Fetching linter")
74+
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
75+
76+
$(GOACC_BIN):
77+
@$(call print, "Fetching go-acc")
78+
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
79+
80+
$(STATIK_BIN):
81+
@$(call print, "Fetching statik")
82+
$(DEPGET) $(STATIK_PKG)
83+
84+
yarn-install:
85+
@$(call print, "Installing app dependencies with yarn")
86+
cd app; yarn
87+
88+
# ============
89+
# INSTALLATION
90+
# ============
91+
statik-build: $(STATIK_BIN) app-build
92+
@$(call print, "Building statik package.")
93+
statik -src=app/build
94+
95+
build: statik-build go-build
96+
install: statik-build go-install
97+
98+
go-build:
99+
@$(call print, "Building shushtar.")
100+
$(GOBUILD) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" -o shushtar-debug $(PKG)/cmd/shushtar
101+
102+
go-install:
103+
@$(call print, "Installing shushtar.")
104+
$(GOINSTALL) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" $(PKG)/cmd/shushtar
105+
106+
app-build: yarn-install
107+
@$(call print, "Building production app.")
108+
cd app; yarn build
109+
110+
release: statik-build
111+
@$(call print, "Creating release of shushtar.")
112+
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
113+
114+
scratch: build
115+
116+
# =======
117+
# TESTING
118+
# =======
119+
120+
check: unit
121+
122+
unit:
123+
@$(call print, "Running unit tests.")
124+
$(UNIT)
125+
126+
unit-cover: $(GOACC_BIN)
127+
@$(call print, "Running unit coverage tests.")
128+
$(GOACC_BIN) $(COVER_PKG)
129+
130+
unit-race:
131+
@$(call print, "Running unit race tests.")
132+
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
133+
134+
goveralls: $(GOVERALLS_BIN)
135+
@$(call print, "Sending coverage report.")
136+
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
137+
138+
travis-race: lint unit-race
139+
140+
travis-cover: lint unit-cover goveralls
141+
142+
travis-itest: lint
143+
144+
145+
# =============
146+
# FLAKE HUNTING
147+
# =============
148+
flake-unit:
149+
@$(call print, "Flake hunting unit tests.")
150+
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
151+
152+
# =========
153+
# UTILITIES
154+
# =========
155+
fmt:
156+
@$(call print, "Formatting source.")
157+
gofmt -l -w -s $(GOFILES_NOVENDOR)
158+
159+
lint: $(LINT_BIN)
160+
@$(call print, "Linting source.")
161+
$(LINT)
162+
163+
mod:
164+
@$(call print, "Tidying modules.")
165+
$(GOMOD) tidy
166+
167+
mod-check:
168+
@$(call print, "Checking modules.")
169+
$(GOMOD) tidy
170+
if test -n "$$(git status | grep -e "go.mod\|go.sum")"; then echo "Running go mod tidy changes go.mod/go.sum"; git status; git diff; exit 1; fi
171+
172+
list:
173+
@$(call print, "Listing commands.")
174+
@$(MAKE) -qp | \
175+
awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \
176+
grep -v Makefile | \
177+
sort
178+
179+
clean:
180+
@$(call print, "Cleaning source.$(NC)")
181+
$(RM) ./shushtar-debug
182+
$(RM) coverage.txt
183+
$(RM) -r statik

make/release_flags.mk

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
VERSION_TAG = $(shell date +%Y%m%d)-01
2+
VERSION_CHECK = @$(call print, "Building master with date version tag")
3+
4+
BUILD_SYSTEM = darwin-386 \
5+
darwin-amd64 \
6+
linux-386 \
7+
linux-amd64 \
8+
linux-armv6 \
9+
linux-armv7 \
10+
linux-arm64 \
11+
windows-386 \
12+
windows-amd64 \
13+
windows-arm
14+
15+
LND_RELEASE_TAGS = grub autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc
16+
17+
# By default we will build all systems. But with the 'sys' tag, a specific
18+
# system can be specified. This is useful to release for a subset of
19+
# systems/architectures.
20+
ifneq ($(sys),)
21+
BUILD_SYSTEM = $(sys)
22+
endif
23+
24+
# Use all build tags by default but allow them to be overwritten.
25+
ifneq ($(tags),)
26+
LND_RELEASE_TAGS = $(tags)
27+
endif

release.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
# Simple bash script to build basic lnd tools for all the platforms
4+
# we support with the golang cross-compiler.
5+
#
6+
# Copyright (c) 2016 Company 0, LLC.
7+
# Use of this source code is governed by the ISC
8+
# license.
9+
10+
set -e
11+
12+
PKG="github.com/lightninglabs/shushtar"
13+
PACKAGE=shushtar
14+
15+
# green prints one line of green text (if the terminal supports it).
16+
function green() {
17+
echo -e "\e[0;32m${1}\e[0m"
18+
}
19+
20+
# red prints one line of red text (if the terminal supports it).
21+
function red() {
22+
echo -e "\e[0;31m${1}\e[0m"
23+
}
24+
25+
# build_release builds the actual release binaries.
26+
# arguments: <version-tag> <build-system(s)> <build-tags> <ldflags>
27+
function build_release() {
28+
local tag=$1
29+
local sys=$2
30+
local buildtags=$3
31+
local ldflags=$4
32+
33+
green " - Packaging vendor"
34+
go mod vendor
35+
tar -czf vendor.tar.gz vendor
36+
37+
maindir=$PACKAGE-$tag
38+
mkdir -p $maindir
39+
40+
cp vendor.tar.gz $maindir/
41+
rm vendor.tar.gz
42+
rm -r vendor
43+
44+
package_source="${maindir}/${PACKAGE}-source-${tag}.tar"
45+
git archive -o "${package_source}" HEAD
46+
gzip -f "${package_source}" >"${package_source}.gz"
47+
48+
cd "${maindir}"
49+
50+
for i in $sys; do
51+
os=$(echo $i | cut -f1 -d-)
52+
arch=$(echo $i | cut -f2 -d-)
53+
arm=
54+
55+
if [[ $arch == "armv6" ]]; then
56+
arch=arm
57+
arm=6
58+
elif [[ $arch == "armv7" ]]; then
59+
arch=arm
60+
arm=7
61+
fi
62+
63+
dir="${PACKAGE}-${i}-${tag}"
64+
mkdir "${dir}"
65+
pushd "${dir}"
66+
67+
green " - Building: ${os} ${arch} ${arm} with build tags '${buildtags}'"
68+
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" -tags="${buildtags}" ${PKG}/cmd/shushtar
69+
popd
70+
71+
if [[ $os == "windows" ]]; then
72+
zip -r "${dir}.zip" "${dir}"
73+
else
74+
tar -cvzf "${dir}.tar.gz" "${dir}"
75+
fi
76+
77+
rm -r "${dir}"
78+
done
79+
80+
shasum -a 256 * >manifest-$tag.txt
81+
}
82+
83+
# usage prints the usage of the whole script.
84+
function usage() {
85+
red "Usage: "
86+
red "release.sh build-release <version-tag> <build-system(s)> <build-tags> <ldflags>"
87+
}
88+
89+
# Whatever sub command is passed in, we need at least 2 arguments.
90+
if [ "$#" -lt 2 ]; then
91+
usage
92+
exit 1
93+
fi
94+
95+
# Extract the sub command and remove it from the list of parameters by shifting
96+
# them to the left.
97+
SUBCOMMAND=$1
98+
shift
99+
100+
# Call the function corresponding to the specified sub command or print the
101+
# usage if the sub command was not found.
102+
case $SUBCOMMAND in
103+
build-release)
104+
green "Building release"
105+
build_release "$@"
106+
;;
107+
*)
108+
usage
109+
exit 1
110+
;;
111+
esac

0 commit comments

Comments
 (0)