1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/build.sh

458 lines
14 KiB
Bash
Raw Normal View History

2015-07-04 14:10:11 +02:00
#! /bin/bash
2018-06-04 03:36:06 +02:00
msBuildVersion='15.0'
2015-07-04 14:10:11 +02:00
outputFolder='./_output'
2019-09-12 22:50:16 +02:00
outputFolderWindows='./_output_windows'
2017-09-18 05:25:28 +02:00
outputFolderLinux='./_output_linux'
outputFolderMacOS='./_output_macos'
outputFolderMacOSApp='./_output_macos_app'
2019-09-12 22:50:16 +02:00
testPackageFolder='./_tests'
testPackageFolderWindows='./_tests_windows'
testPackageFolderLinux='./_tests_linux'
2015-07-04 14:10:11 +02:00
sourceFolder='./src'
2017-09-18 05:25:28 +02:00
slnFile=$sourceFolder/Sonarr.sln
2019-09-12 22:50:16 +02:00
updateSubFolder=Sonarr.Update
2015-07-04 14:10:11 +02:00
nuget='tools/nuget/nuget.exe';
2018-06-04 03:36:06 +02:00
vswhere='tools/vswhere/vswhere.exe';
. ./version.sh
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
}
2017-09-18 05:25:28 +02:00
ProgressStart()
{
echo "##teamcity[blockOpened name='$1']"
echo "##teamcity[progressStart '$1']"
}
ProgressEnd()
{
echo "##teamcity[progressFinish '$1']"
echo "##teamcity[blockClosed name='$1']"
}
UpdateVersionNumber()
{
if [ "$BUILD_NUMBER" != "" ]; then
echo "Updating Version Info"
verMajorMinorRevision=`echo "$buildVersion" | cut -d. -f1,2,3`
verBuild=`echo "${BUILD_NUMBER}" | cut -d. -f4`
BUILD_NUMBER=$verMajorMinorRevision.$verBuild
echo "##teamcity[buildNumber '$BUILD_NUMBER']"
sed -i "s/<AssemblyVersion>[0-9.*]\+<\/AssemblyVersion>/<AssemblyVersion>$BUILD_NUMBER<\/AssemblyVersion>/g" ./src/Directory.Build.props
sed -i "s/<AssemblyConfiguration>[\$()A-Za-z-]\+<\/AssemblyConfiguration>/<AssemblyConfiguration>${BRANCH:-dev}<\/AssemblyConfiguration>/g" ./src/Directory.Build.props
fi
}
CreateReleaseInfo()
{
if [ "$BUILD_NUMBER" != "" ]; then
echo "Create Release Info"
echo -e "# Do Not Edit\nReleaseVersion=$BUILD_NUMBER\nBranch=${BRANCH:-dev}" > $outputFolder/release_info
fi
}
2015-07-04 14:10:11 +02: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 07:49:09 +02:00
echo "Removing dylib files"
find $path -name "*.dylib" -exec rm "{}" \;
2015-07-04 14:10:11 +02:00
echo "Removing Empty folders"
find $path -depth -empty -type d -exec rm -r "{}" \;
}
BuildWithMSBuild()
{
2021-03-20 00:21:04 +02:00
msBuildPath=`$vswhere -latest -products \* -requires Microsoft.Component.MSBuild -find MSBuild\\\\\*\*\\\\Bin\\\\MSBuild.exe`
2020-02-07 22:16:53 +02:00
msBuildPath=${msBuildPath/C:\\/\/c\/}
msBuildPath=${msBuildPath//\\/\/}
msBuildDir=$(dirname "$msBuildPath")
2018-06-04 03:36:06 +02:00
2020-02-07 22:16:53 +02:00
echo $msBuildDir
export PATH=$msBuildDir:$PATH
2018-06-04 03:36:06 +02:00
CheckExitCode MSBuild.exe $slnFile //p:Configuration=Release //p:Platform=x86 //t:Clean //m
$nuget restore $slnFile
CheckExitCode MSBuild.exe $slnFile //p:Configuration=Release //p:Platform=x86 //t:Build //m //p:AllowedReferenceRelatedFileExtensions=.pdb
2015-07-04 14:10:11 +02:00
}
BuildWithXbuild()
{
export MONO_IOMAP=case
CheckExitCode msbuild /t:Clean $slnFile
mono $nuget restore $slnFile
CheckExitCode msbuild /p:Configuration=Release /p:Platform=x86 /t:Build /p:AllowedReferenceRelatedFileExtensions=.pdb $slnFile
2015-07-04 14:10:11 +02:00
}
2017-10-07 06:04:00 +02:00
LintUI()
{
ProgressStart 'ESLint'
2019-07-17 03:39:44 +02:00
CheckExitCode yarn lint
2017-10-07 06:04:00 +02:00
ProgressEnd 'ESLint'
ProgressStart 'Stylelint'
CheckExitCode yarn stylelint
ProgressEnd 'Stylelint'
}
2015-07-04 14:10:11 +02:00
Build()
{
2017-09-18 05:25:28 +02:00
ProgressStart 'Build'
2015-07-04 14:10:11 +02:00
rm -rf $outputFolder
rm -rf $testPackageFolder
2015-07-04 14:10:11 +02:00
if [ $runtime = "dotnet" ] ; then
BuildWithMSBuild
else
BuildWithXbuild
fi
2016-01-16 08:06:33 +02:00
2015-07-04 14:10:11 +02:00
CleanFolder $outputFolder false
2016-01-16 08:06:33 +02:00
2015-07-04 14:10:11 +02:00
echo "Removing Mono.Posix.dll"
rm $outputFolder/Mono.Posix.dll
2017-09-18 05:25:28 +02:00
ProgressEnd 'Build'
2015-07-04 14:10:11 +02:00
}
RunGulp()
{
2018-01-13 04:01:27 +02:00
ProgressStart 'yarn install'
yarn install
ProgressEnd 'yarn install'
2015-07-04 14:10:11 +02:00
2017-10-07 06:04:00 +02:00
LintUI
2017-09-18 05:25:28 +02:00
ProgressStart 'Running gulp'
2017-02-24 02:31:29 +02:00
CheckExitCode yarn run build --production
2017-09-18 05:25:28 +02:00
ProgressEnd 'Running gulp'
2015-07-04 14:10:11 +02:00
}
CreateMdbs()
{
local path=$1
if [ $runtime = "dotnet" ] ; then
2016-01-16 07:49:09 +02:00
local pdbFiles=( $(find $path -name "*.pdb") )
for filename in "${pdbFiles[@]}"
do
if [ -e ${filename%.pdb}.dll ] ; then
tools/pdb2mdb/pdb2mdb.exe ${filename%.pdb}.dll
fi
if [ -e ${filename%.pdb}.exe ] ; then
tools/pdb2mdb/pdb2mdb.exe ${filename%.pdb}.exe
fi
done
2015-07-04 14:10:11 +02:00
fi
}
2019-09-12 22:50:16 +02:00
PatchMono()
{
local path=$1
# Below we deal with some mono incompatibilities with windows-only dotnet core/standard libs
# See: https://github.com/mono/mono/blob/master/tools/nuget-hash-extractor/download.sh
# That list defines assemblies that are prohibited from being loaded from the appdir, instead loading from mono GAC.
# We have debian dependencies to get these installed or facades from mono 5.10+
for assembly in System.IO.Compression System.Runtime.InteropServices.RuntimeInformation System.Net.Http System.Globalization.Extensions System.Text.Encoding.CodePages System.Threading.Overlapped
do
if [ -e $path/$assembly.dll ]; then
if [ -e $sourceFolder/Libraries/Mono/$assembly.dll ]; then
echo "Copy Mono-specific facade $assembly.dll (uses win32 interop)"
cp $sourceFolder/Libraries/Mono/$assembly.dll $path/$assembly.dll
else
echo "Remove $assembly.dll (uses win32 interop)"
rm $path/$assembly.dll
fi
fi
done
# Copy more stable version of Vectors for mono <5.12
if [ -e $path/System.Numerics.Vectors.dll ]; then
packageDir="$HOME/.nuget/packages/system.numerics.vectors/4.5.0"
if [ ! -d "$HOME/.nuget/packages/system.numerics.vectors/4.5.0" ]; then
# May reside in the NuGetFallback folder, which is harder to find
# Download somewhere to get the real cache populated
if [ $runtime = "dotnet" ] ; then
$nuget install System.Numerics.Vectors -Version 4.5.0 -Output ./_temp/System.Numerics.Vectors
else
mono $nuget install System.Numerics.Vectors -Version 4.5.0 -Output ./_temp/System.Numerics.Vectors
fi
rm -rf ./_temp/System.Numerics.Vectors
fi
# Copy the netstandard2.0 version rather than net46
cp "$packageDir/lib/netstandard2.0/System.Numerics.Vectors.dll" $path/
fi
2019-09-12 22:50:16 +02:00
}
2015-07-04 14:10:11 +02:00
PackageMono()
{
2017-09-18 05:25:28 +02:00
ProgressStart 'Creating Mono Package'
rm -rf $outputFolderLinux
echo "Copying Binaries"
cp -r $outputFolder $outputFolderLinux
2015-07-04 14:10:11 +02:00
echo "Creating MDBs"
2017-09-18 05:25:28 +02:00
CreateMdbs $outputFolderLinux
2015-07-04 14:10:11 +02:00
echo "Removing PDBs"
2017-09-18 05:25:28 +02:00
find $outputFolderLinux -name "*.pdb" -exec rm "{}" \;
2015-07-04 14:10:11 +02:00
echo "Removing Service helpers"
2017-09-18 05:25:28 +02:00
rm -f $outputFolderLinux/ServiceUninstall.*
rm -f $outputFolderLinux/ServiceInstall.*
2015-07-04 14:10:11 +02:00
echo "Removing native windows binaries Sqlite, MediaInfo"
2017-09-18 05:25:28 +02:00
rm -f $outputFolderLinux/sqlite3.*
rm -f $outputFolderLinux/MediaInfo.*
2015-07-04 14:10:11 +02:00
2019-09-12 22:50:16 +02:00
PatchMono $outputFolderLinux
2017-09-18 05:25:28 +02:00
echo "Adding Sonarr.Core.dll.config (for dllmap)"
cp $sourceFolder/NzbDrone.Core/Sonarr.Core.dll.config $outputFolderLinux
2015-07-04 14:10:11 +02:00
# Remove Http binding redirect by renaming it
# We don't need this anymore once our minimum mono version is 5.10
sed -i "s/System.Net.Http/System.Net.Http.Mono/g" $outputFolderLinux/Sonarr.Console.exe.config
2019-09-12 22:50:16 +02:00
2017-09-18 05:25:28 +02:00
echo "Renaming Sonarr.Console.exe to Sonarr.exe"
rm $outputFolderLinux/Sonarr.exe*
for file in $outputFolderLinux/Sonarr.Console.exe*; do
2015-07-04 14:10:11 +02:00
mv "$file" "${file//.Console/}"
done
2017-09-18 05:25:28 +02:00
echo "Removing Sonarr.Windows"
rm $outputFolderLinux/Sonarr.Windows.*
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
echo "Adding Sonarr.Mono to UpdatePackage"
2019-09-12 22:50:16 +02:00
cp $outputFolderLinux/Sonarr.Mono.* $outputFolderLinux/$updateSubFolder/
2016-01-16 08:06:33 +02:00
2017-09-18 05:25:28 +02:00
ProgressEnd 'Creating Mono Package'
2015-07-04 14:10:11 +02:00
}
2017-09-18 05:25:28 +02:00
PackageMacOS()
2015-07-04 14:10:11 +02:00
{
2017-09-18 05:25:28 +02:00
ProgressStart 'Creating MacOS Package'
rm -rf $outputFolderMacOS
mkdir $outputFolderMacOS
2017-09-18 05:25:28 +02:00
echo "Copying Binaries"
cp -r $outputFolderLinux/* $outputFolderMacOS
2015-07-04 14:10:11 +02:00
echo "Adding Sonarr Launcher"
cp ./distribution/osx/Launcher/dist/Launcher $outputFolderMacOS/
mv $outputFolderMacOS/Sonarr.exe $outputFolderMacOS/Sonarr.exe.bak
mv $outputFolderMacOS/Launcher $outputFolderMacOS/Sonarr
mv $outputFolderMacOS/Sonarr.exe.bak $outputFolderMacOS/Sonarr.exe
chmod +x $outputFolderMacOS/Sonarr
echo "Adding Sonarr.Update Launcher"
cp ./distribution/osx/Launcher/dist/Launcher $outputFolderMacOS/Sonarr.Update/
mv $outputFolderMacOS/Sonarr.Update/Sonarr.Update.exe $outputFolderMacOS/Sonarr.Update/Sonarr.Update.exe.bak
mv $outputFolderMacOS/Sonarr.Update/Launcher $outputFolderMacOS/Sonarr.Update/Sonarr.Update
mv $outputFolderMacOS/Sonarr.Update/Sonarr.Update.exe.bak $outputFolderMacOS/Sonarr.Update/Sonarr.Update.exe
chmod +x $outputFolderMacOS/Sonarr.Update/Sonarr.Update
2015-07-04 14:10:11 +02:00
echo "Adding sqlite dylibs"
2017-09-18 05:25:28 +02:00
cp $sourceFolder/Libraries/Sqlite/*.dylib $outputFolderMacOS
2015-07-04 14:10:11 +02:00
echo "Adding MediaInfo dylib"
2017-09-18 05:25:28 +02:00
cp $sourceFolder/Libraries/MediaInfo/*.dylib $outputFolderMacOS
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
ProgressEnd 'Creating MacOS Package'
2015-07-04 14:10:11 +02:00
}
2017-09-18 05:25:28 +02:00
PackageMacOSApp()
2015-07-04 14:10:11 +02:00
{
2017-09-18 05:25:28 +02:00
ProgressStart 'Creating macOS App Package'
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
rm -rf $outputFolderMacOSApp
mkdir $outputFolderMacOSApp
cp -r ./distribution/osx/Sonarr.app $outputFolderMacOSApp
2017-09-18 05:25:28 +02:00
mkdir -p $outputFolderMacOSApp/Sonarr.app/Contents/MacOS
2015-07-04 14:10:11 +02:00
echo "Adding Sonarr Launcher"
cp ./distribution/osx/Launcher/dist/Launcher $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/
mv $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/Launcher $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/Sonarr
chmod +x $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/Sonarr
2017-09-18 05:25:28 +02:00
echo "Copying Binaries"
mkdir -p $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/bin
cp -r $outputFolderLinux/* $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/bin/
2017-09-18 05:25:28 +02:00
echo "Adding sqlite dylibs"
cp $sourceFolder/Libraries/Sqlite/*.dylib $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/bin/
2017-09-18 05:25:28 +02:00
echo "Adding MediaInfo dylib"
cp $sourceFolder/Libraries/MediaInfo/*.dylib $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/bin/
2017-09-18 05:25:28 +02:00
echo "Removing Update Folder"
rm -r $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/bin/Sonarr.Update
echo "# Do Not Edit\nPackageVersion=${BUILD_NUMBER}\nPackageAuthor=[Team Sonarr](https://sonarr.tv)\nReleaseVersion=${BUILD_NUMBER}\nUpdateMethod=$PackageUpdater\nBranch=${Branch:-master}" > $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/package_info
2017-09-18 05:25:28 +02:00
ProgressEnd 'Creating macOS App Package'
2015-07-04 14:10:11 +02:00
}
2019-09-12 22:50:16 +02:00
PackageTestsMono()
2015-07-04 14:10:11 +02:00
{
2019-09-12 22:50:16 +02:00
ProgressStart 'Creating Mono Test Package'
rm -rf $testPackageFolderLinux
echo "Copying Binaries"
cp -r $testPackageFolder $testPackageFolderLinux
2017-09-18 05:25:28 +02:00
2015-07-04 14:10:11 +02:00
if [ $runtime = "dotnet" ] ; then
2019-09-12 22:50:16 +02:00
$nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolderLinux
2015-07-04 14:10:11 +02:00
else
2019-09-12 22:50:16 +02:00
mono $nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolderLinux
2015-07-04 14:10:11 +02:00
fi
2019-09-12 22:50:16 +02:00
echo "Creating MDBs"
CreateMdbs $testPackageFolderLinux
2015-07-04 14:10:11 +02:00
2019-09-12 22:50:16 +02:00
echo "Removing PDBs"
find $testPackageFolderLinux -name "*.pdb" -exec rm "{}" \;
2015-07-04 14:10:11 +02:00
2019-09-12 22:50:16 +02:00
PatchMono $testPackageFolderLinux
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
echo "Adding Sonarr.Core.dll.config (for dllmap)"
2019-09-12 22:50:16 +02:00
cp $sourceFolder/NzbDrone.Core/Sonarr.Core.dll.config $testPackageFolderLinux
# Remove Http binding redirect by renaming it
# We don't need this anymore once our minimum mono version is 5.10
sed -i "s/System.Net.Http/System.Net.Http.Mono/g" $testPackageFolderLinux/Sonarr.Common.Test.dll.config
cp ./test.sh $testPackageFolderLinux/
dos2unix $testPackageFolderLinux/test.sh
echo "Removing Sonarr.Windows"
rm $testPackageFolderLinux/Sonarr.Windows.*
2015-07-04 14:10:11 +02:00
2019-09-12 22:50:16 +02:00
rm -f $testPackageFolderLinux/*.log.config
CleanFolder $testPackageFolderLinux true
ProgressEnd 'Creating Linux Test Package'
2015-07-04 14:10:11 +02:00
}
2019-09-12 22:50:16 +02:00
PackageTestsWindows()
2015-07-04 14:10:11 +02:00
{
2019-09-12 22:50:16 +02:00
ProgressStart 'Creating Windows Test Package'
rm -rf $testPackageFolderWindows
echo "Copying Binaries"
cp -r $testPackageFolder $testPackageFolderWindows
if [ $runtime = "dotnet" ] ; then
$nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolderWindows
else
mono $nuget install NUnit.ConsoleRunner -Version 3.10.0 -Output $testPackageFolderWindows
fi
cp ./test.sh $testPackageFolderWindows
echo "Removing Sonarr.Mono"
rm -f $testPackageFolderWindows/Sonarr.Mono.*
rm -f $testPackageFolderWindows/*.log.config
CleanFolder $testPackageFolderWindows true
ProgressEnd 'Creating Windows Test Package'
}
PackageWindows()
{
ProgressStart 'Creating Windows Package'
rm -rf $outputFolderWindows
echo "Copying Binaries"
cp -r $outputFolder $outputFolderWindows
2017-09-18 05:25:28 +02:00
echo "Removing Sonarr.Mono"
2019-09-12 22:50:16 +02:00
rm -f $outputFolderWindows/Sonarr.Mono.*
2017-09-18 05:25:28 +02:00
echo "Adding Sonarr.Windows to UpdatePackage"
2019-09-12 22:50:16 +02:00
cp $outputFolderWindows/Sonarr.Windows.* $outputFolderWindows/$updateSubFolder/
2015-07-04 14:10:11 +02:00
2019-09-12 22:50:16 +02:00
ProgressEnd 'Creating Windows Package'
2017-09-18 05:25:28 +02:00
}
PublishArtifacts()
{
2018-01-26 21:30:13 +02:00
ProgressStart 'Publishing Artifacts'
# Tests
2019-09-12 22:50:16 +02:00
echo "##teamcity[publishArtifacts '$testPackageFolderWindows/** => tests.windows.zip']"
echo "##teamcity[publishArtifacts '$testPackageFolderLinux/** => tests.linux.zip']"
2018-01-26 21:30:13 +02:00
# Releases
2019-09-12 22:50:16 +02:00
echo "##teamcity[publishArtifacts '$outputFolderWindows/** => Sonarr.$BRANCH.$BUILD_NUMBER.windows.zip!Sonarr']"
2017-09-18 05:25:28 +02:00
echo "##teamcity[publishArtifacts '$outputFolderLinux/** => Sonarr.$BRANCH.$BUILD_NUMBER.linux.tar.gz!Sonarr']"
echo "##teamcity[publishArtifacts '$outputFolderMacOS/** => Sonarr.$BRANCH.$BUILD_NUMBER.macos.tar.gz!Sonarr']"
echo "##teamcity[publishArtifacts '$outputFolderMacOSApp/** => Sonarr.$BRANCH.$BUILD_NUMBER.macos.zip']"
2018-01-26 21:30:13 +02:00
# Debian Package
echo "##teamcity[publishArtifacts 'distribution/** => distribution.zip']"
ProgressEnd 'Publishing Artifacts'
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
runtime="dotnet"
;;
*)
# otherwise use mono
runtime="mono"
;;
esac
UpdateVersionNumber
2015-07-04 14:10:11 +02:00
Build
CreateReleaseInfo
2015-07-04 14:10:11 +02:00
RunGulp
PackageMono
2017-09-18 05:25:28 +02:00
PackageMacOS
PackageMacOSApp
2019-09-12 22:50:16 +02:00
PackageTestsMono
PackageTestsWindows
PackageWindows
2017-09-18 05:25:28 +02:00
PublishArtifacts