2016-09-08 23:31:07 +02:00
#!/usr/bin/env bash
set -e
2016-09-12 23:10:36 +02:00
# This is borrowed from https://github.com/dotnet/cli/blob/18456af5caeae44defc23ad5579c838c1fda3c3d/run.sh
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
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
# run from directory of launch.sh so artifacts are placed appropriately
pushd " $DIR "
2016-09-09 01:57:32 +02:00
if [ [ -z " $FORK " ] ] ; then
FORK = PowerShell
fi
if [ [ -z " $BRANCH " ] ] ; then
BRANCH = master
fi
2016-09-08 23:31:07 +02:00
# Build both sets by default
if [ [ -z " $BUILDS " ] ] ; then
2016-10-11 20:03:08 +02:00
BUILDS = "release nightly"
2016-09-08 23:31:07 +02:00
fi
# Build specified distributions
if [ [ -z $DISTROS ] ] ; then
2016-09-09 01:26:20 +02:00
DISTROS = "ubuntu14.04 ubuntu16.04 centos7"
2016-09-08 23:31:07 +02:00
fi
for build in $BUILDS ; do
2016-10-11 20:03:08 +02:00
# each distro can be done in parallel; but release must be done before nightly
2016-09-08 23:31:07 +02:00
for distro in $DISTROS ; do
2016-10-11 20:03:08 +02:00
logfile = " $distro .log "
2016-09-12 21:38:52 +02:00
if [ [ " $TEST " -eq 1 ] ] ; then logfile = " test- $logfile " ; fi
2016-10-11 20:03:08 +02:00
mkdir -p " logs/ $build "
logfile = " logs/ $build / $logfile "
2016-09-12 21:38:52 +02:00
echo " Logging to docker/ $logfile "
2016-10-11 20:03:08 +02:00
if [ [ " $build " = release ] ] ; then
2016-10-11 22:15:24 +02:00
repo = "microsoft/powershell"
2016-10-11 20:03:08 +02:00
else
2016-10-11 22:15:24 +02:00
repo = "microsoft/powershell-nightly"
2016-10-11 20:03:08 +02:00
fi
2016-09-12 21:38:52 +02:00
(
2016-10-11 20:03:08 +02:00
image = " $repo : $distro "
2016-09-12 23:10:36 +02:00
pushd " $build "
2016-09-12 21:38:52 +02:00
if [ [ " $TEST " -eq 1 ] ] ; then
echo " LOG: testing $image "
command = "cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester -powershell powershell -Pester ./src/Modules/Shared/Pester"
2016-10-11 20:03:08 +02:00
# clone repo for release images because it's not already done
if [ [ " $build " = release ] ] ; then
2016-09-12 21:38:52 +02:00
command = " git clone --recursive https://github.com/ $FORK /PowerShell -b $BRANCH ; $command "
fi
# run Pester tests inside container
# RUNARGS can be set in the environment
docker run $RUNARGS " $image " -c " $command "
else
echo " LOG: building $image "
# copy the common script because it lives outside the docker build context
2016-10-11 20:03:08 +02:00
if [ [ " $build " = nightly ] ] ; then
2016-09-12 21:38:52 +02:00
cp bootstrap.ps1 " $distro "
buildargs = " --build-arg fork= $FORK --build-arg branch= $BRANCH "
fi
# build and tag the image so they can be derived from
# BUILDARGS can be set in the environment
docker build $buildargs $BUILDARGS -t " $image " " $distro "
2016-10-11 20:03:08 +02:00
if [ [ " $build " = nightly ] ] ; then
2016-09-12 23:10:36 +02:00
echo "LOG: Saving package to docker/packages"
popd
mkdir -p packages
command = 'cp -vf /PowerShell/powershell*{deb,rpm} /mnt 2> /dev/null'
# override entrypoint to be bash so we can use globbing
docker run --rm --volume " $( pwd ) /packages:/mnt " --entrypoint bash " $image " -c " $command "
fi
2016-09-09 23:24:24 +02:00
fi
2016-09-12 21:38:52 +02:00
) & >> " $logfile " &
2016-09-08 23:31:07 +02:00
done
2016-09-12 21:38:52 +02:00
echo " Waiting for $build containers to finish; tail the logs for more information. "
wait
2016-09-08 23:31:07 +02:00
done
2016-09-12 23:10:36 +02:00
popd