2021-07-30 06:47:53 +02:00
#! /usr/bin/env bash
set -e
outputFolder = '_output'
testPackageFolder = '_tests'
artifactsFolder = "_artifacts" ;
2023-11-26 06:23:10 +02:00
framework = " ${ FRAMEWORK : =net6.0 } "
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
ProgressStart( )
{
2023-11-26 06:23:10 +02:00
echo " ::group:: $1 "
2021-07-30 06:47:53 +02:00
echo " Start ' $1 ' "
2017-09-18 05:25:28 +02:00
}
ProgressEnd( )
{
2021-07-30 06:47:53 +02:00
echo " Finish ' $1 ' "
2023-11-26 06:23:10 +02:00
echo "::endgroup::"
2017-09-18 05:25:28 +02:00
}
2018-11-20 22:13:44 +02:00
UpdateVersionNumber( )
{
2022-08-20 19:29:51 +02:00
if [ " $SONARR_VERSION " != "" ] ; then
echo " Updating version info to: $SONARR_VERSION "
sed -i'' -e " s/<AssemblyVersion>[0-9.*]\+<\/AssemblyVersion>/<AssemblyVersion> $SONARR_VERSION <\/AssemblyVersion>/g " src/Directory.Build.props
2022-08-21 00:54:58 +02:00
sed -i'' -e " s/<AssemblyConfiguration>[\$()A-Za-z-]\+<\/AssemblyConfiguration>/<AssemblyConfiguration> ${ BRANCH } <\/AssemblyConfiguration>/g " src/Directory.Build.props
2022-08-20 19:29:51 +02:00
sed -i'' -e " s/<string>10.0.0.0<\/string>/<string> $SONARR_VERSION <\/string>/g " distribution/macOS/Sonarr.app/Contents/Info.plist
2018-11-20 22:13:44 +02:00
fi
}
2022-12-03 01:58:39 +02:00
EnableExtraPlatformsInSDK( )
2015-07-04 14:10:11 +02:00
{
2022-12-03 01:58:39 +02:00
BUNDLEDVERSIONS = " ${ SDK_PATH } /Microsoft.NETCoreSdk.BundledVersions.props "
if grep -q freebsd-x64 " $BUNDLEDVERSIONS " ; then
echo "Extra platforms already enabled"
else
echo "Enabling extra platform support"
sed -i.ORI 's/osx-x64/osx-x64;freebsd-x64/' " $BUNDLEDVERSIONS "
fi
}
2015-07-04 14:10:11 +02:00
2022-12-03 01:58:39 +02:00
EnableExtraPlatforms( )
{
2021-07-30 06:47:53 +02:00
if grep -qv freebsd-x64 src/Directory.Build.props; then
sed -i'' -e "s^<RuntimeIdentifiers>\(.*\)</RuntimeIdentifiers>^<RuntimeIdentifiers>\1;freebsd-x64</RuntimeIdentifiers>^g" src/Directory.Build.props
2015-07-04 14:10:11 +02:00
fi
}
2017-10-07 06:04:00 +02:00
LintUI( )
{
ProgressStart 'ESLint'
2021-07-30 06:47:53 +02:00
yarn lint
2017-10-07 06:04:00 +02:00
ProgressEnd 'ESLint'
ProgressStart 'Stylelint'
2021-07-30 06:47:53 +02:00
yarn stylelint
2017-10-07 06:04:00 +02:00
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
2019-08-16 20:39:35 +02:00
rm -rf $testPackageFolder
2015-07-04 14:10:11 +02:00
2021-07-30 06:47:53 +02:00
slnFile = src/Sonarr.sln
if [ $os = "windows" ] ; then
platform = Windows
2015-07-04 14:10:11 +02:00
else
2021-07-30 06:47:53 +02:00
platform = Posix
2015-07-04 14:10:11 +02:00
fi
2016-01-16 08:06:33 +02:00
2021-07-30 06:47:53 +02:00
dotnet clean $slnFile -c Debug
dotnet clean $slnFile -c Release
2016-01-16 08:06:33 +02:00
2021-07-30 06:47:53 +02:00
if [ [ -z " $RID " || -z " $FRAMEWORK " ] ] ;
then
dotnet msbuild -restore $slnFile -p:Configuration= Release -p:Platform= $platform -t:PublishAllRids
else
dotnet msbuild -restore $slnFile -p:Configuration= Release -p:Platform= $platform -p:RuntimeIdentifiers= $RID -t:PublishAllRids
fi
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
ProgressEnd 'Build'
2015-07-04 14:10:11 +02:00
}
2021-07-30 06:47:53 +02:00
YarnInstall( )
2015-07-04 14:10:11 +02:00
{
2018-01-13 04:01:27 +02:00
ProgressStart 'yarn install'
2021-07-30 06:47:53 +02:00
yarn install --frozen-lockfile --network-timeout 120000
2018-01-13 04:01:27 +02:00
ProgressEnd 'yarn install'
2015-07-04 14:10:11 +02:00
}
2021-07-30 06:47:53 +02:00
RunWebpack( )
2015-07-04 14:10:11 +02:00
{
2021-07-30 06:47:53 +02:00
ProgressStart 'Running webpack'
yarn run build --env production
ProgressEnd 'Running webpack'
2015-07-04 14:10:11 +02:00
}
2021-07-30 06:47:53 +02:00
PackageFiles( )
2019-09-12 22:50:16 +02:00
{
2021-07-30 06:47:53 +02:00
local folder = " $1 "
local framework = " $2 "
local runtime = " $3 "
rm -rf $folder
mkdir -p $folder
cp -r $outputFolder /$framework /$runtime /publish/* $folder
cp -r $outputFolder /Sonarr.Update/$framework /$runtime /publish $folder /Sonarr.Update
2022-08-23 07:11:34 +02:00
if [ " $FRONTEND " = "YES" ] ;
then
cp -r $outputFolder /UI $folder
fi
2021-07-30 06:47:53 +02:00
echo "Adding LICENSE"
cp LICENSE.md $folder
2019-09-12 22:50:16 +02:00
}
2021-07-30 06:47:53 +02:00
PackageLinux( )
2015-07-04 14:10:11 +02:00
{
2021-07-30 06:47:53 +02:00
local framework = " $1 "
local runtime = " $2 "
2017-09-18 05:25:28 +02:00
2021-07-30 06:47:53 +02:00
ProgressStart " Creating $runtime Package for $framework "
2017-09-18 05:25:28 +02:00
2021-07-30 06:47:53 +02:00
local folder = $artifactsFolder /$runtime /$framework /Sonarr
2015-07-04 14:10:11 +02:00
2021-07-30 06:47:53 +02:00
PackageFiles " $folder " " $framework " " $runtime "
2015-07-04 14:10:11 +02:00
echo "Removing Service helpers"
2021-07-30 06:47:53 +02:00
rm -f $folder /ServiceUninstall.*
rm -f $folder /ServiceInstall.*
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
echo "Removing Sonarr.Windows"
2021-07-30 06:47:53 +02:00
rm $folder /Sonarr.Windows.*
2015-07-04 14:10:11 +02:00
2017-09-18 05:25:28 +02:00
echo "Adding Sonarr.Mono to UpdatePackage"
2021-07-30 06:47:53 +02:00
cp $folder /Sonarr.Mono.* $folder /Sonarr.Update
2023-11-26 06:23:10 +02:00
if [ " $framework " = " $framework " ] ; then
2021-07-30 06:47:53 +02:00
cp $folder /Mono.Posix.NETStandard.* $folder /Sonarr.Update
cp $folder /libMonoPosixHelper.* $folder /Sonarr.Update
fi
2016-01-16 08:06:33 +02:00
2021-07-30 06:47:53 +02:00
ProgressEnd " Creating $runtime Package for $framework "
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
{
2021-07-30 06:47:53 +02:00
local framework = " $1 "
2021-11-12 21:45:54 +02:00
local runtime = " $2 "
2021-12-25 02:29:53 +02:00
2021-11-12 21:45:54 +02:00
ProgressStart " Creating $runtime Package for $framework "
2015-07-04 14:10:11 +02:00
2021-11-12 21:45:54 +02:00
local folder = $artifactsFolder /$runtime /$framework /Sonarr
2020-05-07 11:59:03 +02:00
2021-11-12 21:45:54 +02:00
PackageFiles " $folder " " $framework " " $runtime "
2020-05-07 11:59:03 +02:00
2021-07-30 06:47:53 +02:00
echo "Removing Service helpers"
rm -f $folder /ServiceUninstall.*
rm -f $folder /ServiceInstall.*
2015-07-04 14:10:11 +02:00
2021-07-30 06:47:53 +02:00
echo "Removing Sonarr.Windows"
rm $folder /Sonarr.Windows.*
echo "Adding Sonarr.Mono to UpdatePackage"
cp $folder /Sonarr.Mono.* $folder /Sonarr.Update
2023-11-26 06:23:10 +02:00
if [ " $framework " = " $framework " ] ; then
2021-07-30 06:47:53 +02:00
cp $folder /Mono.Posix.NETStandard.* $folder /Sonarr.Update
cp $folder /libMonoPosixHelper.* $folder /Sonarr.Update
fi
2015-07-04 14:10:11 +02:00
2021-12-25 02:29:53 +02:00
ProgressEnd " Creating $runtime Package for $framework "
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
{
2021-07-30 06:47:53 +02:00
local framework = " $1 "
2021-11-12 21:45:54 +02:00
local runtime = " $2 "
2021-12-25 02:29:53 +02:00
2021-11-12 21:45:54 +02:00
ProgressStart " Creating $runtime App Package for $framework "
2015-07-04 14:10:11 +02:00
2021-11-12 21:45:54 +02:00
local folder = $artifactsFolder /$runtime -app/$framework
2015-07-04 14:10:11 +02:00
2021-07-30 06:47:53 +02:00
rm -rf $folder
mkdir -p $folder
2021-12-25 02:29:53 +02:00
cp -r distribution/macOS/Sonarr.app $folder
2021-07-30 06:47:53 +02:00
mkdir -p $folder /Sonarr.app/Contents/MacOS
2017-09-18 05:25:28 +02:00
echo "Copying Binaries"
2021-11-12 21:45:54 +02:00
cp -r $artifactsFolder /$runtime /$framework /Sonarr/* $folder /Sonarr.app/Contents/MacOS
2017-09-18 05:25:28 +02:00
echo "Removing Update Folder"
2021-07-30 06:47:53 +02:00
rm -r $folder /Sonarr.app/Contents/MacOS/Sonarr.Update
2017-09-18 05:25:28 +02:00
2021-12-25 02:29:53 +02:00
ProgressEnd " Creating $runtime App Package for $framework "
2015-07-04 14:10:11 +02:00
}
2019-09-12 22:50:16 +02:00
PackageWindows( )
{
2021-07-30 06:47:53 +02:00
local framework = " $1 "
local runtime = " $2 "
2021-12-25 02:29:53 +02:00
2021-07-30 06:47:53 +02:00
ProgressStart " Creating Windows Package for $framework "
2019-09-12 22:50:16 +02:00
2021-07-30 06:47:53 +02:00
local folder = $artifactsFolder /$runtime /$framework /Sonarr
2021-12-25 02:29:53 +02:00
2021-07-30 06:47:53 +02:00
PackageFiles " $folder " " $framework " " $runtime "
cp -r $outputFolder /$framework -windows/$runtime /publish/* $folder
2017-09-18 05:25:28 +02:00
echo "Removing Sonarr.Mono"
2021-07-30 06:47:53 +02:00
rm -f $folder /Sonarr.Mono.*
rm -f $folder /Mono.Posix.NETStandard.*
rm -f $folder /libMonoPosixHelper.*
2017-09-18 05:25:28 +02:00
echo "Adding Sonarr.Windows to UpdatePackage"
2021-07-30 06:47:53 +02:00
cp $folder /Sonarr.Windows.* $folder /Sonarr.Update
2015-07-04 14:10:11 +02:00
2021-12-25 02:29:53 +02:00
ProgressEnd " Creating Windows Package for $framework "
2017-09-18 05:25:28 +02:00
}
2021-07-30 06:47:53 +02:00
Package( )
{
local framework = " $1 "
local runtime = " $2 "
local SPLIT
IFS = '-' read -ra SPLIT <<< " $runtime "
case " ${ SPLIT [0] } " in
linux| freebsd*)
PackageLinux " $framework " " $runtime "
; ;
win)
PackageWindows " $framework " " $runtime "
; ;
osx)
2021-11-12 21:45:54 +02:00
PackageMacOS " $framework " " $runtime "
2021-07-30 06:47:53 +02:00
; ;
esac
}
PackageTests( )
2017-09-18 05:25:28 +02:00
{
2021-07-30 06:47:53 +02:00
local framework = " $1 "
local runtime = " $2 "
2018-01-26 21:30:13 +02:00
2021-12-25 02:29:53 +02:00
ProgressStart " Creating $runtime Test Package for $framework "
2021-07-30 06:47:53 +02:00
cp test.sh " $testPackageFolder / $framework / $runtime /publish "
2018-01-26 21:30:13 +02:00
2021-07-30 06:47:53 +02:00
rm -f $testPackageFolder /$framework /$runtime /*.log.config
2021-12-25 02:29:53 +02:00
ProgressEnd " Creating $runtime Test Package for $framework "
}
UploadTestArtifacts( )
{
local framework = " $1 "
ProgressStart 'Publishing Test Artifacts'
# Tests
for dir in $testPackageFolder /$framework /*
do
local runtime = $( basename " $dir " )
echo " ##teamcity[publishArtifacts ' $testPackageFolder / $framework / $runtime /publish/** => tests. $runtime .zip'] "
done
ProgressEnd 'Publishing Test Artifacts'
}
UploadArtifacts( )
{
local framework = " $1 "
ProgressStart 'Publishing Artifacts'
# Releases
for dir in $artifactsFolder /*
do
local runtime = $( basename " $dir " )
2022-08-23 07:11:34 +02:00
echo " ##teamcity[publishArtifacts ' $artifactsFolder / $runtime / $framework /** => Sonarr. $BRANCH . $SONARR_VERSION . $runtime .zip'] "
2021-12-25 02:29:53 +02:00
done
2022-08-23 07:11:34 +02:00
# Debian Package / Windows installer / macOS app
2021-12-25 02:29:53 +02:00
echo "##teamcity[publishArtifacts 'distribution/** => distribution.zip']"
ProgressEnd 'Publishing Artifacts'
2015-07-04 14:10:11 +02:00
}
2022-08-23 07:11:34 +02:00
UploadUIArtifacts( )
{
local framework = " $1 "
ProgressStart 'Publishing UI Artifacts'
# UI folder
echo " ##teamcity[publishArtifacts ' $outputFolder /UI/** => UI.zip'] "
ProgressEnd 'Publishing UI 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
2021-07-30 06:47:53 +02:00
os = "windows"
2015-07-04 14:10:11 +02:00
; ;
*)
# otherwise use mono
2021-07-30 06:47:53 +02:00
os = "posix"
2015-07-04 14:10:11 +02:00
; ;
esac
2021-07-30 06:47:53 +02:00
POSITIONAL = ( )
if [ $# -eq 0 ] ; then
echo "No arguments provided, building everything"
BACKEND = YES
FRONTEND = YES
PACKAGES = YES
LINT = YES
2022-12-03 01:58:39 +02:00
ENABLE_EXTRA_PLATFORMS = NO
ENABLE_EXTRA_PLATFORMS_IN_SDK = NO
2021-07-30 06:47:53 +02:00
fi
while [ [ $# -gt 0 ] ]
do
key = " $1 "
case $key in
--backend)
BACKEND = YES
shift # past argument
; ;
2022-12-03 01:58:39 +02:00
--enable-bsd| --enable-extra-platforms)
ENABLE_EXTRA_PLATFORMS = YES
shift # past argument
; ;
--enable-extra-platforms-in-sdk)
ENABLE_EXTRA_PLATFORMS_IN_SDK = YES
2021-07-30 06:47:53 +02:00
shift # past argument
; ;
-r| --runtime)
RID = " $2 "
shift # past argument
shift # past value
; ;
-f| --framework)
FRAMEWORK = " $2 "
shift # past argument
shift # past value
; ;
--frontend)
FRONTEND = YES
shift # past argument
; ;
--packages)
PACKAGES = YES
shift # past argument
; ;
--lint)
LINT = YES
shift # past argument
; ;
--all)
BACKEND = YES
FRONTEND = YES
PACKAGES = YES
LINT = 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
2022-12-03 01:58:39 +02:00
if [ " $ENABLE_EXTRA_PLATFORMS_IN_SDK " = "YES" ] ;
then
EnableExtraPlatformsInSDK
fi
2021-07-30 06:47:53 +02:00
if [ " $BACKEND " = "YES" ] ;
then
UpdateVersionNumber
2022-12-03 01:58:39 +02:00
if [ " $ENABLE_EXTRA_PLATFORMS " = "YES" ] ;
2021-07-30 06:47:53 +02:00
then
2022-12-03 01:58:39 +02:00
EnableExtraPlatforms
2021-07-30 06:47:53 +02:00
fi
2022-08-20 19:29:51 +02:00
2021-07-30 06:47:53 +02:00
Build
2022-08-20 19:29:51 +02:00
2021-07-30 06:47:53 +02:00
if [ [ -z " $RID " || -z " $FRAMEWORK " ] ] ;
then
2023-11-26 06:23:10 +02:00
PackageTests " $framework " "win-x64"
PackageTests " $framework " "win-x86"
PackageTests " $framework " "linux-x64"
PackageTests " $framework " "linux-musl-x64"
PackageTests " $framework " "osx-x64"
2022-12-03 01:58:39 +02:00
if [ " $ENABLE_EXTRA_PLATFORMS " = "YES" ] ;
2021-07-30 06:47:53 +02:00
then
2023-11-26 06:23:10 +02:00
PackageTests " $framework " "freebsd-x64"
2021-07-30 06:47:53 +02:00
fi
else
PackageTests " $FRAMEWORK " " $RID "
fi
2021-12-25 02:29:53 +02:00
2023-11-26 06:23:10 +02:00
UploadTestArtifacts " $framework "
2021-07-30 06:47:53 +02:00
fi
2022-09-25 09:36:09 +02:00
if [ " $FRONTEND " = "YES" ] ;
2021-07-30 06:47:53 +02:00
then
2022-09-25 09:36:09 +02:00
YarnInstall
if [ " $LINT " = "YES" ] ;
2021-07-30 06:47:53 +02:00
then
2022-09-25 09:36:09 +02:00
LintUI
2021-07-30 06:47:53 +02:00
fi
2021-12-25 02:29:53 +02:00
2022-08-23 07:11:34 +02:00
RunWebpack
UploadUIArtifacts
fi
2021-07-30 06:47:53 +02:00
if [ " $PACKAGES " = "YES" ] ;
then
UpdateVersionNumber
if [ [ -z " $RID " || -z " $FRAMEWORK " ] ] ;
then
2023-11-26 06:23:10 +02:00
Package " $framework " "win-x64"
Package " $framework " "win-x86"
Package " $framework " "linux-x64"
Package " $framework " "linux-musl-x64"
Package " $framework " "linux-arm64"
Package " $framework " "linux-musl-arm64"
Package " $framework " "linux-arm"
Package " $framework " "osx-x64"
Package " $framework " "osx-arm64"
2022-12-03 01:58:39 +02:00
if [ " $ENABLE_EXTRA_PLATFORMS " = "YES" ] ;
2021-07-30 06:47:53 +02:00
then
2023-11-26 06:23:10 +02:00
Package " $framework " "freebsd-x64"
2021-07-30 06:47:53 +02:00
fi
else
Package " $FRAMEWORK " " $RID "
fi
2021-12-25 02:29:53 +02:00
2023-11-26 06:23:10 +02:00
UploadArtifacts " $framework "
2021-07-30 06:47:53 +02:00
fi