device-simulation-dotnet/scripts/build

91 строка
2.4 KiB
Plaintext
Исходник Обычный вид История

2017-05-01 04:17:01 +03:00
#!/usr/bin/env bash
# Usage:
# Build the project in the local environment: ./scripts/build
# Build the project inside a Docker container: ./scripts/build -s
# Build the project inside a Docker container: ./scripts/build --in-sandbox
2017-05-01 04:17:01 +03:00
# Debug|Release
CONFIGURATION=Release
set -e
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
source "$APP_HOME/scripts/.functions.sh"
# Folder where PCS sandboxes cache data. Reuse the same folder to speed up the
# sandbox and to save disk space.
# Use PCS_CACHE="$APP_HOME/.cache" to cache inside the project folder
PCS_CACHE="/tmp/azure/iotpcs/.cache"
2017-05-01 04:17:01 +03:00
compile() {
check_dependency_dotnet
cd $APP_HOME
header "Downloading dependencies..."
dotnet restore
header "Compiling code..."
dotnet build --configuration $CONFIGURATION
2017-05-01 04:17:01 +03:00
}
run_tests() {
check_dependency_dotnet
cd $APP_HOME
header "Running tests..."
PROJECTS=$(dotnet sln list | grep 'csproj$' | grep '\.Test')
2017-05-01 04:17:01 +03:00
for PROJ in $PROJECTS; do
echo "-- $PROJ"
dotnet test --configuration $CONFIGURATION $PROJ
2017-05-01 04:17:01 +03:00
done
}
setup_sandbox_cache() {
mkdir -p $PCS_CACHE/sandbox/.config
mkdir -p $PCS_CACHE/sandbox/.dotnet
mkdir -p $PCS_CACHE/sandbox/.nuget
}
build_in_sandbox() {
setup_sandbox_cache
cd $APP_HOME
echo "Note: caching .NET files in $PCS_CACHE"
# On Windows this script should use docker.exe, in which case
# the parameters syntax is different, e.g. volumes path
# (i.e. C:\path\path\... vs /c/path/path/...).
#
# Note that this script is also used for the git precommit hook.
set +e
IS_WINDOWS=$(which cmd.exe)
set -e
if [[ -z "$IS_WINDOWS" ]]; then
check_dependency_docker
docker run -it \
-e "PCS_IOTHUBMANAGER_WEBSERVICE_URL=$PCS_IOTHUBMANAGER_WEBSERVICE_URL" \
-v "$PCS_CACHE/sandbox/.config:/root/.config" \
-v "$PCS_CACHE/sandbox/.dotnet:/root/.dotnet" \
-v "$PCS_CACHE/sandbox/.nuget:/root/.nuget" \
-v "$APP_HOME:/opt/code" \
azureiotpcs/code-builder-dotnet:1.0-dotnetcore /opt/scripts/build
else
# Note 'winpty' is required to provide a TTY to Docker
cmd.exe /c "winpty .\scripts\build.cmd" --in-sandbox
fi
}
if [[ "$1" == "--in-sandbox" || "$1" == "-s" ]]; then
build_in_sandbox
else
# workaround for https://github.com/dotnet/cli/issues/3995
unset home
compile
run_tests
fi
set +e