From 56edf2d850baf202503cb72ee82a7e28d8ba9a68 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 11 Jun 2020 09:59:42 +0200 Subject: [PATCH] Add release script, bump to version v0.2.0 --- .gitignore | 3 +- Makefile | 40 +++++++++++++-- cmd/chantools/main.go | 13 +++-- release.sh | 110 ++++++++++++++++++++++++++++++++++++++++++ release_flags.mk | 0 5 files changed, 159 insertions(+), 7 deletions(-) create mode 100755 release.sh create mode 100644 release_flags.mk diff --git a/.gitignore b/.gitignore index 627445a..ce39358 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /chantools -results \ No newline at end of file +results +/chantools-v* diff --git a/Makefile b/Makefile index 3a69738..dc9962f 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,38 @@ GOINSTALL := GO111MODULE=on go install -v GOTEST := GO111MODULE=on go test -v XARGS := xargs -L 1 +VERSION_TAG = $(shell git describe --tags) +VERSION_CHECK = @$(call print, "Building master with date version tag") + +BUILD_SYSTEM = darwin-386 \ +darwin-amd64 \ +linux-386 \ +linux-amd64 \ +linux-armv6 \ +linux-armv7 \ +linux-arm64 \ +windows-386 \ +windows-amd64 \ +windows-arm + +# By default we will build all systems. But with the 'sys' tag, a specific +# system can be specified. This is useful to release for a subset of +# systems/architectures. +ifneq ($(sys),) +BUILD_SYSTEM = $(sys) +endif + TEST_FLAGS = -test.timeout=20m UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) +LDFLAGS := -X main.Commit=$(shell git describe --tags) +RELEASE_LDFLAGS := -s -w -buildid= $(LDFLAGS) + +GREEN := "\\033[0;32m" +NC := "\\033[0m" +define print + echo $(GREEN)$1$(NC) +endef default: build @@ -34,11 +63,16 @@ unit: build: @$(call print, "Building chantools.") - $(GOBUILD) ./... + $(GOBUILD) -ldflags "$(LDFLAGS)" ./... install: @$(call print, "Installing chantools.") - $(GOINSTALL) ./... + $(GOINSTALL) -ldflags "$(LDFLAGS)" ./... + +release: + @$(call print, "Creating release of chantools.") + rm -rf chantools-v* + ./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)" fmt: @$(call print, "Formatting source.") @@ -46,4 +80,4 @@ fmt: lint: $(LINT_BIN) @$(call print, "Linting source.") - $(LINT) \ No newline at end of file + $(LINT) diff --git a/cmd/chantools/main.go b/cmd/chantools/main.go index be25979..9213666 100644 --- a/cmd/chantools/main.go +++ b/cmd/chantools/main.go @@ -26,6 +26,11 @@ import ( const ( defaultAPIURL = "https://blockstream.info/api" + version = "0.2.0" +) + +var ( + Commit = "" ) type config struct { @@ -65,6 +70,8 @@ func runCommandParser() error { // Parse command line. parser := flags.NewParser(cfg, flags.Default) + + log.Infof("chantools version v%s commit %s", version, Commit) _, _ = parser.AddCommand( "summary", "Compile a summary about the current state of "+ "channels.", "", &summaryCommand{}, @@ -223,7 +230,7 @@ func rootKeyFromConsole() (*hdkeychain.ExtendedKey, time.Time, error) { // cipher seed. fmt.Printf("Input your cipher seed passphrase (press enter if " + "your seed doesn't have a passphrase): ") - passphrase, err := terminal.ReadPassword(syscall.Stdin) + passphrase, err := terminal.ReadPassword(int(syscall.Stdin)) // nolint if err != nil { return nil, time.Unix(0, 0), err } @@ -249,9 +256,9 @@ func rootKeyFromConsole() (*hdkeychain.ExtendedKey, time.Time, error) { func passwordFromConsole(userQuery string) ([]byte, error) { // Read from terminal (if there is one). - if terminal.IsTerminal(syscall.Stdin) { + if terminal.IsTerminal(int(syscall.Stdin)) { // nolint fmt.Print(userQuery) - pw, err := terminal.ReadPassword(syscall.Stdin) + pw, err := terminal.ReadPassword(int(syscall.Stdin)) // nolint if err != nil { return nil, err } diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..9913722 --- /dev/null +++ b/release.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +# Simple bash script to build basic chantools for all the platforms +# we support with the golang cross-compiler. +# +# Copyright (c) 2016 Company 0, LLC. +# Use of this source code is governed by the ISC +# license. + +set -e + +PKG="github.com/guggero/chantools" +PACKAGE=chantools + +# green prints one line of green text (if the terminal supports it). +function green() { + echo -e "\e[0;32m${1}\e[0m" +} + +# red prints one line of red text (if the terminal supports it). +function red() { + echo -e "\e[0;31m${1}\e[0m" +} + +# build_release builds the actual release binaries. +# arguments: +function build_release() { + local tag=$1 + local sys=$2 + local ldflags=$3 + + green " - Packaging vendor" + go mod vendor + tar -czf vendor.tar.gz vendor + + maindir=$PACKAGE-$tag + mkdir -p $maindir + + cp vendor.tar.gz $maindir/ + rm vendor.tar.gz + rm -r vendor + + package_source="${maindir}/${PACKAGE}-source-${tag}.tar" + git archive -o "${package_source}" HEAD + gzip -f "${package_source}" >"${package_source}.gz" + + cd "${maindir}" + + for i in $sys; do + os=$(echo $i | cut -f1 -d-) + arch=$(echo $i | cut -f2 -d-) + arm= + + if [[ $arch == "armv6" ]]; then + arch=arm + arm=6 + elif [[ $arch == "armv7" ]]; then + arch=arm + arm=7 + fi + + dir="${PACKAGE}-${i}-${tag}" + mkdir "${dir}" + pushd "${dir}" + + green " - Building: ${os} ${arch} ${arm}" + env CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" ${PKG}/cmd/chantools + popd + + if [[ $os == "windows" ]]; then + zip -r "${dir}.zip" "${dir}" + else + tar -cvzf "${dir}.tar.gz" "${dir}" + fi + + rm -r "${dir}" + done + + shasum -a 256 * >manifest-$tag.txt +} + +# usage prints the usage of the whole script. +function usage() { + red "Usage: " + red "release.sh build-release " +} + +# Whatever sub command is passed in, we need at least 2 arguments. +if [ "$#" -lt 2 ]; then + usage + exit 1 +fi + +# Extract the sub command and remove it from the list of parameters by shifting +# them to the left. +SUBCOMMAND=$1 +shift + +# Call the function corresponding to the specified sub command or print the +# usage if the sub command was not found. +case $SUBCOMMAND in +build-release) + green "Building release" + build_release "$@" + ;; +*) + usage + exit 1 + ;; +esac diff --git a/release_flags.mk b/release_flags.mk new file mode 100644 index 0000000..e69de29