Radarr/build.sh

359 lines
9.1 KiB
Bash
Raw Normal View History

2015-07-04 12:10:11 +00:00
#! /bin/bash
msBuildVersion='15.0'
2015-07-04 12:10:11 +00:00
outputFolder='./_output'
outputFolderLinux='./_output_linux'
outputFolderMacOS='./_output_macos'
outputFolderMacOSApp='./_output_macos_app'
2015-07-04 12:10:11 +00:00
testPackageFolder='./_tests/'
sourceFolder='./src'
2018-11-23 07:05:47 +00:00
slnFile=$sourceFolder/Radarr.sln
updateFolder=$outputFolder/Radarr.Update
updateFolderMono=$outputFolderLinux/Radarr.Update
#Artifact variables
artifactsFolder="./_artifacts";
artifactsFolderWindows=$artifactsFolder/windows
artifactsFolderLinux=$artifactsFolder/linux
artifactsFolderMacOS=$artifactsFolder/macos
artifactsFolderMacOSApp=$artifactsFolder/macos-app
2015-07-04 12:10:11 +00:00
nuget='tools/nuget/nuget.exe';
vswhere='tools/vswhere/vswhere.exe';
2015-07-04 12:10:11 +00:00
CheckExitCode()
{
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "error with $1" >&2
exit 1
fi
return $status
}
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 12:10:11 +00:00
CleanFolder()
{
local path=$1
local keepConfigFiles=$2
find $path -name "*.transform" -exec rm "{}" \;
if [ $keepConfigFiles != true ] ; then
find $path -name "*.dll.config" -exec rm "{}" \;
fi
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 "{}" \;
2016-01-16 05:49:09 +00:00
echo "Removing dylib files"
find $path -name "*.dylib" -exec rm "{}" \;
2015-07-04 12:10:11 +00:00
echo "Removing Empty folders"
find $path -depth -empty -type d -exec rm -r "{}" \;
}
BuildWithMSBuild()
{
installationPath=`$vswhere -latest -products \* -requires Microsoft.Component.MSBuild -property installationPath`
installationPath=${installationPath/C:\\/\/c\/}
installationPath=${installationPath//\\/\/}
msBuild="$installationPath/MSBuild/$msBuildVersion/Bin"
echo $msBuild
2015-07-04 12:10:11 +00:00
export PATH=$msBuild:$PATH
CheckExitCode MSBuild.exe $slnFile //p:Configuration=Debug //p:Platform=x86 //t:Clean //m
CheckExitCode MSBuild.exe $slnFile //p:Configuration=Release //p:Platform=x86 //t:Clean //m
$nuget locals all -clear
$nuget restore $slnFile
CheckExitCode MSBuild.exe $slnFile //p:Configuration=Release //p:Platform=x86 //t:Build //m //p:AllowedReferenceRelatedFileExtensions=.pdb
2015-07-04 12:10:11 +00:00
}
BuildWithXbuild()
{
export MONO_IOMAP=case
CheckExitCode msbuild /p:Configuration=Debug /t:Clean $slnFile
CheckExitCode msbuild /p:Configuration=Release /t:Clean $slnFile
mono $nuget locals all -clear
mono $nuget restore $slnFile
CheckExitCode msbuild /p:Configuration=Release /p:Platform=x86 /t:Build /p:AllowedReferenceRelatedFileExtensions=.pdb $slnFile
2015-07-04 12:10:11 +00:00
}
2018-11-23 07:05:47 +00:00
LintUI()
{
ProgressStart 'ESLint'
2019-07-27 05:33:33 +00:00
CheckExitCode yarn lint
ProgressEnd 'ESLint'
2018-11-23 07:05:47 +00:00
ProgressStart 'Stylelint'
2018-11-23 07:05:47 +00:00
CheckExitCode yarn stylelint
ProgressEnd 'Stylelint'
2018-11-23 07:05:47 +00:00
}
2015-07-04 12:10:11 +00:00
Build()
{
ProgressStart 'Build'
2015-07-04 12:10:11 +00:00
rm -rf $outputFolder
rm -rf $testPackageFolder
2015-07-04 12:10:11 +00:00
if [ $runtime = "dotnet" ] ; then
BuildWithMSBuild
else
BuildWithXbuild
fi
2016-01-16 06:06:33 +00:00
2015-07-04 12:10:11 +00:00
CleanFolder $outputFolder false
2016-01-16 06:06:33 +00:00
2015-07-04 12:10:11 +00:00
echo "Removing Mono.Posix.dll"
rm $outputFolder/Mono.Posix.dll
echo "Adding LICENSE.md"
cp LICENSE.md $outputFolder
ProgressEnd 'Build'
2015-07-04 12:10:11 +00:00
}
RunGulp()
{
ProgressStart 'yarn install'
yarn install --frozen-lockfile
ProgressEnd 'yarn install'
2018-11-23 07:05:47 +00:00
LintUI
2015-07-04 12:10:11 +00:00
ProgressStart 'Running gulp'
2018-11-23 07:05:47 +00:00
CheckExitCode yarn run build --production
ProgressEnd 'Running gulp'
2015-07-04 12:10:11 +00:00
}
PackageMono()
{
ProgressStart 'Creating Mono Package'
2015-07-04 12:10:11 +00:00
rm -rf $outputFolderLinux
2015-07-04 12:10:11 +00:00
echo "Copying Binaries"
cp -r $outputFolder $outputFolderLinux
2015-07-04 12:10:11 +00:00
echo "Removing Service helpers"
rm -f $outputFolderLinux/ServiceUninstall.*
rm -f $outputFolderLinux/ServiceInstall.*
2015-07-04 12:10:11 +00:00
echo "Removing native windows binaries Sqlite, MediaInfo"
rm -f $outputFolderLinux/sqlite3.*
rm -f $outputFolderLinux/MediaInfo.*
2015-07-04 12:10:11 +00:00
echo "Adding Radarr.Core.dll.config (for dllmap)"
cp $sourceFolder/NzbDrone.Core/Radarr.Core.dll.config $outputFolderLinux
2015-07-04 12:10:11 +00:00
2018-11-23 07:05:47 +00:00
echo "Renaming Radarr.Console.exe to Radarr.exe"
rm $outputFolderLinux/Radarr.exe*
for file in $outputFolderLinux/Radarr.Console.exe*; do
2015-07-04 12:10:11 +00:00
mv "$file" "${file//.Console/}"
done
2018-11-23 07:05:47 +00:00
echo "Removing Radarr.Windows"
rm $outputFolderLinux/Radarr.Windows.*
2015-07-04 12:10:11 +00:00
2018-11-23 07:05:47 +00:00
echo "Adding Radarr.Mono to UpdatePackage"
cp $outputFolderLinux/Radarr.Mono.* $updateFolderMono
2016-01-16 06:06:33 +00:00
ProgressEnd 'Creating Mono Package'
2015-07-04 12:10:11 +00:00
}
PackageMacOS()
2015-07-04 12:10:11 +00:00
{
ProgressStart 'Creating MacOS Package'
rm -rf $outputFolderMacOS
mkdir $outputFolderMacOS
echo "Adding Startup script"
cp ./macOS/Radarr $outputFolderMacOS
dos2unix $outputFolderMacOS/Radarr
echo "Copying Binaries"
cp -r $outputFolderLinux/* $outputFolderMacOS
2015-07-04 12:10:11 +00:00
echo "Adding sqlite dylibs"
cp $sourceFolder/Libraries/Sqlite/*.dylib $outputFolderMacOS
2015-07-04 12:10:11 +00:00
echo "Adding MediaInfo dylib"
cp $sourceFolder/Libraries/MediaInfo/*.dylib $outputFolderMacOS
2015-07-04 12:10:11 +00:00
ProgressEnd 'Creating MacOS Package'
2015-07-04 12:10:11 +00:00
}
PackageMacOSApp()
2015-07-04 12:10:11 +00:00
{
ProgressStart 'Creating macOS App Package'
rm -rf $outputFolderMacOSApp
mkdir $outputFolderMacOSApp
cp -r ./macOS/Radarr.app $outputFolderMacOSApp
mkdir -p $outputFolderMacOSApp/Radarr.app/Contents/MacOS
echo "Adding Startup script"
cp ./macOS/Radarr $outputFolderMacOSApp/Radarr.app/Contents/MacOS
dos2unix $outputFolderMacOSApp/Radarr.app/Contents/MacOS/Radarr
echo "Copying Binaries"
cp -r $outputFolderLinux/* $outputFolderMacOSApp/Radarr.app/Contents/MacOS
2015-07-04 12:10:11 +00:00
echo "Adding sqlite dylibs"
cp $sourceFolder/Libraries/Sqlite/*.dylib $outputFolderMacOSApp/Radarr.app/Contents/MacOS
echo "Adding MediaInfo dylib"
cp $sourceFolder/Libraries/MediaInfo/*.dylib $outputFolderMacOSApp/Radarr.app/Contents/MacOS
2015-07-04 12:10:11 +00:00
echo "Removing Update Folder"
rm -r $outputFolderMacOSApp/Radarr.app/Contents/MacOS/Radarr.Update
ProgressEnd 'Creating macOS App Package'
2015-07-04 12:10:11 +00:00
}
PackageTests()
{
ProgressStart 'Creating Test Package'
2015-07-04 12:10:11 +00:00
if [ $runtime = "dotnet" ] ; then
$nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder
2015-07-04 12:10:11 +00:00
else
mono $nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolder
2015-07-04 12:10:11 +00:00
fi
cp ./test.sh $testPackageFolder
2015-07-04 12:10:11 +00:00
rm -f $testPackageFolder/*.log.config
CleanFolder $testPackageFolder true
2018-11-23 07:05:47 +00:00
echo "Adding Radarr.Core.dll.config (for dllmap)"
cp $sourceFolder/NzbDrone.Core/Radarr.Core.dll.config $testPackageFolder
echo "Adding sqlite dylibs"
cp $sourceFolder/Libraries/Sqlite/*.dylib $testPackageFolder
ProgressEnd 'Creating Test Package'
2015-07-04 12:10:11 +00:00
}
CleanupWindowsPackage()
{
ProgressStart 'Cleaning Windows Package'
2018-11-23 07:05:47 +00:00
echo "Removing Radarr.Mono"
rm -f $outputFolder/Radarr.Mono.*
2015-07-04 12:10:11 +00:00
2018-11-23 07:05:47 +00:00
echo "Adding Radarr.Windows to UpdatePackage"
cp $outputFolder/Radarr.Windows.* $updateFolder
ProgressEnd 'Cleaning Windows Package'
}
PackageArtifacts()
{
echo "Creating Artifact Directories"
rm -rf $artifactsFolder
mkdir $artifactsFolder
mkdir $artifactsFolderWindows
mkdir $artifactsFolderMacOS
mkdir $artifactsFolderLinux
mkdir $artifactsFolderWindows/Radarr
mkdir $artifactsFolderMacOS/Radarr
mkdir $artifactsFolderLinux/Radarr
mkdir $artifactsFolderMacOSApp
cp -r $outputFolder/* $artifactsFolderWindows/Radarr
cp -r $outputFolderMacOSApp/* $artifactsFolderMacOSApp
cp -r $outputFolderMacOS/* $artifactsFolderMacOS/Radarr
cp -r $outputFolderLinux/* $artifactsFolderLinux/Radarr
2015-07-04 12:10:11 +00:00
}
# Use mono or .net depending on OS
case "$(uname -s)" in
CYGWIN*|MINGW32*|MINGW64*|MSYS*)
# on windows, use dotnet
runtime="dotnet"
;;
*)
# otherwise use mono
runtime="mono"
;;
esac
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
2018-02-12 16:37:11 +00: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
# Only build backend if we haven't set only-frontend or only-packages
if [ -z "$ONLY_FRONTEND" ] && [ -z "$ONLY_PACKAGES" ];
then
UpdateVersionNumber
Build
PackageTests
fi
# Only build frontend if we haven't set only-backend or only-packages
if [ -z "$ONLY_BACKEND" ] && [ -z "$ONLY_PACKAGES" ];
then
RunGulp
fi
# Only package if we haven't set only-backend or only-frontend
if [ -z "$ONLY_BACKEND" ] && [ -z "$ONLY_FRONTEND" ];
then
PackageMono
PackageMacOS
PackageMacOSApp
CleanupWindowsPackage
PackageArtifacts
fi