sonarr-repo-only/build.sh

377 lines
8.5 KiB
Bash
Raw Normal View History

#! /usr/bin/env bash
set -e
outputFolder='_output'
testPackageFolder='_tests'
artifactsFolder="_artifacts";
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
ProgressStart()
{
echo "Start '$1'"
2017-09-18 03:25:28 +00:00
}
ProgressEnd()
{
echo "Finish '$1'"
2017-09-18 03:25:28 +00:00
}
UpdateVersionNumber()
{
if [ "$SONARRVERSION" != "" ]; then
echo "Updating Version Info"
sed -i'' -e "s/<AssemblyVersion>[0-9.*]\+<\/AssemblyVersion>/<AssemblyVersion>$SONARRVERSION<\/AssemblyVersion>/g" src/Directory.Build.props
sed -i'' -e "s/<AssemblyConfiguration>[\$()A-Za-z-]\+<\/AssemblyConfiguration>/<AssemblyConfiguration>${BUILD_SOURCEBRANCHNAME}<\/AssemblyConfiguration>/g" src/Directory.Build.props
sed -i'' -e "s/<string>10.0.0.0<\/string>/<string>$SONARRVERSION<\/string>/g" distribution/osx/Sonarr.app/Contents/Info.plist
fi
}
EnableBsdSupport()
2015-07-04 12:10:11 +00:00
{
#todo enable sdk with
#SDK_PATH=$(dotnet --list-sdks | grep -P '5\.\d\.\d+' | head -1 | sed 's/\(5\.[0-9]*\.[0-9]*\).*\[\(.*\)\]/\2\/\1/g')
# BUNDLED_VERSIONS="${SDK_PATH}/Microsoft.NETCoreSdk.BundledVersions.props"
2015-07-04 12:10:11 +00: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 12:10:11 +00:00
fi
}
2017-10-07 04:04:00 +00:00
LintUI()
{
ProgressStart 'ESLint'
yarn lint
2017-10-07 04:04:00 +00:00
ProgressEnd 'ESLint'
ProgressStart 'Stylelint'
yarn stylelint
2017-10-07 04:04:00 +00:00
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
rm -rf $testPackageFolder
2015-07-04 12:10:11 +00:00
slnFile=src/Sonarr.sln
if [ $os = "windows" ]; then
platform=Windows
2015-07-04 12:10:11 +00:00
else
platform=Posix
2015-07-04 12:10:11 +00:00
fi
2016-01-16 06:06:33 +00:00
dotnet clean $slnFile -c Debug
dotnet clean $slnFile -c Release
2016-01-16 06:06:33 +00: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 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
ProgressEnd 'Build'
2015-07-04 12:10:11 +00:00
}
YarnInstall()
2015-07-04 12:10:11 +00:00
{
2018-01-13 02:01:27 +00:00
ProgressStart 'yarn install'
yarn install --frozen-lockfile --network-timeout 120000
2018-01-13 02:01:27 +00:00
ProgressEnd 'yarn install'
2015-07-04 12:10:11 +00:00
}
RunWebpack()
2015-07-04 12:10:11 +00:00
{
ProgressStart 'Running webpack'
yarn run build --env production
ProgressEnd 'Running webpack'
2015-07-04 12:10:11 +00:00
}
PackageFiles()
2019-09-12 20:50:16 +00: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
cp -r $outputFolder/UI $folder
echo "Adding LICENSE"
cp LICENSE.md $folder
2019-09-12 20:50:16 +00:00
}
PackageLinux()
2015-07-04 12:10:11 +00:00
{
local framework="$1"
local runtime="$2"
2017-09-18 03:25:28 +00:00
ProgressStart "Creating $runtime Package for $framework"
2017-09-18 03:25:28 +00:00
local folder=$artifactsFolder/$runtime/$framework/Sonarr
2015-07-04 12:10:11 +00:00
PackageFiles "$folder" "$framework" "$runtime"
2015-07-04 12:10:11 +00:00
echo "Removing Service helpers"
rm -f $folder/ServiceUninstall.*
rm -f $folder/ServiceInstall.*
2015-07-04 12:10:11 +00:00
2017-09-18 03:25:28 +00:00
echo "Removing Sonarr.Windows"
rm $folder/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 $folder/Sonarr.Mono.* $folder/Sonarr.Update
if [ "$framework" = "net6.0" ]; then
cp $folder/Mono.Posix.NETStandard.* $folder/Sonarr.Update
cp $folder/libMonoPosixHelper.* $folder/Sonarr.Update
fi
2016-01-16 06:06:33 +00:00
ProgressEnd "Creating $runtime Package for $framework"
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
{
local framework="$1"
ProgressStart "Creating MacOS Package for $framework"
2015-07-04 12:10:11 +00:00
local folder=$artifactsFolder/macos/$framework/Sonarr
PackageFiles "$folder" "$framework" "osx-x64"
echo "Removing Service helpers"
rm -f $folder/ServiceUninstall.*
rm -f $folder/ServiceInstall.*
2015-07-04 12:10:11 +00:00
echo "Removing Sonarr.Windows"
rm $folder/Sonarr.Windows.*
echo "Adding Sonarr.Mono to UpdatePackage"
cp $folder/Sonarr.Mono.* $folder/Sonarr.Update
if [ "$framework" = "net6.0" ]; then
cp $folder/Mono.Posix.NETStandard.* $folder/Sonarr.Update
cp $folder/libMonoPosixHelper.* $folder/Sonarr.Update
fi
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
{
local framework="$1"
ProgressStart "Creating macOS App Package for $framework"
2015-07-04 12:10:11 +00:00
local folder=$artifactsFolder/macos-app/$framework
2015-07-04 12:10:11 +00:00
rm -rf $folder
mkdir -p $folder
cp -r distribution/osx/Sonarr.app $folder
mkdir -p $folder/Sonarr.app/Contents/MacOS
2017-09-18 03:25:28 +00:00
echo "Copying Binaries"
cp -r $artifactsFolder/macos/$framework/Sonarr/* $folder/Sonarr.app/Contents/MacOS
2017-09-18 03:25:28 +00:00
echo "Removing Update Folder"
rm -r $folder/Sonarr.app/Contents/MacOS/Sonarr.Update
2017-09-18 03:25:28 +00:00
ProgressEnd 'Creating macOS App Package'
2015-07-04 12:10:11 +00:00
}
2019-09-12 20:50:16 +00:00
PackageWindows()
{
local framework="$1"
local runtime="$2"
ProgressStart "Creating Windows Package for $framework"
2019-09-12 20:50:16 +00:00
local folder=$artifactsFolder/$runtime/$framework/Sonarr
2019-09-12 20:50:16 +00:00
PackageFiles "$folder" "$framework" "$runtime"
cp -r $outputFolder/$framework-windows/$runtime/publish/* $folder
2017-09-18 03:25:28 +00:00
echo "Removing Sonarr.Mono"
rm -f $folder/Sonarr.Mono.*
rm -f $folder/Mono.Posix.NETStandard.*
rm -f $folder/libMonoPosixHelper.*
2017-09-18 03:25:28 +00:00
echo "Adding Sonarr.Windows to UpdatePackage"
cp $folder/Sonarr.Windows.* $folder/Sonarr.Update
2015-07-04 12:10:11 +00:00
2019-09-12 20:50:16 +00:00
ProgressEnd 'Creating Windows Package'
2017-09-18 03:25:28 +00: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)
PackageMacOS "$framework"
PackageMacOSApp "$framework"
;;
esac
}
PackageTests()
2017-09-18 03:25:28 +00:00
{
local framework="$1"
local runtime="$2"
2018-01-26 19:30:13 +00:00
cp test.sh "$testPackageFolder/$framework/$runtime/publish"
2018-01-26 19:30:13 +00:00
rm -f $testPackageFolder/$framework/$runtime/*.log.config
ProgressEnd 'Creating Test Package'
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
os="windows"
2015-07-04 12:10:11 +00:00
;;
*)
# otherwise use mono
os="posix"
2015-07-04 12:10:11 +00:00
;;
esac
POSITIONAL=()
if [ $# -eq 0 ]; then
echo "No arguments provided, building everything"
BACKEND=YES
FRONTEND=YES
PACKAGES=YES
LINT=YES
ENABLE_BSD=NO
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--backend)
BACKEND=YES
shift # past argument
;;
--enable-bsd)
ENABLE_BSD=YES
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
if [ "$BACKEND" = "YES" ];
then
UpdateVersionNumber
if [ "$ENABLE_BSD" = "YES" ];
then
EnableBsdSupport
fi
Build
if [[ -z "$RID" || -z "$FRAMEWORK" ]];
then
PackageTests "net6.0" "win-x64"
PackageTests "net6.0" "win-x86"
PackageTests "net6.0" "linux-x64"
PackageTests "net6.0" "linux-musl-x64"
PackageTests "net6.0" "osx-x64"
if [ "$ENABLE_BSD" = "YES" ];
then
PackageTests "net6.0" "freebsd-x64"
fi
else
PackageTests "$FRAMEWORK" "$RID"
fi
fi
if [ "$FRONTEND" = "YES" ];
then
YarnInstall
RunWebpack
fi
if [ "$LINT" = "YES" ];
then
if [ -z "$FRONTEND" ];
then
YarnInstall
fi
LintUI
fi
if [ "$PACKAGES" = "YES" ];
then
UpdateVersionNumber
if [[ -z "$RID" || -z "$FRAMEWORK" ]];
then
Package "net6.0" "win-x64"
Package "net6.0" "win-x86"
Package "net6.0" "linux-x64"
Package "net6.0" "linux-musl-x64"
Package "net6.0" "linux-arm64"
Package "net6.0" "linux-musl-arm64"
Package "net6.0" "linux-arm"
Package "net6.0" "osx-x64"
if [ "$ENABLE_BSD" = "YES" ];
then
Package "net6.0" "freebsd-x64"
fi
else
Package "$FRAMEWORK" "$RID"
fi
fi