Skip to content

Commit 56edf2d

Browse files
committed
Add release script, bump to version v0.2.0
1 parent 15d88df commit 56edf2d

File tree

5 files changed

+159
-7
lines changed

5 files changed

+159
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/chantools
2-
results
2+
results
3+
/chantools-v*

Makefile

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,38 @@ GOINSTALL := GO111MODULE=on go install -v
1818
GOTEST := GO111MODULE=on go test -v
1919
XARGS := xargs -L 1
2020

21+
VERSION_TAG = $(shell git describe --tags)
22+
VERSION_CHECK = @$(call print, "Building master with date version tag")
23+
24+
BUILD_SYSTEM = darwin-386 \
25+
darwin-amd64 \
26+
linux-386 \
27+
linux-amd64 \
28+
linux-armv6 \
29+
linux-armv7 \
30+
linux-arm64 \
31+
windows-386 \
32+
windows-amd64 \
33+
windows-arm
34+
35+
# By default we will build all systems. But with the 'sys' tag, a specific
36+
# system can be specified. This is useful to release for a subset of
37+
# systems/architectures.
38+
ifneq ($(sys),)
39+
BUILD_SYSTEM = $(sys)
40+
endif
41+
2142
TEST_FLAGS = -test.timeout=20m
2243

2344
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
45+
LDFLAGS := -X main.Commit=$(shell git describe --tags)
46+
RELEASE_LDFLAGS := -s -w -buildid= $(LDFLAGS)
47+
48+
GREEN := "\\033[0;32m"
49+
NC := "\\033[0m"
50+
define print
51+
echo $(GREEN)$1$(NC)
52+
endef
2453

2554
default: build
2655

@@ -34,16 +63,21 @@ unit:
3463

3564
build:
3665
@$(call print, "Building chantools.")
37-
$(GOBUILD) ./...
66+
$(GOBUILD) -ldflags "$(LDFLAGS)" ./...
3867

3968
install:
4069
@$(call print, "Installing chantools.")
41-
$(GOINSTALL) ./...
70+
$(GOINSTALL) -ldflags "$(LDFLAGS)" ./...
71+
72+
release:
73+
@$(call print, "Creating release of chantools.")
74+
rm -rf chantools-v*
75+
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)"
4276

4377
fmt:
4478
@$(call print, "Formatting source.")
4579
gofmt -l -w -s $(GOFILES_NOVENDOR)
4680

4781
lint: $(LINT_BIN)
4882
@$(call print, "Linting source.")
49-
$(LINT)
83+
$(LINT)

cmd/chantools/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import (
2626

2727
const (
2828
defaultAPIURL = "https://blockstream.info/api"
29+
version = "0.2.0"
30+
)
31+
32+
var (
33+
Commit = ""
2934
)
3035

3136
type config struct {
@@ -65,6 +70,8 @@ func runCommandParser() error {
6570

6671
// Parse command line.
6772
parser := flags.NewParser(cfg, flags.Default)
73+
74+
log.Infof("chantools version v%s commit %s", version, Commit)
6875
_, _ = parser.AddCommand(
6976
"summary", "Compile a summary about the current state of "+
7077
"channels.", "", &summaryCommand{},
@@ -223,7 +230,7 @@ func rootKeyFromConsole() (*hdkeychain.ExtendedKey, time.Time, error) {
223230
// cipher seed.
224231
fmt.Printf("Input your cipher seed passphrase (press enter if " +
225232
"your seed doesn't have a passphrase): ")
226-
passphrase, err := terminal.ReadPassword(syscall.Stdin)
233+
passphrase, err := terminal.ReadPassword(int(syscall.Stdin)) // nolint
227234
if err != nil {
228235
return nil, time.Unix(0, 0), err
229236
}
@@ -249,9 +256,9 @@ func rootKeyFromConsole() (*hdkeychain.ExtendedKey, time.Time, error) {
249256

250257
func passwordFromConsole(userQuery string) ([]byte, error) {
251258
// Read from terminal (if there is one).
252-
if terminal.IsTerminal(syscall.Stdin) {
259+
if terminal.IsTerminal(int(syscall.Stdin)) { // nolint
253260
fmt.Print(userQuery)
254-
pw, err := terminal.ReadPassword(syscall.Stdin)
261+
pw, err := terminal.ReadPassword(int(syscall.Stdin)) // nolint
255262
if err != nil {
256263
return nil, err
257264
}

release.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# Simple bash script to build basic chantools 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/guggero/chantools"
13+
PACKAGE=chantools
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)> <ldflags>
27+
function build_release() {
28+
local tag=$1
29+
local sys=$2
30+
local ldflags=$3
31+
32+
green " - Packaging vendor"
33+
go mod vendor
34+
tar -czf vendor.tar.gz vendor
35+
36+
maindir=$PACKAGE-$tag
37+
mkdir -p $maindir
38+
39+
cp vendor.tar.gz $maindir/
40+
rm vendor.tar.gz
41+
rm -r vendor
42+
43+
package_source="${maindir}/${PACKAGE}-source-${tag}.tar"
44+
git archive -o "${package_source}" HEAD
45+
gzip -f "${package_source}" >"${package_source}.gz"
46+
47+
cd "${maindir}"
48+
49+
for i in $sys; do
50+
os=$(echo $i | cut -f1 -d-)
51+
arch=$(echo $i | cut -f2 -d-)
52+
arm=
53+
54+
if [[ $arch == "armv6" ]]; then
55+
arch=arm
56+
arm=6
57+
elif [[ $arch == "armv7" ]]; then
58+
arch=arm
59+
arm=7
60+
fi
61+
62+
dir="${PACKAGE}-${i}-${tag}"
63+
mkdir "${dir}"
64+
pushd "${dir}"
65+
66+
green " - Building: ${os} ${arch} ${arm}"
67+
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" ${PKG}/cmd/chantools
68+
popd
69+
70+
if [[ $os == "windows" ]]; then
71+
zip -r "${dir}.zip" "${dir}"
72+
else
73+
tar -cvzf "${dir}.tar.gz" "${dir}"
74+
fi
75+
76+
rm -r "${dir}"
77+
done
78+
79+
shasum -a 256 * >manifest-$tag.txt
80+
}
81+
82+
# usage prints the usage of the whole script.
83+
function usage() {
84+
red "Usage: "
85+
red "release.sh build-release <version-tag> <build-system(s)> <ldflags>"
86+
}
87+
88+
# Whatever sub command is passed in, we need at least 2 arguments.
89+
if [ "$#" -lt 2 ]; then
90+
usage
91+
exit 1
92+
fi
93+
94+
# Extract the sub command and remove it from the list of parameters by shifting
95+
# them to the left.
96+
SUBCOMMAND=$1
97+
shift
98+
99+
# Call the function corresponding to the specified sub command or print the
100+
# usage if the sub command was not found.
101+
case $SUBCOMMAND in
102+
build-release)
103+
green "Building release"
104+
build_release "$@"
105+
;;
106+
*)
107+
usage
108+
exit 1
109+
;;
110+
esac

release_flags.mk

Whitespace-only changes.

0 commit comments

Comments
 (0)