Skip to content

Commit

Permalink
Merge pull request #80 from arborchat/travis-build-release
Browse files Browse the repository at this point in the history
Build new releases on merge to master
  • Loading branch information
jwhett authored Jan 16, 2019
2 parents adff77c + 3087193 commit ab3bda6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ install:
script:
- go test -v -cover ./...
- for os in linux darwin windows openbsd; do echo "building for $os" && env GOOS="$os" go build -o /dev/null; done
- ./build-releases.sh
43 changes: 43 additions & 0 deletions build-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -euo pipefail

# only build on master
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "master" ]; then
echo "Not building release, this is a pull request"
exit 0
fi

# get hub if we don't have it
if ! command -v hub 2>&1 > /dev/null ; then
go get github.com/github/hub
fi

release_flags=""
head_commit="$(git rev-parse HEAD 2> /dev/null)"

# build pre-release if not on a tag, otherwise build release
if ! git describe --tags --exact-match HEAD > /dev/null 2>&1 ; then
echo "Building pre-release, not tagged commit"
readonly tag="release-$(echo ${head_commit} | head -c 7)"
release_flags="--prerelease"
else
echo "Building release, tagged commit"
readonly tag="$(git describe --tags --exact-match HEAD 2> /dev/null)"
fi

readonly project="muscadine"
readonly bin_name="$project"
readonly message="Automatic build"

# create the release and upload artifacts
hub release create $release_flags --message="$message" --commitish="$head_commit" "$tag"
for os in darwin linux windows openbsd; do
archive_name="$project-$os.tar.gz"
echo "Building $project for $os"
env GOOS="$os" CGO_ENABLED=0 go build -o "$bin_name" &&\
tar czf "$archive_name" "$bin_name" &&\
rm "$bin_name"
echo "Adding $archive_name to release $tag"
hub release edit --message="$message" --attach="$archive_name#muscadine_${os}" "$tag"
done

0 comments on commit ab3bda6

Please sign in to comment.