Update NUKE version and build script dependencies

This commit is contained in:
Alex Barney 2021-12-17 00:59:18 -07:00
parent 592343212f
commit fc1e098118
12 changed files with 194 additions and 88 deletions

1
.gitignore vendored
View file

@ -261,6 +261,7 @@ __pycache__/
*.pyc
**/launchSettings.json
.nuke/temp
global.json

0
.nuke
View file

135
.nuke/build.schema.json Normal file
View file

@ -0,0 +1,135 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build",
"definitions": {
"build": {
"type": "object",
"properties": {
"_solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded. Default is LibHac.sln"
},
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)"
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
},
"Host": {
"type": "string",
"description": "Host for execution. Default is 'automatic'",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"NoReflection": {
"type": "boolean",
"description": "Disable reflection in native builds"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
},
"Plan": {
"type": "boolean",
"description": "Shows the execution plan (HTML)"
},
"Profile": {
"type": "array",
"description": "Defines the profiles to load",
"items": {
"type": "string"
}
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
},
"Skip": {
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"AppVeyorBuild",
"Clean",
"Codegen",
"Compile",
"Full",
"Native",
"Pack",
"Publish",
"Restore",
"SetVersion",
"Sign",
"Standard",
"Test",
"Zip"
]
}
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"type": "string",
"enum": [
"AppVeyorBuild",
"Clean",
"Codegen",
"Compile",
"Full",
"Native",
"Pack",
"Publish",
"Restore",
"SetVersion",
"Sign",
"Standard",
"Test",
"Zip"
]
}
},
"Untrimmed": {
"type": "boolean",
"description": "Don't enable any size-reducing settings on native builds"
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
"enum": [
"Minimal",
"Normal",
"Quiet",
"Verbose"
]
}
}
}
}
}

4
.nuke/parameters.json Normal file
View file

@ -0,0 +1,4 @@
{
"$schema": "./build.schema.json",
"Solution": ""
}

View file

@ -1,6 +1,7 @@
version: 0.0.0-{build}
image: Visual Studio 2019
image: Visual Studio 2022
environment:
IGNORE_NORMALISATION_GIT_HEAD_MOVE: 1
myget_api_key:
secure: 0xJoYAtR6psXCRvk1qm5czDObkeRjHKPjfe5gIExXVFPwA0VVODYv/hBZYUtz2F3
build_script:

View file

@ -4,4 +4,4 @@
:; exit $?
@ECHO OFF
powershell -ExecutionPolicy ByPass -NoProfile "%~dp0build.ps1" %*
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*

View file

@ -1,6 +1,6 @@
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)]
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$BuildArguments
)
@ -14,9 +14,9 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
###########################################################################
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
$TempDirectory = "$PSScriptRoot\.tmp"
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
$DotNetGlobalFile = "$PSScriptRoot\global.json"
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "Current"
$DotNetCliVersion = Get-Content DotnetCliVersion.txt
@ -38,22 +38,26 @@ function ExecSafe([scriptblock] $cmd) {
try {
$json = "{`"sdk`":{`"version`":`"$DotNetCliVersion`"}}"
Out-File -FilePath $DotNetGlobalFile -Encoding utf8 -InputObject $json
# If global.json exists, load expected version
if (Test-Path $DotNetGlobalFile) {
$DotNetVersion = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json).sdk.version
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
$DotNetVersion = $DotNetGlobal.sdk.version
}
}
$DotNetDirectory = "$TempDirectory\dotnet-win"
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
# If dotnet CLI is installed globally and it matches requested version, use for execution
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
(!(Test-Path variable:DotNetVersion) -or $(& cmd.exe /c 'dotnet --version 2>&1') -eq $DotNetVersion)) {
$(dotnet --version) -eq $DotNetVersion) {
$env:DOTNET_EXE = (Get-Command "dotnet").Path
}
# If dotnet CLI is installed locally and it matches requested version, use for execution
elseif ($null -eq (Get-Command $env:DOTNET_EXE -ErrorAction SilentlyContinue) -or `
!(Test-Path variable:DotNetVersion) -or $(& cmd.exe /c "$env:DOTNET_EXE --version 2>&1") -ne $DotNetVersion) {
!(Test-Path variable:DotNetVersion) -or $(& $env:DOTNET_EXE --version) -ne $DotNetVersion) {
# Download install script
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
@ -63,11 +67,11 @@ try {
# Install by channel or version
if (!(Test-Path variable:DotNetVersion)) {
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
}
else {
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
} else {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
}
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
}
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"

View file

@ -10,9 +10,9 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
###########################################################################
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
TEMP_DIRECTORY="$SCRIPT_DIR/.tmp"
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
DOTNET_GLOBAL_FILE="$SCRIPT_DIR/global.json"
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="Current"
@ -25,7 +25,7 @@ export DOTNET_MULTILEVEL_LOOKUP=0
###########################################################################
function FirstJsonValue {
perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2}
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
}
trap "rm -f \"$DOTNET_GLOBAL_FILE\"" INT TERM EXIT
@ -35,18 +35,18 @@ json="{\"sdk\":{\"version\":\"$dotnetCliVersion\"}}"
echo "$json" > "$DOTNET_GLOBAL_FILE"
# If global.json exists, load expected version
if [ -f "$DOTNET_GLOBAL_FILE" ]; then
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
DOTNET_VERSION=$dotnetCliVersion
fi
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
# If dotnet CLI is installed globally and it matches requested version, use for execution
if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then
export DOTNET_EXE="$(command -v dotnet)"
elif [[ ! (-x "$DOTNET_EXE" && (-z ${DOTNET_VERSION+x} || $($DOTNET_EXE --version) == "$DOTNET_VERSION")) ]]; then
# Download install script
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
mkdir -p "$TEMP_DIRECTORY"
@ -55,9 +55,10 @@ elif [[ ! (-x "$DOTNET_EXE" && (-z ${DOTNET_VERSION+x} || $($DOTNET_EXE --versio
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
chmod +x "$DOTNET_INSTALL_FILE"
fi
# Install by channel or version
if [ -z ${DOTNET_VERSION+x} ]; then
if [[ -z ${DOTNET_VERSION+x} ]]; then
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
else
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path

View file

@ -43,7 +43,7 @@ partial class Build : NukeBuild
AbsolutePath TestsDirectory => RootDirectory / "tests";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed";
AbsolutePath TempDirectory => RootDirectory / ".tmp";
AbsolutePath TempDirectory => RootDirectory / ".nuke" / "temp";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net5.0";
AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}";
AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}";
@ -142,21 +142,21 @@ partial class Build : NukeBuild
suffix += $"+{gitVersion.Sha.Substring(0, 8)}";
}
if (Host == HostType.AppVeyor)
if (Host is AppVeyor appVeyor)
{
// Workaround GitVersion issue by getting PR info manually https://github.com/GitTools/GitVersion/issues/1927
string prNumber = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER");
// Workaround GitVersion issue by getting PR info manually https://github.com/GitTools/GitVersion/issues/1927
int? prNumber = appVeyor.PullRequestNumber;
string branchName = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH");
if (int.TryParse(prNumber, out int prInt) && branchName != null)
if (prNumber != null && branchName != null)
{
string prString = $"PullRequest{prInt:D4}";
string prString = $"PullRequest{prNumber:D4}";
VersionString = VersionString.Replace(branchName, prString);
suffix = suffix.Replace(branchName, prString);
suffix = suffix?.Replace(branchName, prString) ?? "";
}
SetAppVeyorVersion(VersionString);
appVeyor.UpdateBuildVersion(VersionString);
}
VersionProps = new Dictionary<string, object>
@ -226,8 +226,8 @@ partial class Build : NukeBuild
.SetNoBuild(true)
.SetProperties(VersionProps));
// Hack around OS newline differences
if (EnvironmentInfo.IsUnix)
// Hack around OS newline differences
if (EnvironmentInfo.IsUnix)
{
foreach (string filename in Directory.EnumerateFiles(CliCoreDir, "*.json"))
{
@ -256,8 +256,6 @@ partial class Build : NukeBuild
RepackNugetPackage(filename);
}
if (Host != HostType.AppVeyor) return;
foreach (string filename in Directory.EnumerateFiles(ArtifactsDirectory, "*.*nupkg"))
{
PushArtifact(filename);
@ -292,10 +290,7 @@ partial class Build : NukeBuild
ZipFiles(CliCoreZip, namesCore);
Logger.Normal($"Created {CliCoreZip}");
if (Host == HostType.AppVeyor)
{
PushArtifact(CliCoreZip);
}
PushArtifact(CliCoreZip);
});
Target Publish => _ => _
@ -396,10 +391,7 @@ partial class Build : NukeBuild
ZipFile(CliNativeZip, CliNativeExe, $"hactoolnet{NativeProgramExtension}");
Logger.Normal($"Created {CliNativeZip}");
if (Host == HostType.AppVeyor)
{
PushArtifact(CliNativeZip);
}
PushArtifact(CliNativeZip);
}
public static void ZipFiles(string outFile, IEnumerable<string> files)
@ -530,55 +522,20 @@ partial class Build : NukeBuild
return compressed;
}
public static void PushArtifact(string path)
public static void PushArtifact(string path, string name = null)
{
if (Host is not AppVeyor appVeyor) return;
if (!File.Exists(path))
{
Logger.Warn($"Unable to add artifact {path}");
}
var psi = new ProcessStartInfo
{
FileName = "appveyor",
Arguments = $"PushArtifact \"{path}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var proc = new Process
{
StartInfo = psi
};
proc.Start();
proc.WaitForExit();
appVeyor.PushArtifact(path, name);
Logger.Normal($"Added AppVeyor artifact {path}");
}
public static void SetAppVeyorVersion(string version)
{
var psi = new ProcessStartInfo
{
FileName = "appveyor",
Arguments = $"UpdateBuild -Version \"{version}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var proc = new Process
{
StartInfo = psi
};
proc.Start();
proc.WaitForExit();
}
public static void ReplaceLineEndings(string filename)
{
string text = File.ReadAllText(filename);

View file

@ -42,7 +42,7 @@ public static class ResultCodeGen
WriteOutput("LibHac/ResultNameResolver.Generated.cs", archiveStr);
string enumStr = PrintEnum(modules);
WriteOutput("../.tmp/result_enums.txt", enumStr);
WriteOutput("../.nuke/temp/result_enums.txt", enumStr);
}
private static ResultSet ReadResults()

View file

@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nuke.Common" Version="5.0.2" />
<PackageReference Include="Nuke.Common" Version="5.3.0" />
</ItemGroup>
<ItemGroup>

View file

@ -7,14 +7,17 @@
<RootNamespace>LibHacBuild</RootNamespace>
<IsPackable>False</IsPackable>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
</PropertyGroup>
<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.8.0]" />
<PackageReference Include="CsvHelper" Version="26.0.1" />
<PackageReference Include="NuGet.CommandLine" Version="5.8.1" />
<PackageReference Include="Nuke.Common" Version="5.0.2" />
<PackageReference Include="SharpZipLib" Version="1.3.1" />
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="NuGet.CommandLine" Version="6.0.0" />
<PackageReference Include="Nuke.Common" Version="5.3.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
</ItemGroup>
<ItemGroup>