diff --git a/.gitignore b/.gitignore index 48583b0bc..2a5850895 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,7 @@ Radarr_*.gz _start _temp_*/**/* + +#AppVeyor +/tools-cake/ +/_artifacts/ \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..b6102fa5a --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,38 @@ +version: '0.2.0.{build}' + +branches: + only: + - develop + +assembly_info: + patch: true + file: 'src\NzbDrone.Common\Properties\SharedAssemblyInfo.cs' + assembly_version: '{version}' + assembly_file_version: '{version}' + assembly_informational_version: '{version}-rc1' + +environment: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + +install: + - git submodule update --init --recursive + +build_script: + - ps: ./build-appveyor.ps1 + +test: off +# test: +# assemblies: +# - '_tests\*Test.dll' +# categories: +# except: +# - IntegrationTest +# - AutomationTest + +artifacts: + - path: '_artifacts\*.zip' + - path: '_artifacts\*.tar.gz' + +cache: + - '%USERPROFILE%\.nuget\packages' + - node_modules \ No newline at end of file diff --git a/build-appveyor.cake b/build-appveyor.cake new file mode 100644 index 000000000..8d806e663 --- /dev/null +++ b/build-appveyor.cake @@ -0,0 +1,303 @@ +#addin "Cake.Npm" +#addin "SharpZipLib" +#addin "Cake.Compression" + +// Build variables +var outputFolder = "./_output"; +var outputFolderMono = outputFolder + "_mono"; +var outputFolderOsx = outputFolder + "_osx"; +var outputFolderOsxApp = outputFolderOsx + "_app"; +var testPackageFolder = "./_tests"; +var testSearchPattern = "*.Test/bin/x86/Release"; +var sourceFolder = "./src"; +var solutionFile = sourceFolder + "/NzbDrone.sln"; +var updateFolder = outputFolder + "/NzbDrone.Update"; +var updateFolderMono = outputFolderMono + "/NzbDrone.Update"; + +// Artifact variables +var artifactsFolder = "./_artifacts"; +var artifactsFolderWindows = artifactsFolder + "/windows"; +var artifactsFolderLinux = artifactsFolder + "/linux"; +var artifactsFolderOsx = artifactsFolder + "/osx"; +var artifactsFolderOsxApp = artifactsFolder + "/osx-app"; + +// Utility methods +public void RemoveEmptyFolders(string startLocation) { + foreach (var directory in System.IO.Directory.GetDirectories(startLocation)) + { + RemoveEmptyFolders(directory); + + if (System.IO.Directory.GetFiles(directory).Length == 0 && + System.IO.Directory.GetDirectories(directory).Length == 0) + { + DeleteDirectory(directory, false); + } + } +} + +public void CleanFolder(string path, bool keepConfigFiles) { + DeleteFiles(path + "/**/*.transform"); + + if (!keepConfigFiles) { + DeleteFiles(path + "/**/*.dll.config"); + } + + DeleteFiles(path + "/**/FluentValidation.resources.dll"); + DeleteFiles(path + "/**/App.config"); + + DeleteFiles(path + "/**/*.less"); + + DeleteFiles(path + "/**/*.vshost.exe"); + + DeleteFiles(path + "/**/*.dylib"); + + RemoveEmptyFolders(path); +} + +public void CreateMdbs(string path) { + foreach (var file in System.IO.Directory.EnumerateFiles(path, "*.pdb", System.IO.SearchOption.AllDirectories)) { + var actualFile = file.Substring(0, file.Length - 4); + + if (FileExists(actualFile + ".exe")) { + StartProcess("./tools/pdb2mdb/pdb2mdb.exe", new ProcessSettings() + .WithArguments(args => args.Append(actualFile + ".exe"))); + } + + if (FileExists(actualFile + ".dll")) { + StartProcess("./tools/pdb2mdb/pdb2mdb.exe", new ProcessSettings() + .WithArguments(args => args.Append(actualFile + ".dll"))); + } + } +} + +// Build Tasks +Task("Compile").Does(() => { + // Build + if (DirectoryExists(outputFolder)) { + DeleteDirectory(outputFolder, true); + } + + MSBuild(solutionFile, config => + config.UseToolVersion(MSBuildToolVersion.VS2015) + .WithTarget("Clean") + .SetVerbosity(Verbosity.Minimal)); + + NuGetRestore(solutionFile); + + MSBuild(solutionFile, config => + config.UseToolVersion(MSBuildToolVersion.VS2015) + .SetPlatformTarget(PlatformTarget.x86) + .SetConfiguration("Release") + .WithProperty("AllowedReferenceRelatedFileExtensions", new string[] { ".pdb" }) + .WithTarget("Build") + .SetVerbosity(Verbosity.Minimal)); + + CleanFolder(outputFolder, false); + + // Add JsonNet + DeleteFiles(outputFolder + "/Newtonsoft.Json.*"); + CopyFiles(sourceFolder + "/packages/Newtonsoft.Json.*/lib/net35/*.dll", outputFolder); + CopyFiles(sourceFolder + "/packages/Newtonsoft.Json.*/lib/net35/*.dll", updateFolder); + + // Remove Mono stuff + DeleteFile(outputFolder + "/Mono.Posix.dll"); +}); + +Task("Gulp").Does(() => { + Npm + .WithLogLevel(NpmLogLevel.Silent) + .FromPath(".") + .Install() + .RunScript("build"); +}); + +Task("PackageMono").Does(() => { + // Start mono package + if (DirectoryExists(outputFolderMono)) { + DeleteDirectory(outputFolderMono, true); + } + + CopyDirectory(outputFolder, outputFolderMono); + + // Create MDBs + CreateMdbs(outputFolderMono); + + // Remove PDBs + DeleteFiles(outputFolderMono + "/**/*.pdb"); + + // Remove service helpers + DeleteFiles(outputFolderMono + "/ServiceUninstall.*"); + DeleteFiles(outputFolderMono + "/ServiceInstall.*"); + + // Remove native windows binaries + DeleteFiles(outputFolderMono + "/sqlite3.*"); + DeleteFiles(outputFolderMono + "/MediaInfo.*"); + + // Adding NzbDrone.Core.dll.config (for dllmap) + CopyFile(sourceFolder + "/NzbDrone.Core/NzbDrone.Core.dll.config", outputFolderMono + "/NzbDrone.Core.dll.config"); + + // Adding CurlSharp.dll.config (for dllmap) + CopyFile(sourceFolder + "/NzbDrone.Common/CurlSharp.dll.config", outputFolderMono + "/CurlSharp.dll.config"); + + // Renaming Radarr.Console.exe to Radarr.exe + DeleteFiles(outputFolderMono + "/Radarr.exe*"); + MoveFile(outputFolderMono + "/Radarr.Console.exe", outputFolderMono + "/Radarr.exe"); + MoveFile(outputFolderMono + "/Radarr.Console.exe.config", outputFolderMono + "/Radarr.exe.config"); + MoveFile(outputFolderMono + "/Radarr.Console.exe.mdb", outputFolderMono + "/Radarr.exe.mdb"); + + // Remove NzbDrone.Windows.* + DeleteFiles(outputFolderMono + "/NzbDrone.Windows.*"); + + // Adding NzbDrone.Mono to updatePackage + CopyFiles(outputFolderMono + "/NzbDrone.Mono.*", updateFolderMono); +}); + +Task("PackageOsx").Does(() => { + // Start osx package + if (DirectoryExists(outputFolderOsx)) { + DeleteDirectory(outputFolderOsx, true); + } + + CopyDirectory(outputFolderMono, outputFolderOsx); + + // Adding sqlite dylibs + CopyFiles(sourceFolder + "/Libraries/Sqlite/*.dylib", outputFolderOsx); + + // Adding MediaInfo dylib + CopyFiles(sourceFolder + "/Libraries/MediaInfo/*.dylib", outputFolderOsx); + + // Adding Startup script + CopyFile("./osx/Sonarr", outputFolderOsx + "/Sonarr"); +}); + +Task("PackageOsxApp").Does(() => { + // Start osx app package + if (DirectoryExists(outputFolderOsxApp)) { + DeleteDirectory(outputFolderOsxApp, true); + } + + CreateDirectory(outputFolderOsxApp); + + // Copy osx package files + CopyDirectory("./osx/Radarr.app", outputFolderOsxApp + "/Radarr.app"); + CopyDirectory(outputFolderOsx, outputFolderOsxApp + "/Radarr.app/Contents/MacOS"); +}); + +Task("PackageTests").Does(() => { + // Start tests package + if (DirectoryExists(testPackageFolder)) { + DeleteDirectory(testPackageFolder, true); + } + + CreateDirectory(testPackageFolder); + + // Copy tests + CopyFiles(sourceFolder + "/" + testSearchPattern + "/*", testPackageFolder); + foreach (var directory in System.IO.Directory.GetDirectories(sourceFolder, "*.Test")) { + var releaseDirectory = directory + "/bin/x86/Release"; + if (DirectoryExists(releaseDirectory)) { + foreach (var releaseSubDirectory in System.IO.Directory.GetDirectories(releaseDirectory)) { + Information(System.IO.Path.GetDirectoryName(releaseSubDirectory)); + CopyDirectory(releaseSubDirectory, testPackageFolder + "/" + System.IO.Path.GetFileName(releaseSubDirectory)); + } + } + } + + // Install NUnit.ConsoleRunner + NuGetInstall("NUnit.ConsoleRunner", new NuGetInstallSettings { + Version = "3.2.0", + OutputDirectory = testPackageFolder + }); + + // Copy dlls + CopyFiles(outputFolder + "/*.dll", testPackageFolder); + + // Copy scripts + CopyFiles("./*.sh", testPackageFolder); + + // Create MDBs for tests + CreateMdbs(testPackageFolder); + + // Remove config + DeleteFiles(testPackageFolder + "/*.log.config"); + + // Clean + CleanFolder(testPackageFolder, true); + + // Adding NzbDrone.Core.dll.config (for dllmap) + CopyFile(sourceFolder + "/NzbDrone.Core/NzbDrone.Core.dll.config", testPackageFolder + "/NzbDrone.Core.dll.config"); + + // Adding CurlSharp.dll.config (for dllmap) + CopyFile(sourceFolder + "/NzbDrone.Common/CurlSharp.dll.config", testPackageFolder + "/CurlSharp.dll.config"); + + // Adding CurlSharp libraries + CopyFiles(sourceFolder + "/ExternalModules/CurlSharp/libs/i386/*", testPackageFolder); +}); + +Task("CleanupWindowsPackage").Does(() => { + // Remove mono + DeleteFiles(outputFolder + "/NzbDrone.Mono.*"); + + // Adding NzbDrone.Windows to updatePackage + CopyFiles(outputFolder + "/NzbDrone.Windows.*", updateFolder); +}); + +Task("Build") + .IsDependentOn("Compile") + .IsDependentOn("Gulp") + .IsDependentOn("PackageMono") + .IsDependentOn("PackageOsx") + .IsDependentOn("PackageOsxApp") + .IsDependentOn("PackageTests") + .IsDependentOn("CleanupWindowsPackage"); + +// Build Artifacts +Task("CleanArtifacts").Does(() => { + if (DirectoryExists(artifactsFolder)) { + DeleteDirectory(artifactsFolder, true); + } + + CreateDirectory(artifactsFolder); +}); + +Task("ArtifactsWindows").Does(() => { + CopyDirectory(outputFolder, artifactsFolderWindows + "/Radarr"); +}); + +Task("ArtifactsLinux").Does(() => { + CopyDirectory(outputFolderMono, artifactsFolderLinux + "/Radarr"); +}); + +Task("ArtifactsOsx").Does(() => { + CopyDirectory(outputFolderOsx, artifactsFolderOsx + "/Radarr"); +}); + +Task("ArtifactsOsxApp").Does(() => { + CopyDirectory(outputFolderOsxApp, artifactsFolderOsxApp); +}); + +Task("CompressArtifacts").Does(() => { + var prefix = ""; + + if (AppVeyor.IsRunningOnAppVeyor) { + prefix += AppVeyor.Environment.Repository.Branch + "."; + prefix += AppVeyor.Environment.Build.Version + "."; + } + + Zip(artifactsFolderWindows, artifactsFolder + "/Radarr." + prefix + "windows.zip"); + GZipCompress(artifactsFolderLinux, artifactsFolder + "/Radarr." + prefix + "linux.tar.gz"); + GZipCompress(artifactsFolderOsx, artifactsFolder + "/Radarr." + prefix + "osx.tar.gz"); + Zip(artifactsFolderOsxApp, artifactsFolder + "/Radarr." + prefix + "osx-app.zip"); +}); + +Task("Artifacts") + .IsDependentOn("CleanArtifacts") + .IsDependentOn("ArtifactsWindows") + .IsDependentOn("ArtifactsLinux") + .IsDependentOn("ArtifactsOsx") + .IsDependentOn("ArtifactsOsxApp") + .IsDependentOn("CompressArtifacts"); + +// Run +RunTarget("Build"); +RunTarget("Artifacts"); \ No newline at end of file diff --git a/build-appveyor.ps1 b/build-appveyor.ps1 new file mode 100644 index 000000000..fd3bea746 --- /dev/null +++ b/build-appveyor.ps1 @@ -0,0 +1,184 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +<# +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. +.LINK +http://cakebuild.net +#> + +[CmdletBinding()] +Param( + [string]$Script = "build-appveyor.cake", + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null +function MD5HashFile([string] $filePath) +{ + if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) + { + return $null + } + + [System.IO.Stream] $file = $null; + [System.Security.Cryptography.MD5] $md5 = $null; + try + { + $md5 = [System.Security.Cryptography.MD5]::Create() + $file = [System.IO.File]::OpenRead($filePath) + return [System.BitConverter]::ToString($md5.ComputeHash($file)) + } + finally + { + if ($file -ne $null) + { + $file.Dispose() + } + } +} + +Write-Host "Preparing to run build script..." + +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools-cake" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" +$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Throw "Could not download packages.config." + } +} + +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + + # Check for changes in packages.config and remove installed tools if true. + [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + Write-Verbose -Message "Missing or changed package.config hash..." + Remove-Item * -Recurse -Exclude packages.config,nuget.exe + } + + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + else + { + $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" + } + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE \ No newline at end of file