From e30f87fc52b006767fe59d500de429e36b5dc10e Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 27 Jan 2020 11:12:20 +0100 Subject: [PATCH 1/5] Add osx platform and turn off git autocrlf --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3571007..367d039 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ go: os: - linux - windows + - osx branches: only: @@ -14,6 +15,9 @@ branches: - /^feature\/travis\/.+$/ # feature/travis/* - /^fix\/travis\/.+$/ # fix/travis/* +git: + autocrlf: false + install: - go get -d -u github.com/golang/dep - go install github.com/golang/dep/cmd/dep From fcdc66ce578db0d62c4d3e213ac1f64d501cb8f8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 27 Jan 2020 13:08:00 +0100 Subject: [PATCH 2/5] Add release publishing --- .gitignore | 5 +-- .travis.yml | 23 +++++++++++- cmd/build | 5 ++- cmd/main.go | 2 +- pack | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 5 deletions(-) create mode 100755 pack diff --git a/.gitignore b/.gitignore index dccf69d..f9776fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cpu.out vendor -cmd/cmd -cmd/jess +cmd/cmd* +cmd/jess* +dist diff --git a/.travis.yml b/.travis.yml index 367d039..37ef5c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ branches: - /^fix\/travis\/.+$/ # fix/travis/* git: - autocrlf: false + autocrlf: false # gofmt doesn't like CRLF install: - go get -d -u github.com/golang/dep @@ -25,3 +25,24 @@ install: - ./test install script: ./test --scripted + +before_deploy: + - git config --local user.name "travis" + - git config --local user.email "" + - ./pack build + +deploy: + provider: releases + api_key: + secure: "Qj3iEGWiAH7uTfOcY6Hi1qF573R5eKjoiJRKgbkt8W7JNOeW+QJD/Vv78q3tpY3UkG1Ez4sOWRsXHrCF6V462NFoY/VFsb5V1i8WP9+v0Z0uNtYFWfWcp0HBN7jT9xsbCwnF4KnaWx+7hOpxeY+L6bBDnsIXMnK/rOWI+HdM2IFdXSEqvpoBERGyNKuPJMdssvX2tbitvRmj13RVZWQoBvxUr2DB8WAavG4afuqwkzoIHw11HpRf2v8BZ8eB1rO6FxaaC2yb8GsFwKsKLUVuqS5carZQVewHSAifh4Zq3f6fZDYRR5gBm8pLeMghWIt6rwo8L1/Fn3uZUkhKFLUR3zrEkxoHdf4jZjJ1oC4zcSDHJKA20QVCTfZGM1OaXmS7UzftRz/855tGvF746M1gSNzMPNmK2thgEgxW3UlOxbSSMvd5NDpTyPYn+DAW3lPDRNNH9a0t+C1mfb3SI4uHl+QaQ9BKSLpIwOJRVEAbrl7Vt7gs5pLJmj3bcwiZ3jjfEwuTNg6n+5QypUdWDY3sQ0EQVOHOHuSRR2TcnSd8wvVPKY7LZ+Fq8Dm0/lTKnz9pyy1psdUZpTEZ97IO3y7gFg3GSKGOoKkx94V5QtTSM9h3TFGFAF275n0MO5LTKyWZtT/1x9/G1k80fNAOHE9cooJAw580uI305pr3r3hjmN0=" + file_glob: true + file: dist/* + skip_cleanup: true + overwrite: true + on: + tags: true + +# encrypting the Github Peronal Access Token: +# docker run --rm -ti ruby /bin/bash +# gem install travis +# travis encrypt -r safing/jess diff --git a/cmd/build b/cmd/build index 85c3b4d..5b61e33 100755 --- a/cmd/build +++ b/cmd/build @@ -1,5 +1,8 @@ #!/bin/bash +baseDir="$( cd "$(dirname "$0")" && pwd )" +cd "$baseDir" + # get build data if [[ "$BUILD_COMMIT" == "" ]]; then BUILD_COMMIT=$(git describe --all --long --abbrev=99 --dirty 2>/dev/null) @@ -45,7 +48,7 @@ fi echo "Please notice, that this build script includes metadata into the build." echo "This information is useful for debugging and license compliance." -echo "Run the compiled binary with the -version flag to see the information included." +echo "Run the compiled binary with the version command to see the information included." # build BUILD_PATH="github.com/safing/jess/vendor/github.com/safing/portbase/info" diff --git a/cmd/main.go b/cmd/main.go index 75a6b0e..0d4e98d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -40,7 +40,7 @@ var ( ) func main() { - info.Set("jess", "v0.0.1", "GPLv3", true) + info.Set("jess", "0.0.1", "GPLv3", true) err := info.CheckVersion() if err != nil { diff --git a/pack b/pack new file mode 100755 index 0000000..27c6678 --- /dev/null +++ b/pack @@ -0,0 +1,101 @@ +#!/bin/bash + +baseDir="$( cd "$(dirname "$0")" && pwd )" +cd "$baseDir" + +COL_OFF="\033[00m" +COL_BOLD="\033[01;01m" +COL_RED="\033[31m" + +destDirPart1="dist" + +function check { + # output + output="cmd" + # get version + version=$(grep "info.Set" cmd/main.go | cut -d'"' -f4) + # build versioned file name with platform + filename="jess_${GOOS}_${GOARCH}_v${version//./-}" + # platform + platform="${GOOS}_${GOARCH}" + if [[ $GOOS == "windows" ]]; then + filename="${filename}.exe" + output="${output}.exe" + fi + # build destination path + destPath=${destDirPart1}/$filename + + # check if file exists + if [[ -f $destPath ]]; then + echo "$platform $version already built" + else + echo -e "${COL_BOLD}$platform $version${COL_OFF}" + fi +} + +function build { + # output + output="cmd/cmd" + # get version + version=$(grep "info.Set" cmd/main.go | cut -d'"' -f4) + # build versioned file name with platform + filename="jess_${GOOS}_${GOARCH}_v${version//./-}" + # platform + platform="${GOOS}_${GOARCH}" + if [[ $GOOS == "windows" ]]; then + filename="${filename}.exe" + output="${output}.exe" + fi + # build destination path + destPath=${destDirPart1}/$filename + + # check if file exists + if [[ -f $destPath ]]; then + echo "$platform already built in version $version, skipping..." + return + fi + + # build + ./cmd/build + if [[ $? -ne 0 ]]; then + echo -e "\n${COL_BOLD}$platform: ${COL_RED}BUILD FAILED.${COL_OFF}" + exit 1 + fi + mkdir -p $(dirname $destPath) + cp $output $destPath + echo -e "\n${COL_BOLD}$platform: successfully built.${COL_OFF}" +} + +function check_all { + GOOS=linux GOARCH=amd64 check + GOOS=windows GOARCH=amd64 check + GOOS=darwin GOARCH=amd64 check +} + +function build_all { + GOOS=linux GOARCH=amd64 build + GOOS=windows GOARCH=amd64 build + GOOS=darwin GOARCH=amd64 build +} + +case $1 in + "check" ) + check_all + ;; + "build" ) + build_all + ;; + * ) + echo "" + echo "build list:" + echo "" + check_all + echo "" + read -p "press [Enter] to start building" x + echo "" + build_all + echo "" + echo "finished building." + echo "" + ;; +esac From 9a8599a8c7b90a36ce6b2d2d612372caa1729266 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 27 Jan 2020 14:20:30 +0100 Subject: [PATCH 3/5] Add version tags to travis branch selection --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 37ef5c8..cbcc672 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ branches: - develop - /^feature\/travis\/.+$/ # feature/travis/* - /^fix\/travis\/.+$/ # fix/travis/* + - /^v.*$/ # version tags git: autocrlf: false # gofmt doesn't like CRLF @@ -33,7 +34,7 @@ before_deploy: deploy: provider: releases - api_key: + token: secure: "Qj3iEGWiAH7uTfOcY6Hi1qF573R5eKjoiJRKgbkt8W7JNOeW+QJD/Vv78q3tpY3UkG1Ez4sOWRsXHrCF6V462NFoY/VFsb5V1i8WP9+v0Z0uNtYFWfWcp0HBN7jT9xsbCwnF4KnaWx+7hOpxeY+L6bBDnsIXMnK/rOWI+HdM2IFdXSEqvpoBERGyNKuPJMdssvX2tbitvRmj13RVZWQoBvxUr2DB8WAavG4afuqwkzoIHw11HpRf2v8BZ8eB1rO6FxaaC2yb8GsFwKsKLUVuqS5carZQVewHSAifh4Zq3f6fZDYRR5gBm8pLeMghWIt6rwo8L1/Fn3uZUkhKFLUR3zrEkxoHdf4jZjJ1oC4zcSDHJKA20QVCTfZGM1OaXmS7UzftRz/855tGvF746M1gSNzMPNmK2thgEgxW3UlOxbSSMvd5NDpTyPYn+DAW3lPDRNNH9a0t+C1mfb3SI4uHl+QaQ9BKSLpIwOJRVEAbrl7Vt7gs5pLJmj3bcwiZ3jjfEwuTNg6n+5QypUdWDY3sQ0EQVOHOHuSRR2TcnSd8wvVPKY7LZ+Fq8Dm0/lTKnz9pyy1psdUZpTEZ97IO3y7gFg3GSKGOoKkx94V5QtTSM9h3TFGFAF275n0MO5LTKyWZtT/1x9/G1k80fNAOHE9cooJAw580uI305pr3r3hjmN0=" file_glob: true file: dist/* From 8597884c7881012ef3ade73437b561978ad40de5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 29 Jan 2020 11:38:12 +0100 Subject: [PATCH 4/5] Fix building and enable to build always --- .travis.yml | 9 +++------ cmd/build | 2 +- pack | 7 +++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index cbcc672..a34392c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,12 +25,9 @@ install: - dep ensure - ./test install -script: ./test --scripted - -before_deploy: - - git config --local user.name "travis" - - git config --local user.email "" - - ./pack build +script: + - ./test --scripted + - ./pack build-os deploy: provider: releases diff --git a/cmd/build b/cmd/build index 5b61e33..bd347c2 100755 --- a/cmd/build +++ b/cmd/build @@ -11,7 +11,7 @@ if [[ "$BUILD_USER" == "" ]]; then BUILD_USER=$(id -un) fi if [[ "$BUILD_HOST" == "" ]]; then - BUILD_HOST=$(hostname -f) + BUILD_HOST=$(hostname) fi if [[ "$BUILD_DATE" == "" ]]; then BUILD_DATE=$(date +%d.%m.%Y) diff --git a/pack b/pack index 27c6678..f202818 100755 --- a/pack +++ b/pack @@ -78,6 +78,10 @@ function build_all { GOOS=darwin GOARCH=amd64 build } +function build_os { + GOARCH=amd64 build +} + case $1 in "check" ) check_all @@ -85,6 +89,9 @@ case $1 in "build" ) build_all ;; + "build-os" ) + build_os + ;; * ) echo "" echo "build list:" From f88ef7d2c3c83eb5f0f7ab8bff3000266c612b3f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 29 Jan 2020 11:45:34 +0100 Subject: [PATCH 5/5] Update pack script to fix info msgs --- pack | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pack b/pack index f202818..6317112 100755 --- a/pack +++ b/pack @@ -79,6 +79,10 @@ function build_all { } function build_os { + # build only for current OS + # set for script + GOOS=$(go env GOOS) + # architectures GOARCH=amd64 build }