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 3571007..a34392c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ go: os: - linux - windows + - osx branches: only: @@ -13,6 +14,10 @@ branches: - develop - /^feature\/travis\/.+$/ # feature/travis/* - /^fix\/travis\/.+$/ # fix/travis/* + - /^v.*$/ # version tags + +git: + autocrlf: false # gofmt doesn't like CRLF install: - go get -d -u github.com/golang/dep @@ -20,4 +25,22 @@ install: - dep ensure - ./test install -script: ./test --scripted +script: + - ./test --scripted + - ./pack build-os + +deploy: + provider: releases + 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/* + 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..bd347c2 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) @@ -8,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) @@ -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..6317112 --- /dev/null +++ b/pack @@ -0,0 +1,112 @@ +#!/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 +} + +function build_os { + # build only for current OS + # set for script + GOOS=$(go env GOOS) + # architectures + GOARCH=amd64 build +} + +case $1 in + "check" ) + check_all + ;; + "build" ) + build_all + ;; + "build-os" ) + build_os + ;; + * ) + 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