diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 000000000..236c934d2 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,69 @@ +# Source this to add some fancy stuff to your scripts + +# Detect build servers +if [[ ! -z "$JENKINS_URL" || ! -z "$BUILD_BUILDID" ]]; then + # Jenkins or VSO build, disable colors because they make things gross. + NO_COLOR=1 +fi + +if [ "$NO_COLOR" != "1" ]; then + # ANSI Colors + RCol='\e[0m' # Text Reset + + # Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds + Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m'; + Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m'; + Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m'; + Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m'; + Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m'; + Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m'; + Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m'; + Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m'; +fi + +cecho() +{ + local text=$1 + printf "%b\n" "$text" +} + +banner() +{ + local text=$1 + cecho "${BGre}*** $text ***${RCol}" +} + +info() +{ + local text=$1 + cecho "${Gre}info :${RCol} $text" +} + +warning() +{ + local text=$1 + cecho "${Yel}warn :${RCol} $text" 1>&2 +} + +error() +{ + local text=$1 + cecho "${Red}error:${RCol} $text" 1>&2 +} + +UNAME=$(uname) + +if [ -z "$RID" ]; then + if [ "$UNAME" == "Darwin" ]; then + OSNAME=osx + RID=osx.10.10-x64 + elif [ "$UNAME" == "Linux" ]; then + # Detect Distro? + OSNAME=linux + RID=ubuntu.14.04-x64 + else + error "unknown OS: $UNAME" 1>&2 + exit 1 + fi +fi + diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index c1e079c5a..bc421df64 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -2,11 +2,6 @@ set -e -[ -z "$CONFIGURATION" ] && CONFIGURATION=Debug - -# TODO: Replace this with a dotnet generation -TFM=dnxcore50 - SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" @@ -14,45 +9,37 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +source "$DIR/_common.sh" + +[ -z "$CONFIGURATION" ] && CONFIGURATION=Debug + +# TODO: Replace this with a dotnet generation +TFM=dnxcore50 + REPOROOT="$( cd -P "$DIR/.." && pwd )" START_PATH=$PATH -echo "Bootstrapping dotnet.exe using DNX" - -if [ -z "$RID" ]; then - UNAME=$(uname) - if [ "$UNAME" == "Darwin" ]; then - RID=osx.10.10-x64 - elif [ "$UNAME" == "Linux" ]; then - # Detect Distro? - RID=ubuntu.14.04-x64 - else - echo "Unknown OS: $UNAME" 1>&2 - exit 1 - fi -fi - OUTPUT_ROOT=$REPOROOT/artifacts/$RID DNX_DIR=$OUTPUT_ROOT/dnx STAGE1_DIR=$OUTPUT_ROOT/stage1 STAGE2_DIR=$OUTPUT_ROOT/stage2 -echo "Installing stage0" +banner "Installing stage0" source $DIR/dnvm2.sh dnvm upgrade -a dotnet_stage0 - DNX_ROOT="$(dirname $(which dotnet))/dnx" -echo "Restoring packages" +banner "Restoring packages" -dotnet restore "$REPOROOT" --runtime osx.10.10-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.11-x64 +dotnet restore "$REPOROOT" --runtime osx.10.10-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.11-x64 --quiet # Clean up stage1 [ -d "$STAGE1_DIR" ] && rm -Rf "$STAGE1_DIR" -echo "Building basic dotnet tools using Stage 0" +banner "Building stage1 using downloaded stage0" dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Cli" dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler" dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc" @@ -68,7 +55,7 @@ chmod a+x $STAGE1_DIR/corerun # Clean up stage2 [ -d "$STAGE2_DIR" ] && rm -Rf "$STAGE2_DIR" -echo "Building stage2 dotnet using stage1 ..." +banner "Building stage2 dotnet using compiled stage1 ..." dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Cli" dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler" dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc" @@ -86,21 +73,22 @@ cp $DIR/dotnet-restore.sh $STAGE2_DIR/dotnet-restore chmod a+x $STAGE2_DIR/dotnet-restore # Smoke-test the output +banner "Testing stage2 ..." export PATH=$STAGE2_DIR:$START_PATH # rm "$REPOROOT/test/TestApp/project.lock.json" # dotnet restore "$REPOROOT/test/TestApp" --runtime "$RID" # dotnet publish "$REPOROOT/test/TestApp" --framework "$TFM" --runtime "$RID" --output "$REPOROOT/artifacts/$RID/smoketest" -# OUTPUT=$($REPOROOT/artifacts/$RID/smoketest/TestApp) -# [ "$OUTPUT" == "This is a test app" ] || (echo "Smoke test failed!" && exit 1) +OUTPUT=$($REPOROOT/artifacts/$RID/smoketest/TestApp) +[ "$OUTPUT" == "This is a test app" ] || (error "Smoke test failed!" && exit 1) # Check that a compiler error is reported set +e dotnet compile "$REPOROOT/test/compile/failing/SimpleCompilerError" --framework "$TFM" 2>/dev/null >/dev/null rc=$? if [ $rc == 0 ]; then - echo "Compiler failure test failed! The compiler did not fail to compile!" + error "Compiler failure test failed! The compiler did not fail to compile!" exit 1 fi set -e diff --git a/scripts/ci_build.sh b/scripts/ci_build.sh index c603974af..aaeead2e7 100755 --- a/scripts/ci_build.sh +++ b/scripts/ci_build.sh @@ -1,7 +1,15 @@ #!/usr/bin/env bash set -e -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +source "$SCRIPT_DIR/_common.sh" # Some things depend on HOME and it may not be set. We should fix those things, but until then, we just patch a value in if [ -z "$HOME" ]; then @@ -15,7 +23,7 @@ fi BASE_VERSION=0.0.2-alpha1 if [ ! -z "$BUILD_NUMBER" ]; then export DOTNET_BUILD_VERSION="$BASE_VERSION-$(printf "%05d" $BUILD_NUMBER)" - echo "Building version $DOTNET_BUILD_VERSION" + info "Building version $DOTNET_BUILD_VERSION" fi if [[ "$(uname)" == "Linux" ]]; then diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 8bdd5ee94..d267f07a6 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -7,6 +7,8 @@ RUN apt-get update && \ apt-get -qqy install unzip curl libicu-dev libunwind8 gettext libssl-dev libcurl3-gnutls zlib1g && \ rm -rf /var/lib/apt/lists/* +# No longer need to install DNX since it is embedded (and soon will be gone!) + # Install Package Build Prereqs (and clean up APT cache after to save space in the image) RUN echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main" | tee /etc/apt/sources.list.d/llvm.list && \ curl http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \ diff --git a/scripts/dockerbuild.sh b/scripts/dockerbuild.sh index 9bfcdfc7c..509b3a090 100755 --- a/scripts/dockerbuild.sh +++ b/scripts/dockerbuild.sh @@ -8,6 +8,8 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +source $DIR/_common.sh + cd $DIR/.. [ -z "$DOTNET_BUILD_CONTAINER_TAG" ] && DOTNET_BUILD_CONTAINER_TAG="dotnetcli-build" @@ -18,11 +20,14 @@ cd $DIR/.. echo $DOCKER_HOST_SHARE_DIR # Build the docker container (will be fast if it is already built) +banner "Building Docker Container" docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/ # Run the build in the container +banner "Launching build in Docker Container" +info "Using code from: $DOCKER_HOST_SHARE_DIR" docker run --rm --sig-proxy=true \ - --name $DOTNET_BUILD_CONTAINER_NAME \ + --name $DOTNET_BUILD_CONTAINER_NAME \ -v $DOCKER_HOST_SHARE_DIR:/opt/code \ -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \ -e DOTNET_CI_SKIP_STAGE0_INSTALL=$DOTNET_CI_SKIP_STAGE0_INSTALL \ diff --git a/scripts/dockerpostbuild.sh b/scripts/dockerpostbuild.sh index 09d60f69d..7fb99b404 100755 --- a/scripts/dockerpostbuild.sh +++ b/scripts/dockerpostbuild.sh @@ -8,6 +8,8 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +source "$DIR/_common.sh" + cd $DIR/.. [ -z "$DOTNET_BUILD_CONTAINER_TAG" ] && DOTNET_BUILD_CONTAINER_TAG="dotnetcli-build" @@ -15,13 +17,16 @@ cd $DIR/.. [ -z "$DOCKER_HOST_SHARE_DIR" ] && DOCKER_HOST_SHARE_DIR=$(pwd) # Build the docker container (will be fast if it is already built) +info "Building docker container" docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/ # First thing make sure all of our build containers are stopped +info "Terminating and cleaning all running containers" docker stop $DOTNET_BUILD_CONTAINER_NAME docker rm $DOTNET_BUILD_CONTAINER_NAME # Remove the sticky bit on directories created by docker so we can delete them +info "Cleaning directories created by docker build" docker run --rm \ -v $DOCKER_HOST_SHARE_DIR:/opt/code \ -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \ diff --git a/scripts/package-debian.sh b/scripts/package-debian.sh index 782b85790..97c6e87ad 100755 --- a/scripts/package-debian.sh +++ b/scripts/package-debian.sh @@ -11,11 +11,10 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -UNAME=$(uname) +source "$DIR/_common.sh" - if [ "$UNAME" != "Linux" ]; then - echo "Error: Build only supported on Linux" + errro "Debian Package build only supported on Linux" exit 1 fi @@ -34,6 +33,8 @@ execute(){ } create_empty_debian_layout(){ + banner "Creating empty debian package layout" + rm -rf $PACKAGE_LAYOUT_DIR mkdir -p $PACKAGE_LAYOUT_DIR @@ -44,6 +45,8 @@ create_empty_debian_layout(){ } copy_files_to_debian_layout(){ + banner "Copying files to debian layout" + # Copy Built Binaries cp -a "$REPO_BINARIES_DIR/." "$PACKAGE_LAYOUT_DIR/package_root" @@ -52,12 +55,16 @@ copy_files_to_debian_layout(){ } create_debian_package(){ + banner "Packing .deb" + mkdir -p $PACKAGE_OUTPUT_DIR - + $REPO_ROOT/package_tool/package_tool $PACKAGE_LAYOUT_DIR $PACKAGE_OUTPUT_DIR } test_debian_package(){ + banner "Testing debian package" + git clone https://github.com/sstephenson/bats.git /tmp/bats pushd /tmp/bats ./install.sh /usr/local diff --git a/scripts/package-dnvm.sh b/scripts/package-dnvm.sh index 7342023a4..90c287be0 100755 --- a/scripts/package-dnvm.sh +++ b/scripts/package-dnvm.sh @@ -8,22 +8,9 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -REPOROOT="$( cd -P "$DIR/.." && pwd )" +source "$DIR/_common.sh" -if [ -z "$RID" ]; then - UNAME=$(uname) - if [ "$UNAME" == "Darwin" ]; then - OSNAME=osx - RID=osx.10.10-x64 - elif [ "$UNAME" == "Linux" ]; then - # Detect Distro? - OSNAME=linux - RID=ubuntu.14.04-x64 - else - echo "Unknown OS: $UNAME" 1>&2 - exit 1 - fi -fi +REPOROOT="$( cd -P "$DIR/.." && pwd )" if [ -z "$DOTNET_BUILD_VERSION" ]; then TIMESTAMP=$(date "+%Y%m%d%H%M%S") @@ -33,18 +20,20 @@ fi STAGE2_DIR=$REPOROOT/artifacts/$RID/stage2 if [ ! -d "$STAGE2_DIR" ]; then - echo "Missing stage2 output in $STAGE2_DIR" 1>&2 + error "missing stage2 output in $STAGE2_DIR" 1>&2 exit fi PACKAGE_DIR=$REPOROOT/artifacts/packages/dnvm [ -d "$PACKAGE_DIR" ] || mkdir -p $PACKAGE_DIR -PACKAGE_NAME=$PACKAGE_DIR/dotnet-${OSNAME}-x64.${DOTNET_BUILD_VERSION}.tar.gz +PACKAGE_SHORT_NAME=dotnet-${OSNAME}-x64.${DOTNET_BUILD_VERSION} +PACKAGE_NAME=$PACKAGE_DIR/${PACKAGE_SHORT_NAME}.tar.gz cd $STAGE2_DIR # Correct all the mode flags +banner "Packaging $PACKAGE_SHORT_NAME" # Managed code doesn't need 'x' find . -type f -name "*.dll" | xargs chmod 644 @@ -63,6 +52,6 @@ find . -type f ! -name "*.*" | xargs chmod 755 # Tar up the stage2 artifacts tar -czf $PACKAGE_NAME * -echo "Packaged stage2 to $PACKAGE_NAME" +info "Packaged stage2 to $PACKAGE_NAME" $DIR/publish.sh $PACKAGE_NAME diff --git a/scripts/publish.sh b/scripts/publish.sh index 757b45d3f..cb24946e7 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -8,11 +8,21 @@ # $SASTOKEN # $REPO_ID -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +source "$SCRIPT_DIR/_common.sh" UPLOAD_FILE=$1 UPLOAD_JSON_FILE="package_upload.json" +banner "Publishing package" + execute(){ if ! validate_env_variables; then # fail silently if the required variables are not available for publishing the file. @@ -40,22 +50,22 @@ validate_env_variables(){ local ret=0 if [[ -z "$DOTNET_BUILD_VERSION" ]]; then - echo "DOTNET_BUILD_VERSION environment variable not set" + warning "DOTNET_BUILD_VERSION environment variable not set" ret=1 fi if [[ -z "$SASTOKEN" ]]; then - echo "SASTOKEN environment variable not set" + warning "SASTOKEN environment variable not set" ret=1 fi if [[ -z "$STORAGE_ACCOUNT" ]]; then - echo "STORAGE_ACCOUNT environment variable not set" + warning "STORAGE_ACCOUNT environment variable not set" ret=1 fi if [[ -z "$STORAGE_CONTAINER" ]]; then - echo "STORAGE_CONTAINER environment variable not set" + warning "STORAGE_CONTAINER environment variable not set" ret=1 fi @@ -68,9 +78,10 @@ validate_env_variables(){ } upload_file_to_blob_storage(){ - local filename=$(basename $UPLOAD_FILE) + banner "Uploading $filename to blob storage" + if [[ $filename == *.deb || $filename == *.pkg ]]; then FOLDER="Installers" elif [[ $filename == *.tar.gz ]]; then @@ -83,9 +94,9 @@ upload_file_to_blob_storage(){ result=$? if [ "$result" -gt "0" ]; then - echo "Error: Uploading the $filename to blob storage - $result" + error "uploading the $filename to blob storage - $result" else - echo "Successfully uploaded $filename to blob storage." + info "successfully uploaded $filename to blob storage." fi return $result