Skip to content

Instantly share code, notes, and snippets.

@mattuu
Forked from akfish/pre-commit.sh
Created June 25, 2019 11:49
Show Gist options
  • Save mattuu/c239e124d40b239cf32da75b7b6db3c5 to your computer and use it in GitHub Desktop.
Save mattuu/c239e124d40b239cf32da75b7b6db3c5 to your computer and use it in GitHub Desktop.
Run MSBuild and MSTest for C# project from git pre-commit hook
#!/bin/sh
# Helper
safeRunCommand() {
typeset cmd="$*"
typeset ret_code
echo cmd=$cmd
eval $cmd
ret_code=$?
if [ $ret_code != 0 ]; then
printf "Error : [%d] when executing command: '$cmd'" $ret_code
exit $ret_code
fi
}
# Path To MSBuild.exe
MSBuild="/c/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe"
# Path To MSTest.exe
MSTest="/d/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio\ 11.0/Common7/IDE/MSTest.exe"
# Get Project root path (without tailing /)
ProjectRoot="$(git rev-parse --show-toplevel)"
# Test Containers (without leading /)
Tests=(
"ConsoleSharp.Tests/bin/Debug/ConsoleSharp.Tests.dll"
"Mirror.Test/bin/Debug/Mirror.Test.dll"
)
# Build
safeRunCommand $MSBuild $ProjectRoot/ConsoleSharp.sln
# Test
Args=("${Tests[@]/#//testcontainer:$ProjectRoot/}")
safeRunCommand $MSTest $(eval 'echo "${Args[*]}"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment