Add release publishing

This commit is contained in:
Daniel 2020-01-27 13:08:00 +01:00
parent e30f87fc52
commit fcdc66ce57
5 changed files with 131 additions and 5 deletions

5
.gitignore vendored
View file

@ -1,4 +1,5 @@
cpu.out
vendor
cmd/cmd
cmd/jess
cmd/cmd*
cmd/jess*
dist

View file

@ -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 <TOKEN>

View file

@ -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"

View file

@ -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 {

101
pack Executable file
View file

@ -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