diff --git a/.gitignore b/.gitignore index e9385fc1..ae830506 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ lets-proxy.iml log.txt storage/ +output/ config.toml diff --git a/.travis.yml b/.travis.yml index 33d8b846..3c1a7c30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,15 @@ +env: + - GO111MODULE=on GOFLAGS=-mod=vendor CGO_ENABLED=0 TAG_PREFIX="v0.20.0" + language: go +addons: + apt: + packages: + - dos2unix + go: - "1.12.4" - - "master" - -env: - global: - - GO111MODULE=on - matrix: - - GOFLAGS= - - GOFLAGS=-mod=vendor -matrix: - exclude: - - go: "master" - env: GOFLAGS=-mod=vendor - fast_finish: true - allow_failures: - - go: "master" - - env: GOFLAGS= - services: - docker @@ -34,3 +25,25 @@ after_script: - go get -mod= golang.org/x/tools/cmd/cover - go get -mod= github.com/mattn/goveralls - goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN + +before_deploy: + - git config --local user.name "$GIT_NAME" + - git config --local user.email "$GIT_EMAIL" + - export TRAVIS_TAG="$TAG_PREFIX.$TRAVIS_BUILD_NUMBER" + - git tag $TRAVIS_TAG + - go get -mod= github.com/mitchellh/gox + - mkdir -p output + - OS_ARCH_BUILDS="darwin/amd64 linux/386 linux/amd64 linux/arm freebsd/386 freebsd/amd64 freebsd/arm windows/386 windows/amd64" + - gox --mod=vendor -osarch "$OS_ARCH_BUILDS" --ldflags "-X \"main.VERSION=$TRAVIS_TAG commit $TRAVIS_COMMIT\"" --output="output/lets-proxy_{{.OS}}_{{.Arch}}" -verbose --rebuild ./cmd/ + - bash tests/make_archives.sh + +deploy: + skip_cleanup: true + provider: releases + on: + repo: rekby/lets-proxy2 + branch: master + api_key: $GITHUB_TOKEN + file_glob: true + file: output/* + diff --git a/cmd/flags.go b/cmd/flags.go index 476ab2fd..47b39dfb 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -5,4 +5,5 @@ import "flag" var ( configFileP = flag.String("config", "", "Path to config file. Empty for no read config.") defaultConfigP = flag.Bool("print-default-config", false, "Write default config to stdout and exit.") + versionP = flag.Bool("version", false, "print version and exit") ) diff --git a/cmd/main.go b/cmd/main.go index c934145a..cce37580 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "os" + "runtime" "strings" _ "github.com/kardianos/minwinsvc" @@ -20,6 +21,8 @@ import ( "go.uber.org/zap" ) +var VERSION = "custom" // need be var becouse it redefine by --ldflags "-X main.VERSION" during autobuild + const defaultDirMode = 0700 func main() { @@ -33,6 +36,11 @@ func main() { os.Exit(0) } + if *versionP { + fmt.Printf("Version: '%v', Os: '%v', Arch: '%v'\n", VERSION, runtime.GOOS, runtime.GOARCH) + return + } + startProgram(getConfig(globalContext)) } diff --git a/go.mod b/go.mod index 48058c11..10f1e369 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/gojuno/minimock v0.0.0-20190201083043-bbb4f602d884 github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0 github.com/maxatome/go-testdeep v1.0.8 + github.com/mitchellh/gox v1.0.1 // indirect github.com/pelletier/go-toml v1.3.0 github.com/rekby/zapcontext v0.0.3 github.com/satori/go.uuid v1.2.0 diff --git a/go.sum b/go.sum index d91efed2..ce83236a 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/gojuno/minimock v0.0.0-20190130082935-96af809257c4/go.mod h1:iOiCj/Xd github.com/gojuno/minimock v0.0.0-20190201083043-bbb4f602d884 h1:/aJrUbmqgRvJgQrmzIdqeWJI0nG3H+APPnBReOuFnug= github.com/gojuno/minimock v0.0.0-20190201083043-bbb4f602d884/go.mod h1:m23ur753eqrqUyg8lovbtFUCEu2mBDo1YEfqZKZPwRw= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= +github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/heschik/goimports v0.0.0-20181107214206-01b9d28a5b21/go.mod h1:OojSIbPeQjVvyxj5CBXMXtxP55vfvTHhWE8eKDpj6SM= github.com/hexdigest/gowrap v1.1.1/go.mod h1:BJ3dVLFoWfoXxzpVf+q8UxFtPBz2j0RYwuELxA8qYOg= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -24,6 +26,10 @@ github.com/marwan-at-work/vgop v0.0.0-20180824202541-054e5a7d7b48/go.mod h1:8stA github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/maxatome/go-testdeep v1.0.8 h1:OORprsdGMEDRo1diHCQzxCAaZFWKlHDrBnPttC4wL8g= github.com/maxatome/go-testdeep v1.0.8/go.mod h1:Vcp0RXXOMhUTw2S2HRmUIqHQpG2Oxz+HM/WSWK7yXto= +github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= +github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= +github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pelletier/go-toml v1.3.0 h1:e5+lF2E4Y2WCIxBefVowBuB0iHrUH4HZ8q+6mGF7fJc= diff --git a/tests/make_archives.sh b/tests/make_archives.sh new file mode 100644 index 00000000..86f139b9 --- /dev/null +++ b/tests/make_archives.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -ev + +go run cmd/*.go --print-default-config > output/config_default.toml_ + +cd output + +cp ../README.md ./README.md +unix2dos -n README.md README.txt + +for FILE in `ls`; do + expr match "$FILE" '^lets-proxy_' > /dev/null || continue + echo "$FILE" + if expr match "$FILE" '^lets-proxy_windows' > /dev/null; then + mv "$FILE" lets-proxy.exe + unix2dos -n config_default.toml_ config_default.toml + zip "${FILE%.exe}.zip" lets-proxy.exe README.txt config_default.toml + rm config_default.toml + rm lets-proxy.exe + else + mv "$FILE" lets-proxy + cp config_default.toml_ config_default.toml + tar -zcvf "${FILE%.exe}.tar.gz" lets-proxy README.md config_default.toml + rm config_default.toml + rm lets-proxy + fi +done + +rm config_default.toml_ README.md README.txt +ls \ No newline at end of file