2015-07-04 14:10:11 +02:00
#! /bin/bash
outputFolder = './_output'
testPackageFolder = './_tests/'
sourceFolder = './src'
2018-11-23 08:05:47 +01:00
slnFile = $sourceFolder /Radarr.sln
2019-09-02 23:03:41 +02:00
#Artifact variables
artifactsFolder = "./_artifacts" ;
2015-07-04 14:10:11 +02:00
2016-01-17 01:17:36 +01:00
nuget = 'tools/nuget/nuget.exe' ;
2019-09-02 23:03:41 +02:00
2015-07-04 14:10:11 +02:00
CheckExitCode( )
{
" $@ "
local status = $?
if [ $status -ne 0 ] ; then
echo " error with $1 " >& 2
exit 1
fi
return $status
}
2019-09-02 23:03:41 +02:00
ProgressStart( )
{
echo " Start ' $1 ' "
}
ProgressEnd( )
{
echo " Finish ' $1 ' "
}
UpdateVersionNumber( )
{
if [ " $RADARRVERSION " != "" ] ; then
echo "Updating Version Info"
sed -i " s/<AssemblyVersion>[0-9.*]\+<\/AssemblyVersion>/<AssemblyVersion> $RADARRVERSION <\/AssemblyVersion>/g " ./src/Directory.Build.props
sed -i " s/<AssemblyConfiguration>[\$()A-Za-z-]\+<\/AssemblyConfiguration>/<AssemblyConfiguration> ${ BUILD_SOURCEBRANCHNAME } <\/AssemblyConfiguration>/g " ./src/Directory.Build.props
fi
}
2015-07-04 14:10:11 +02:00
CleanFolder( )
{
local path = $1
find $path -name "*.transform" -exec rm "{}" \;
echo "Removing FluentValidation.Resources files"
find $path -name "FluentValidation.resources.dll" -exec rm "{}" \;
find $path -name "App.config" -exec rm "{}" \;
echo "Removing vshost files"
find $path -name "*.vshost.exe" -exec rm "{}" \;
echo "Removing Empty folders"
find $path -depth -empty -type d -exec rm -r "{}" \;
}
2018-11-23 08:05:47 +01:00
LintUI( )
{
2019-09-02 23:03:41 +02:00
ProgressStart 'ESLint'
2019-07-27 07:33:33 +02:00
CheckExitCode yarn lint
2019-09-02 23:03:41 +02:00
ProgressEnd 'ESLint'
2018-11-23 08:05:47 +01:00
2019-09-02 23:03:41 +02:00
ProgressStart 'Stylelint'
2018-11-23 08:05:47 +01:00
CheckExitCode yarn stylelint
2019-09-02 23:03:41 +02:00
ProgressEnd 'Stylelint'
2018-11-23 08:05:47 +01:00
}
2015-07-04 14:10:11 +02:00
Build( )
{
2019-09-02 23:03:41 +02:00
ProgressStart 'Build'
2015-07-04 14:10:11 +02:00
rm -rf $outputFolder
2019-09-02 23:03:41 +02:00
rm -rf $testPackageFolder
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
CheckExitCode dotnet clean $slnFile -c Debug
CheckExitCode dotnet clean $slnFile -c Release
CheckExitCode dotnet msbuild -restore src/Radarr.sln -p:Configuration= Release -t:PublishAllRids
2019-09-02 23:03:41 +02:00
ProgressEnd 'Build'
2015-07-04 14:10:11 +02:00
}
RunGulp( )
{
2019-09-02 23:03:41 +02:00
ProgressStart 'yarn install'
2019-09-03 04:22:25 +02:00
yarn install --frozen-lockfile
2019-09-02 23:03:41 +02:00
ProgressEnd 'yarn install'
2018-11-23 08:05:47 +01:00
LintUI
2015-07-04 14:10:11 +02:00
2019-09-02 23:03:41 +02:00
ProgressStart 'Running gulp'
2018-11-23 08:05:47 +01:00
CheckExitCode yarn run build --production
2019-09-02 23:03:41 +02:00
ProgressEnd 'Running gulp'
2015-07-04 14:10:11 +02:00
}
2019-10-14 22:20:59 +02:00
PackageFiles( )
2015-07-04 14:10:11 +02:00
{
2019-10-14 22:20:59 +02:00
local folder = " $1 "
local framework = " $2 "
local runtime = " $3 "
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
rm -rf $folder
mkdir -p $folder
cp -r $outputFolder /$framework /$runtime /publish/* $folder
cp -r $outputFolder /Radarr.Update/$framework /$runtime /publish $folder /Radarr.Update
cp -r $outputFolder /UI $folder
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
CleanFolder $folder
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
echo "Adding LICENSE"
cp LICENSE $folder
}
PackageLinux( )
{
local framework = " $1 "
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
ProgressStart " Creating Linux Package for $framework "
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
local folder = $artifactsFolder /linux/$framework /Radarr
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
PackageFiles " $folder " $framework $runtime "linux-x64"
echo "Removing Service helpers"
rm -f $folder /ServiceUninstall.*
rm -f $folder /ServiceInstall.*
2015-07-04 14:10:11 +02:00
2018-11-23 08:05:47 +01:00
echo "Renaming Radarr.Console.exe to Radarr.exe"
2019-10-14 22:20:59 +02:00
rm $folder /Radarr.exe*
for file in $folder /Radarr.Console.exe*; do
2015-07-04 14:10:11 +02:00
mv " $file " " ${ file //.Console/ } "
done
2018-11-23 08:05:47 +01:00
echo "Removing Radarr.Windows"
2019-10-14 22:20:59 +02:00
rm $folder /Radarr.Windows.*
2015-07-04 14:10:11 +02:00
2018-11-23 08:05:47 +01:00
echo "Adding Radarr.Mono to UpdatePackage"
2019-10-14 22:20:59 +02:00
cp $folder /Radarr.Mono.* $folder /Radarr.Update
2016-01-16 07:06:33 +01:00
2019-10-14 22:20:59 +02:00
ProgressEnd " Creating Linux Package for $framework "
2015-07-04 14:10:11 +02:00
}
2019-09-02 23:03:41 +02:00
PackageMacOS( )
2015-07-04 14:10:11 +02:00
{
2019-10-14 22:20:59 +02:00
local framework = " $1 "
ProgressStart " Creating MacOS Package for $framework "
2019-09-02 23:03:41 +02:00
2019-10-14 22:20:59 +02:00
local folder = $artifactsFolder /macos/$framework /Radarr
PackageFiles " $folder " " $framework " "osx-x64"
2019-09-02 23:03:41 +02:00
echo "Adding Startup script"
2019-10-14 22:20:59 +02:00
cp ./macOS/Radarr $folder
dos2unix $folder /Radarr
2019-09-02 23:03:41 +02:00
2019-10-14 22:20:59 +02:00
echo "Removing Service helpers"
rm -f $folder /ServiceUninstall.*
rm -f $folder /ServiceInstall.*
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
echo "Renaming Radarr.Console.exe to Radarr.exe"
rm $folder /Radarr.exe*
for file in $folder /Radarr.Console.exe*; do
mv " $file " " ${ file //.Console/ } "
done
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
echo "Removing Radarr.Windows"
rm $folder /Radarr.Windows.*
echo "Adding Radarr.Mono to UpdatePackage"
cp $folder /Radarr.Mono.* $folder /Radarr.Update
2015-07-04 14:10:11 +02:00
2019-09-02 23:03:41 +02:00
ProgressEnd 'Creating MacOS Package'
2015-07-04 14:10:11 +02:00
}
2019-09-02 23:03:41 +02:00
PackageMacOSApp( )
2015-07-04 14:10:11 +02:00
{
2019-10-14 22:20:59 +02:00
local framework = " $1 "
ProgressStart " Creating macOS App Package for $framework "
2019-09-02 23:03:41 +02:00
2019-10-14 22:20:59 +02:00
local folder = $artifactsFolder /macos-app/$framework
2019-09-02 23:03:41 +02:00
2019-10-14 22:20:59 +02:00
rm -rf $folder
mkdir -p $folder
cp -r ./macOS/Radarr.app $folder
mkdir -p $folder /Radarr.app/Contents/MacOS
2019-09-02 23:03:41 +02:00
echo "Copying Binaries"
2019-10-14 22:20:59 +02:00
cp -r $artifactsFolder /macos/$framework /Radarr/* $folder /Radarr.app/Contents/MacOS
2015-07-04 14:10:11 +02:00
2019-09-02 23:03:41 +02:00
echo "Removing Update Folder"
2019-10-14 22:20:59 +02:00
rm -r $folder /Radarr.app/Contents/MacOS/Radarr.Update
2019-09-02 23:03:41 +02:00
ProgressEnd 'Creating macOS App Package'
2015-07-04 14:10:11 +02:00
}
PackageTests( )
{
2019-09-02 23:03:41 +02:00
ProgressStart 'Creating Test Package'
2015-07-04 14:10:11 +02:00
2019-10-14 22:20:59 +02:00
cp ./test.sh $testPackageFolder /net462/win-x64/publish
cp ./test.sh $testPackageFolder /net462/linux-x64/publish
cp ./test.sh $testPackageFolder /net462/osx-x64/publish
if [ $os = "windows" ] ; then
$nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder /net462/win-x64/publish
$nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder /net462/linux-x64/publish
$nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder /net462/osx-x64/publish
2015-07-04 14:10:11 +02:00
else
2019-10-14 22:20:59 +02:00
mono $nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder /net462/win-x64/publish
mono $nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder /net462/linux-x64/publish
mono $nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder /net462/osx-x64/publish
2015-07-04 14:10:11 +02:00
fi
2019-10-14 22:20:59 +02:00
2015-07-04 14:10:11 +02:00
rm -f $testPackageFolder /*.log.config
2019-10-14 22:20:59 +02:00
# geckodriver.exe isn't copied by dotnet publish
curl -Lo gecko.zip "https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-win64.zip"
unzip -o gecko.zip
cp geckodriver.exe $testPackageFolder /net462/win-x64/publish
2015-08-01 14:54:20 +02:00
2019-10-14 22:20:59 +02:00
CleanFolder $testPackageFolder
2019-09-02 23:03:41 +02:00
ProgressEnd 'Creating Test Package'
2015-07-04 14:10:11 +02:00
}
2019-10-14 22:20:59 +02:00
PackageWindows( )
2015-07-04 14:10:11 +02:00
{
2019-10-14 22:20:59 +02:00
local framework = " $1 "
ProgressStart " Creating Windows Package for $framework "
local folder = $artifactsFolder /windows/$framework /Radarr
PackageFiles " $folder " "net462" "win-x64"
2019-09-02 23:03:41 +02:00
2018-11-23 08:05:47 +01:00
echo "Removing Radarr.Mono"
2019-10-14 22:20:59 +02:00
rm -f $folder /Radarr.Mono.*
2015-07-04 14:10:11 +02:00
2018-11-23 08:05:47 +01:00
echo "Adding Radarr.Windows to UpdatePackage"
2019-10-14 22:20:59 +02:00
cp $folder /Radarr.Windows.* $folder /Radarr.Update
2019-09-02 23:03:41 +02:00
2019-10-14 22:20:59 +02:00
ProgressEnd 'Creating Windows Package'
2015-07-04 14:10:11 +02:00
}
# Use mono or .net depending on OS
case " $( uname -s) " in
CYGWIN*| MINGW32*| MINGW64*| MSYS*)
# on windows, use dotnet
2019-10-14 22:20:59 +02:00
os = "windows"
2015-07-04 14:10:11 +02:00
; ;
*)
# otherwise use mono
2019-10-14 22:20:59 +02:00
os = "posix"
2015-07-04 14:10:11 +02:00
; ;
esac
2019-09-02 23:03:41 +02:00
POSITIONAL = ( )
while [ [ $# -gt 0 ] ]
do
key = " $1 "
2018-02-12 17:37:11 +01:00
2019-09-02 23:03:41 +02:00
case $key in
--only-backend)
ONLY_BACKEND = YES
shift # past argument
; ;
--only-frontend)
ONLY_FRONTEND = YES
shift # past argument
; ;
--only-packages)
ONLY_PACKAGES = YES
shift # past argument
; ;
*) # unknown option
POSITIONAL += ( " $1 " ) # save it in an array for later
shift # past argument
; ;
esac
done
set -- " ${ POSITIONAL [@] } " # restore positional parameters
2018-02-12 17:31:18 +01:00
2019-09-02 23:03:41 +02:00
# Only build backend if we haven't set only-frontend or only-packages
if [ -z " $ONLY_FRONTEND " ] && [ -z " $ONLY_PACKAGES " ] ;
then
UpdateVersionNumber
Build
PackageTests
2018-02-12 17:31:18 +01:00
fi
2019-09-02 23:03:41 +02:00
# Only build frontend if we haven't set only-backend or only-packages
if [ -z " $ONLY_BACKEND " ] && [ -z " $ONLY_PACKAGES " ] ;
then
RunGulp
2018-02-12 17:31:18 +01:00
fi
2019-09-02 23:03:41 +02:00
# Only package if we haven't set only-backend or only-frontend
if [ -z " $ONLY_BACKEND " ] && [ -z " $ONLY_FRONTEND " ] ;
then
2019-10-14 22:20:59 +02:00
PackageWindows "net462"
PackageLinux "net462"
PackageMacOS "net462"
PackageMacOSApp "net462"
2018-02-12 17:31:18 +01:00
fi