set -e

version=$1

if [ -z "$version" ]; then
  echo "No version passed! Example usage: ./release.sh 1.0.0"
  exit 1
fi

echo "Running tests..."
go test

echo "Update version..."
echo -n "v${version}" > VERSION
sed -i '' 's/fmt\.Println("v[0-9]*\.[0-9]*\.[0-9]*")/fmt.Println("v'$version'")/' cmd/captain/cmd.go
sed -i '' 's/v[0-9]*\.[0-9]*\.[0-9]*/v'$version'/' README.md

echo "Build binaries..."
make cross

echo "Update repository..."
git add cmd/captain/cmd.go README.md VERSION
git commit -m "Preparing version ${version}"
git tag --message="v$version" "v$version"

echo "v$version tagged."
echo "Now, run 'git push origin master && git push --tags' and publish the release on GitHub."
