Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Travis CI tests and releases deployment #4

Merged
merged 5 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cpu.out
vendor
cmd/cmd
cmd/jess
cmd/cmd*
cmd/jess*
dist
25 changes: 24 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,41 @@ go:
os:
- linux
- windows
- osx

branches:
only:
- master
- 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
- go install github.com/golang/dep/cmd/dep
- 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 <TOKEN>
7 changes: 5 additions & 2 deletions cmd/build
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
112 changes: 112 additions & 0 deletions pack
Original file line number Diff line number Diff line change
@@ -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