First steps to make Cake compatible with Linux

Working, but still needs some improvements
This commit is contained in:
flightlevel 2019-01-19 17:23:56 +11:00
parent 5d2c64711f
commit e48a20f93d
5 changed files with 229 additions and 62 deletions

1
.gitattributes vendored
View File

@ -6,6 +6,7 @@
# Declare files that will always have LF line endings on checkout.
*.yml text eol=lf
*.sh text eol=lf
# Declare files that will always have CRLF line endings on checkout.
*.cs text eol=crlf

View File

@ -1,6 +1,10 @@
version: 0.10.{build}
skip_tags: true
image: Visual Studio 2017
image:
- Visual Studio 2017
- Ubuntu
environment:
APPVEYOR_YML_DISABLE_PS_LINUX: true
configuration: Release
assembly_info:
patch: true
@ -17,7 +21,8 @@ dotnet_csproj:
file_version: '{version}'
informational_version: '{version}'
build_script:
- ps: .\build.ps1
- ps: .\build.ps1 --target=Default
- sh: ./build.sh --target=Linux
test: off
before_deploy:
- ps: ${env:release_description} = ( Get-Content -LiteralPath BuildOutput/ReleaseNotes.txt -Encoding UTF8 ) -join "`n";

View File

@ -25,8 +25,17 @@ Task("Info")
.Does(() =>
{
Information(@"Jackett Cake build script starting...");
Information(@"Requires InnoSetup and C:\cygwin to be present for packaging (Pre-installed on AppVeyor)");
Information(@"Requires InnoSetup and C:\cygwin to be present for packaging (Pre-installed on AppVeyor) on Windows");
Information(@"Working directory is: " + workingDir);
if (IsRunningOnWindows())
{
Information("Platform is Windows");
}
else
{
Information("Platform is Linux, Windows builds will be skipped");
}
});
Task("Clean")
@ -39,6 +48,8 @@ Task("Clean")
CleanDirectories("./" + artifactsDirName);
CleanDirectories("./" + testResultsDirName);
CreateDirectory("./" + artifactsDirName);
Information("Clean completed");
});
@ -67,29 +78,14 @@ Task("Run-Unit-Tests")
Results = new[] { new NUnit3Result { FileName = resultsFile } }
});
if(AppVeyor.IsRunningOnAppVeyor)
if (AppVeyor.IsRunningOnAppVeyor && IsRunningOnWindows())
{
AppVeyor.UploadTestResults(resultsFile, AppVeyorTestResultsType.NUnit3);
}
});
Task("Check-Packaging-Platform")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
if (IsRunningOnWindows())
{
CreateDirectory("./" + artifactsDirName);
Information("Platform is Windows");
}
else
{
throw new Exception("Packaging is currently only implemented for a Windows environment");
}
});
Task("Package-Windows-Full-Framework")
.IsDependentOn("Check-Packaging-Platform")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
@ -119,7 +115,7 @@ Task("Package-Windows-Full-Framework")
});
Task("Package-Mono-Full-Framework")
.IsDependentOn("Check-Packaging-Platform")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
@ -149,7 +145,7 @@ Task("Package-Mono-Full-Framework")
});
Task("Experimental-DotNetCore")
.IsDependentOn("Check-Packaging-Platform")
.IsDependentOn("Clean")
.Does(() =>
{
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
@ -165,20 +161,11 @@ Task("Experimental-DotNetCore")
Gzip("./BuildOutput/Experimental/netcoreapp2.2/linux-arm", $"./{artifactsDirName}", "Jackett", "Experimental.netcoreapp.linux-arm.tar.gz");
});
Task("Package")
.IsDependentOn("Package-Windows-Full-Framework")
.IsDependentOn("Package-Mono-Full-Framework")
.IsDependentOn("Experimental-DotNetCore")
.Does(() =>
{
Information("Packaging completed");
});
Task("Appveyor-Push-Artifacts")
.IsDependentOn("Package")
.IsDependentOn("Clean")
.Does(() =>
{
if (AppVeyor.IsRunningOnAppVeyor)
if (AppVeyor.IsRunningOnAppVeyor && IsRunningOnWindows())
{
foreach (var file in GetFiles(workingDir + $"/{artifactsDirName}/*"))
{
@ -187,12 +174,12 @@ Task("Appveyor-Push-Artifacts")
}
else
{
Information(@"Skipping as not running in AppVeyor Environment");
Information(@"Skipping artifact push as not running in AppVeyor Windows Environment");
}
});
Task("Release-Notes")
.IsDependentOn("Appveyor-Push-Artifacts")
.IsDependentOn("Clean")
.Does(() =>
{
string latestTag = GitDescribe(".", false, GitDescribeStrategy.Tags, 0);
@ -230,7 +217,7 @@ Task("Release-Notes")
string buildNote = String.Join(Environment.NewLine, notesList);
Information(buildNote);
System.IO.File.WriteAllLines(workingDir + "\\BuildOutput\\ReleaseNotes.txt", notesList.ToArray());
System.IO.File.WriteAllLines(workingDir + "/BuildOutput/ReleaseNotes.txt", notesList.ToArray());
}
else
{
@ -239,6 +226,26 @@ Task("Release-Notes")
});
Task("Windows-Environment")
.IsDependentOn("Package-Windows-Full-Framework")
.IsDependentOn("Package-Mono-Full-Framework")
.IsDependentOn("Experimental-DotNetCore")
.IsDependentOn("Appveyor-Push-Artifacts")
.IsDependentOn("Release-Notes")
.Does(() =>
{
Information("Windows-Environment Task Completed");
});
Task("Linux-Environment")
.IsDependentOn("Experimental-DotNetCore")
.IsDependentOn("Appveyor-Push-Artifacts")
.IsDependentOn("Release-Notes")
.Does(() =>
{
Information("Linux-Environment Task Completed");
});
private void RunCygwinCommand(string utility, string utilityArguments)
{
@ -285,29 +292,52 @@ private string RelativeWinPathToCygPath(string relativePath)
return cygPath;
}
private void RunLinuxCommand(string file, string arg)
{
var startInfo = new System.Diagnostics.ProcessStartInfo()
{
Arguments = arg,
FileName = file,
UseShellExecute = true
};
var process = System.Diagnostics.Process.Start(startInfo);
process.WaitForExit();
}
private void Gzip(string sourceFolder, string outputDirectory, string tarCdirectoryOption, string outputFileName)
{
var cygSourcePath = RelativeWinPathToCygPath(sourceFolder);
var tarFileName = outputFileName.Remove(outputFileName.Length - 3, 3);
var tarArguments = @"-cvf " + cygSourcePath + "/" + tarFileName + " -C " + cygSourcePath + $" {tarCdirectoryOption} --mode ='755'";
var gzipArguments = @"-k " + cygSourcePath + "/" + tarFileName;
if (IsRunningOnWindows())
{
var cygSourcePath = RelativeWinPathToCygPath(sourceFolder);
var tarArguments = @"-cvf " + cygSourcePath + "/" + tarFileName + " -C " + cygSourcePath + $" {tarCdirectoryOption} --mode ='755'";
var gzipArguments = @"-k " + cygSourcePath + "/" + tarFileName;
RunCygwinCommand("Tar", tarArguments);
RunCygwinCommand("Gzip", gzipArguments);
MoveFile($"{sourceFolder}/{tarFileName}.gz", $"{outputDirectory}/{tarFileName}.gz");
RunCygwinCommand("Tar", tarArguments);
RunCygwinCommand("Gzip", gzipArguments);
MoveFile($"{sourceFolder}/{tarFileName}.gz", $"{outputDirectory}/{tarFileName}.gz");
}
else
{
RunLinuxCommand("find", MakeAbsolute(Directory(sourceFolder)) + @" -type d -exec chmod 755 {} \;");
RunLinuxCommand("find", MakeAbsolute(Directory(sourceFolder)) + @" -type f -exec chmod 644 {} \;");
//RunLinuxCommand("chmod", $"755 {MakeAbsolute(Directory(sourceFolder))} /Jackett/jackett");
RunLinuxCommand("tar", $"-C {sourceFolder} -zcvf {outputDirectory}/{tarFileName}.gz Jackett");
}
}
private void DotNetCorePublish(string projectPath, string framework, string runtime)
{
var settings = new DotNetCorePublishSettings
{
Framework = framework,
Runtime = runtime,
OutputDirectory = $"./BuildOutput/Experimental/{framework}/{runtime}/Jackett"
};
{
Framework = framework,
Runtime = runtime,
OutputDirectory = $"./BuildOutput/Experimental/{framework}/{runtime}/Jackett"
};
DotNetCorePublish(projectPath, settings);
DotNetCorePublish(projectPath, settings);
}
//////////////////////////////////////////////////////////////////////
@ -315,12 +345,19 @@ private void DotNetCorePublish(string projectPath, string framework, string runt
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Release-Notes")
.IsDependentOn("Windows-Environment")
.Does(() =>
{
Information("Default Task Completed");
});
Task("Linux")
.IsDependentOn("Linux-Environment")
.Does(() =>
{
Information("Linux Task Completed");
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

View File

@ -25,10 +25,6 @@ Specifies the amount of information to be displayed.
Shows description about tasks.
.PARAMETER DryRun
Performs a dry run.
.PARAMETER Experimental
Uses the nightly builds of the Roslyn script engine.
.PARAMETER Mono
Uses the Mono Compiler rather than the Roslyn script engine.
.PARAMETER SkipToolPackageRestore
Skips restoring of packages.
.PARAMETER ScriptArgs
@ -49,13 +45,25 @@ Param(
[switch]$ShowDescription,
[Alias("WhatIf", "Noop")]
[switch]$DryRun,
[switch]$Experimental,
[switch]$Mono,
[switch]$SkipToolPackageRestore,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
# Attempt to set highest encryption available for SecurityProtocol.
# PowerShell will not set this by default (until maybe .NET 4.6.x). This
# will typically produce a message for PowerShell v2 (just an info
# message though)
try {
# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
# installed (.NET 4.5 is an in-place upgrade).
[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
} catch {
Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3'
}
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
function MD5HashFile([string] $filePath)
{
@ -85,7 +93,7 @@ function GetProxyEnabledWebClient
{
$wc = New-Object System.Net.WebClient
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$wc.Proxy = $proxy
return $wc
}
@ -115,10 +123,11 @@ if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG)) {
Write-Verbose -Message "Downloading packages.config..."
try {
Write-Verbose -Message "Downloading packages.config..."
try {
$wc = GetProxyEnabledWebClient
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG)
} catch {
Throw "Could not download packages.config."
}
}
@ -225,8 +234,6 @@ if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
if ($ShowDescription) { $cakeArguments += "-showdescription" }
if ($DryRun) { $cakeArguments += "-dryrun" }
if ($Experimental) { $cakeArguments += "-experimental" }
if ($Mono) { $cakeArguments += "-mono" }
$cakeArguments += $ScriptArgs
# Start Cake

117
build.sh Normal file
View File

@ -0,0 +1,117 @@
#!/usr/bin/env bash
##########################################################################
# This is the Cake bootstrapper script for Linux and OS X.
# This file was downloaded from https://github.com/cake-build/resources
# Feel free to change this file to fit your needs.
##########################################################################
# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
ADDINS_DIR=$TOOLS_DIR/Addins
MODULES_DIR=$TOOLS_DIR/Modules
NUGET_EXE=$TOOLS_DIR/nuget.exe
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
PACKAGES_CONFIG=$TOOLS_DIR/packages.config
PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
# Define md5sum or md5 depending on Linux/OSX
MD5_EXE=
if [[ "$(uname -s)" == "Darwin" ]]; then
MD5_EXE="md5 -r"
else
MD5_EXE="md5sum"
fi
# Define default arguments.
SCRIPT="build.cake"
CAKE_ARGUMENTS=()
# Parse arguments.
for i in "$@"; do
case $1 in
-s|--script) SCRIPT="$2"; shift ;;
--) shift; CAKE_ARGUMENTS+=("$@"); break ;;
*) CAKE_ARGUMENTS+=("$1") ;;
esac
shift
done
# Make sure the tools folder exist.
if [ ! -d "$TOOLS_DIR" ]; then
mkdir "$TOOLS_DIR"
fi
# Make sure that packages.config exist.
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
echo "Downloading packages.config..."
curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
if [ $? -ne 0 ]; then
echo "An error occurred while downloading packages.config."
exit 1
fi
fi
# Download NuGet if it does not exist.
if [ ! -f "$NUGET_EXE" ]; then
echo "Downloading NuGet..."
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
if [ $? -ne 0 ]; then
echo "An error occurred while downloading nuget.exe."
exit 1
fi
fi
# Restore tools from NuGet.
pushd "$TOOLS_DIR" >/dev/null
if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
fi
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet tools."
exit 1
fi
$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
popd >/dev/null
# Restore addins from NuGet.
if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
pushd "$ADDINS_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet addins."
exit 1
fi
popd >/dev/null
fi
# Restore modules from NuGet.
if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
pushd "$MODULES_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet modules."
exit 1
fi
popd >/dev/null
fi
# Make sure that Cake has been installed.
if [ ! -f "$CAKE_EXE" ]; then
echo "Could not find Cake.exe at '$CAKE_EXE'."
exit 1
fi
# Start Cake
exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}"