1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-26 17:57:43 +00:00
Sonarr/build.sh

360 lines
10 KiB
Bash
Raw Normal View History

2015-07-04 12:10:11 +00:00
#! /bin/bash
2018-06-04 01:36:06 +00:00
msBuildVersion='15.0'
2015-07-04 12:10:11 +00:00
outputFolder='./_output'
2017-09-18 03:25:28 +00:00
outputFolderLinux='./_output_linux'
outputFolderMacOS='./_output_macos'
outputFolderMacOSApp='./_output_macos_app'
2015-07-04 12:10:11 +00:00
testPackageFolder='./_tests/'
2016-01-15 08:27:59 +00:00
testSearchPattern='*.Test/bin/x86/Release'
2015-07-04 12:10:11 +00:00
sourceFolder='./src'
2017-09-18 03:25:28 +00:00
slnFile=$sourceFolder/Sonarr.sln
updateFolder=$outputFolder/Sonarr.Update
updateFolderMono=$outputFolderLinux/Sonarr.Update
2015-07-04 12:10:11 +00:00
nuget='tools/nuget/nuget.exe';
2018-06-04 01:36:06 +00:00
vswhere='tools/vswhere/vswhere.exe';
. ./version.sh
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
}
2017-09-18 03:25:28 +00: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']"
2018-11-23 17:59:41 +00:00
sed -i "s/^[[]assembly: Assembly\(File\|Informational\)\?Version[(]\"[0-9.*]\+\"[)]/[assembly: Assembly\1Version(\"$BUILD_NUMBER\")/g" ./src/NzbDrone*/Properties/AssemblyInfo.cs ./src/Sonarr*/Properties/AssemblyInfo.cs ./src/ServiceHelpers/*/Properties/AssemblyInfo.cs ./src/Common/CommonVersionInfo.cs
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 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()
{
2018-06-04 01:36:06 +00:00
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
2018-06-04 01:36:06 +00: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 12:10:11 +00:00
}
BuildWithXbuild()
{
export MONO_IOMAP=case
CheckExitCode xbuild /t:Clean $slnFile
mono $nuget restore $slnFile
CheckExitCode xbuild /p:Configuration=Release /p:Platform=x86 /t:Build /p:AllowedReferenceRelatedFileExtensions=.pdb $slnFile
2015-07-04 12:10:11 +00:00
}
2017-10-07 04:04:00 +00:00
LintUI()
{
ProgressStart 'ESLint'
CheckExitCode yarn eslint
ProgressEnd 'ESLint'
ProgressStart 'Stylelint'
CheckExitCode yarn stylelint
ProgressEnd 'Stylelint'
}
2015-07-04 12:10:11 +00:00
Build()
{
2017-09-18 03:25:28 +00:00
ProgressStart 'Build'
2015-07-04 12:10:11 +00:00
rm -rf $outputFolder
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
2017-09-18 03:25:28 +00:00
ProgressEnd 'Build'
2015-07-04 12:10:11 +00:00
}
RunGulp()
{
2018-01-13 02:01:27 +00:00
ProgressStart 'yarn install'
yarn install
ProgressEnd 'yarn install'
2015-07-04 12:10:11 +00:00
2017-10-07 04:04:00 +00:00
LintUI
2017-09-18 03:25:28 +00:00
ProgressStart 'Running gulp'
2017-02-24 00:31:29 +00:00
CheckExitCode yarn run build --production
2017-09-18 03:25:28 +00:00
ProgressEnd 'Running gulp'
2015-07-04 12:10:11 +00:00
}
CreateMdbs()
{
local path=$1
if [ $runtime = "dotnet" ] ; then
2016-01-16 05:49:09 +00: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 12:10:11 +00:00
fi
}
PackageMono()
{
2017-09-18 03:25:28 +00:00
ProgressStart 'Creating Mono Package'
rm -rf $outputFolderLinux
echo "Copying Binaries"
cp -r $outputFolder $outputFolderLinux
2015-07-04 12:10:11 +00:00
echo "Creating MDBs"
2017-09-18 03:25:28 +00:00
CreateMdbs $outputFolderLinux
2015-07-04 12:10:11 +00:00
echo "Removing PDBs"
2017-09-18 03:25:28 +00:00
find $outputFolderLinux -name "*.pdb" -exec rm "{}" \;
2015-07-04 12:10:11 +00:00
echo "Removing Service helpers"
2017-09-18 03:25:28 +00:00
rm -f $outputFolderLinux/ServiceUninstall.*
rm -f $outputFolderLinux/ServiceInstall.*
2015-07-04 12:10:11 +00:00
echo "Removing native windows binaries Sqlite, MediaInfo"
2017-09-18 03:25:28 +00:00
rm -f $outputFolderLinux/sqlite3.*
rm -f $outputFolderLinux/MediaInfo.*
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
echo "Adding Sonarr.Core.dll.config (for dllmap)"
cp $sourceFolder/NzbDrone.Core/Sonarr.Core.dll.config $outputFolderLinux
2015-07-04 12:10:11 +00:00
echo "Adding CurlSharp.dll.config (for dllmap)"
2017-09-18 03:25:28 +00:00
cp $sourceFolder/NzbDrone.Common/CurlSharp.dll.config $outputFolderLinux
2015-07-04 12:10:11 +00:00
echo "Adding unix System.Runtime.InteropServices.RuntimeInformation.dll (for SharpRaven)"
cp $sourceFolder/packages/System.Runtime.InteropServices.RuntimeInformation.4.3.0/runtimes/unix/lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll $outputFolderLinux
cp $sourceFolder/packages/System.Runtime.InteropServices.RuntimeInformation.4.3.0/runtimes/unix/lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll $outputFolderLinux/Sonarr.Update
2017-09-18 03:25:28 +00:00
echo "Renaming Sonarr.Console.exe to Sonarr.exe"
rm $outputFolderLinux/Sonarr.exe*
for file in $outputFolderLinux/Sonarr.Console.exe*; do
2015-07-04 12:10:11 +00:00
mv "$file" "${file//.Console/}"
done
2017-09-18 03:25:28 +00:00
echo "Removing Sonarr.Windows"
rm $outputFolderLinux/Sonarr.Windows.*
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
echo "Adding Sonarr.Mono to UpdatePackage"
cp $outputFolderLinux/Sonarr.Mono.* $updateFolderMono
2016-01-16 06:06:33 +00:00
2017-09-18 03:25:28 +00:00
ProgressEnd 'Creating Mono Package'
2015-07-04 12:10:11 +00:00
}
2017-09-18 03:25:28 +00:00
PackageMacOS()
2015-07-04 12:10:11 +00:00
{
2017-09-18 03:25:28 +00:00
ProgressStart 'Creating MacOS Package'
rm -rf $outputFolderMacOS
mkdir $outputFolderMacOS
echo "Adding Startup script"
cp ./macOS/Sonarr $outputFolderMacOS
dos2unix $outputFolderMacOS/Sonarr
echo "Copying Binaries"
cp -r $outputFolderLinux/* $outputFolderMacOS
2015-07-04 12:10:11 +00:00
echo "Adding sqlite dylibs"
2017-09-18 03:25:28 +00:00
cp $sourceFolder/Libraries/Sqlite/*.dylib $outputFolderMacOS
2015-07-04 12:10:11 +00:00
echo "Adding MediaInfo dylib"
2017-09-18 03:25:28 +00:00
cp $sourceFolder/Libraries/MediaInfo/*.dylib $outputFolderMacOS
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
ProgressEnd 'Creating MacOS Package'
2015-07-04 12:10:11 +00:00
}
2017-09-18 03:25:28 +00:00
PackageMacOSApp()
2015-07-04 12:10:11 +00:00
{
2017-09-18 03:25:28 +00:00
ProgressStart 'Creating macOS App Package'
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
rm -rf $outputFolderMacOSApp
mkdir $outputFolderMacOSApp
cp -r ./macOS/Sonarr.app $outputFolderMacOSApp
mkdir -p $outputFolderMacOSApp/Sonarr.app/Contents/MacOS
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
echo "Adding Startup script"
cp ./macOS/Sonarr $outputFolderMacOSApp/Sonarr.app/Contents/MacOS
dos2unix $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/Sonarr
echo "Copying Binaries"
cp -r $outputFolderLinux/* $outputFolderMacOSApp/Sonarr.app/Contents/MacOS
echo "Adding sqlite dylibs"
cp $sourceFolder/Libraries/Sqlite/*.dylib $outputFolderMacOSApp/Sonarr.app/Contents/MacOS
echo "Adding MediaInfo dylib"
cp $sourceFolder/Libraries/MediaInfo/*.dylib $outputFolderMacOSApp/Sonarr.app/Contents/MacOS
echo "Removing Update Folder"
rm -r $outputFolderMacOSApp/Sonarr.app/Contents/MacOS/Sonarr.Update
ProgressEnd 'Creating macOS App Package'
2015-07-04 12:10:11 +00:00
}
PackageTests()
{
2017-09-18 03:25:28 +00:00
ProgressStart 'Creating Test Package'
2015-07-04 12:10:11 +00:00
rm -rf $testPackageFolder
mkdir $testPackageFolder
2016-01-15 08:27:59 +00:00
find $sourceFolder -path $testSearchPattern -exec cp -r -u -T "{}" $testPackageFolder \;
2015-07-04 12:10:11 +00:00
if [ $runtime = "dotnet" ] ; then
2016-04-02 02:19:32 +00:00
$nuget install NUnit.ConsoleRunner -Version 3.2.0 -Output $testPackageFolder
2015-07-04 12:10:11 +00:00
else
2016-04-02 02:19:32 +00:00
mono $nuget install NUnit.ConsoleRunner -Version 3.2.0 -Output $testPackageFolder
2015-07-04 12:10:11 +00:00
fi
cp $outputFolder/*.dll $testPackageFolder
2018-01-26 19:30:13 +00:00
cp ./test.sh $testPackageFolder
2015-07-04 12:10:11 +00:00
echo "Creating MDBs for tests"
CreateMdbs $testPackageFolder
rm -f $testPackageFolder/*.log.config
CleanFolder $testPackageFolder true
2017-09-18 03:25:28 +00:00
echo "Adding Sonarr.Core.dll.config (for dllmap)"
cp $sourceFolder/NzbDrone.Core/Sonarr.Core.dll.config $testPackageFolder
2015-07-04 12:10:11 +00:00
echo "Adding CurlSharp.dll.config (for dllmap)"
cp $sourceFolder/NzbDrone.Common/CurlSharp.dll.config $testPackageFolder
echo "Copying CurlSharp libraries"
cp $sourceFolder/ExternalModules/CurlSharp/libs/i386/* $testPackageFolder
2017-09-18 03:25:28 +00:00
ProgressEnd 'Creating Test Package'
2015-07-04 12:10:11 +00:00
}
CleanupWindowsPackage()
{
2017-09-18 03:25:28 +00:00
ProgressStart 'Cleaning Windows Package'
echo "Removing Sonarr.Mono"
rm -f $outputFolder/Sonarr.Mono.*
echo "Adding Sonarr.Windows to UpdatePackage"
cp $outputFolder/Sonarr.Windows.* $updateFolder
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
ProgressEnd 'Cleaning Windows Package'
}
PublishArtifacts()
{
2018-01-26 19:30:13 +00:00
ProgressStart 'Publishing Artifacts'
# Tests
2017-09-18 03:25:28 +00:00
echo "##teamcity[publishArtifacts '_tests/** => tests.zip']"
2018-01-26 19:30:13 +00:00
# Releases
2017-09-18 03:25:28 +00:00
echo "##teamcity[publishArtifacts '$outputFolder/** => Sonarr.$BRANCH.$BUILD_NUMBER.windows.zip!Sonarr']"
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 19:30:13 +00:00
# Debian Package
echo "##teamcity[publishArtifacts 'distribution/** => distribution.zip']"
ProgressEnd 'Publishing Artifacts'
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
UpdateVersionNumber
2015-07-04 12:10:11 +00:00
Build
CreateReleaseInfo
2015-07-04 12:10:11 +00:00
RunGulp
PackageMono
2017-09-18 03:25:28 +00:00
PackageMacOS
PackageMacOSApp
2015-07-04 12:10:11 +00:00
PackageTests
CleanupWindowsPackage
2017-09-18 03:25:28 +00:00
PublishArtifacts