#!/bin/zsh

if [ -z "$1" ]; then
  echo "Usage: $0 <version>"
  exit 1
fi

sed -i "" -e "s|<AssemblyVersion>.*</AssemblyVersion>|<AssemblyVersion>$1</AssemblyVersion>|" FitConnect/FitConnect.csproj
sed -i "" -e "s|<FileVersion>.*</FileVersion>|<FileVersion>$1</FileVersion>|" FitConnect/FitConnect.csproj
sed -i "" -e "s|<PackageVersion>.*</PackageVersion>|<PackageVersion>$1</PackageVersion>|" FitConnect/FitConnect.csproj


if ! dotnet test; then
  echo "Test failed"
  exit 1
fi

if ! dotnet build; then
  echo "Build failed"
  exit 1
fi

if ! dotnet pack; then
  echo "Pack failed"
  exit 1
fi

CURRENT=$(git branch | grep \* | cut -d ' ' -f2)
if [ "$CURRENT" != "master" ]; then
  echo "Not on master branch"
  exit 1
fi

# Here you can do the release things...