Skip to content

Commit

Permalink
Update NUKE to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed May 10, 2024
1 parent a222c8a commit 4e19f84
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 68 deletions.
2 changes: 0 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
"Clean",
"Compile",
"Coverage",
"CreateNuGetConfigForInternalPackages",
"FrontEndRestore",
"GenerateModelsFromSwagger",
"GenerateVersion",
Expand Down Expand Up @@ -173,7 +172,6 @@
"Clean",
"Compile",
"Coverage",
"CreateNuGetConfigForInternalPackages",
"FrontEndRestore",
"GenerateModelsFromSwagger",
"GenerateVersion",
Expand Down
13 changes: 9 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ $TempDirectory = "$PSScriptRoot\\.nuke\temp"

$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "Current"
$DotNetChannel = "STS"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0
$env:DOTNET_NOLOGO = 1

###########################################################################
# EXECUTION
Expand Down Expand Up @@ -61,9 +60,15 @@ else {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
}
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
$env:PATH = "$DotNetDirectory;$env:PATH"
}

Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"

if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
}

ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
13 changes: 9 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"

DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="Current"
DOTNET_CHANNEL="STS"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0
export DOTNET_NOLOGO=1

###########################################################################
# EXECUTION
Expand Down Expand Up @@ -54,9 +53,15 @@ else
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
fi
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
export PATH="$DOTNET_DIRECTORY:$PATH"
fi

echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"

if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then
"$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true
"$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true
fi

"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
99 changes: 49 additions & 50 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Nuke.Common.Tools.Slack;
using Nuke.Common.Tools.AzureKeyVault.Attributes;
using Nuke.Common.Tools.AzureKeyVault;
using static Nuke.GitHub.GitHubTasks;
using static Nuke.GitHub.ChangeLogExtensions;
Expand All @@ -44,25 +43,25 @@
using Nuke.WebDocu;
using Newtonsoft.Json;
using Nuke.Common.Utilities;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http;
using System.Security.Policy;
using System.Text;

class Build : NukeBuild
{
public static int Main() => Execute<Build>(x => x.Compile);

[KeyVaultSettings(
[AzureKeyVaultConfiguration(
BaseUrlParameterName = nameof(KeyVaultBaseUrl),
ClientIdParameterName = nameof(KeyVaultClientId),
ClientSecretParameterName = nameof(KeyVaultClientSecret))]
readonly KeyVaultSettings KeyVaultSettings;
ClientSecretParameterName = nameof(KeyVaultClientSecret),
TenantId = nameof(KeyVaultTenantId))]
readonly AzureKeyVaultConfiguration KeyVaultSettings;

[Parameter] string KeyVaultBaseUrl;
[Parameter] string KeyVaultClientId;
[Parameter] string KeyVaultClientSecret;
[Parameter] string KeyVaultTenantId;

// This parameter is only required if we're just calling the sign target
// to sign executables in a specific folder
Expand All @@ -77,17 +76,17 @@ class Build : NukeBuild
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

[Parameter] readonly string DockerImageName = "danglopencde";
[KeyVaultSecret] string DanglCiCdSlackWebhookUrl;
[KeyVaultSecret] string DanglCiCdTeamsWebhookUrl;
[KeyVaultSecret] string DockerRegistryUrl;
[KeyVaultSecret] string DockerRegistryUsername;
[KeyVaultSecret] string DockerRegistryPassword;
[KeyVaultSecret] string GitHubAuthenticationToken;
[KeyVaultSecret] string DocuBaseUrl;
[KeyVaultSecret("DanglOpenCDE-DocuApiKey")] string DocuApiKey;
[KeyVaultSecret] string CodeSigningCertificateName;
[KeyVaultSecret] string CodeSigningCertificateKeyVaultBaseUrl;
[KeyVaultSecret] string CodeSigningKeyVaultTenantId;
[AzureKeyVaultSecret] string DanglCiCdSlackWebhookUrl;
[AzureKeyVaultSecret] string DanglCiCdTeamsWebhookUrl;
[AzureKeyVaultSecret] string DockerRegistryUrl;
[AzureKeyVaultSecret] string DockerRegistryUsername;
[AzureKeyVaultSecret] string DockerRegistryPassword;
[AzureKeyVaultSecret] string GitHubAuthenticationToken;
[AzureKeyVaultSecret] string DocuBaseUrl;
[AzureKeyVaultSecret("DanglOpenCDE-DocuApiKey")] string DocuApiKey;
[AzureKeyVaultSecret] string CodeSigningCertificateName;
[AzureKeyVaultSecret] string CodeSigningCertificateKeyVaultBaseUrl;
[AzureKeyVaultSecret] string CodeSigningKeyVaultTenantId;

[Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository;
Expand All @@ -101,7 +100,7 @@ class Build : NukeBuild
AbsolutePath ChangelogFile => RootDirectory / "CHANGELOG.md";
AbsolutePath PublishDirectory => OutputDirectory / "publish";

[PackageExecutable("AzureSignTool", "tools/netcoreapp3.1/any/AzureSignTool.dll")]
[NuGetPackage("AzureSignTool", "tools/net8.0/any/AzureSignTool.dll")]
readonly Tool AzureSign;

public Build()
Expand Down Expand Up @@ -140,10 +139,10 @@ void SendTeamsMessage(string title, string message, bool isError)
.Before(Restore)
.Executes(() =>
{
EnsureCleanDirectory(SourceDirectory / "client" / "dangl-opencde-client-ui" / "node_modules");
FilterChildPaths(SourceDirectory.GlobDirectories("**/bin", "**/obj")).ForEach(DeleteDirectory);
FilterChildPaths(TestsDirectory.GlobDirectories("**/bin", "**/obj")).ForEach(DeleteDirectory);
EnsureCleanDirectory(OutputDirectory);
(SourceDirectory / "client" / "dangl-opencde-client-ui" / "node_modules").CreateOrCleanDirectory();
FilterChildPaths(SourceDirectory.GlobDirectories("**/bin", "**/obj")).ForEach(d => Directory.Delete(d));
FilterChildPaths(TestsDirectory.GlobDirectories("**/bin", "**/obj")).ForEach(d => Directory.Delete(d));
(OutputDirectory).CreateOrCleanDirectory();
});

public static IEnumerable<string> FilterChildPaths(IReadOnlyCollection<AbsolutePath> src)
Expand Down Expand Up @@ -214,7 +213,7 @@ public static class VersionsService
public static DateTime BuildDateUtc {{ get; }} = {currentDateUtc};
}}
}}";
WriteAllText(filePath, content);
filePath.WriteAllText(content);
}

void GenerateFrontendVersion(DateTime buildDate)
Expand All @@ -233,7 +232,7 @@ void GenerateFrontendVersion(DateTime buildDate)
informationalVersion: ""{GitVersion.InformationalVersion}"",
buildDateUtc: {currentDateUtc}
}}";
WriteAllText(filePath, content);
filePath.WriteAllText(content);
}

Target BuildDocFxMetadata => _ => _
Expand All @@ -254,7 +253,7 @@ void GenerateFrontendVersion(DateTime buildDate)
DocFXBuild(x => x
.SetProcessEnvironmentVariable("DOCFX_SOURCE_BRANCH_NAME", GitVersion.BranchName)
.SetConfigFile(DocFxFile));
DeleteFile(DocsDirectory / "CHANGELOG.md");
(DocsDirectory / "CHANGELOG.md").DeleteFile();
});

Target Coverage => _ => _
Expand All @@ -265,9 +264,9 @@ void GenerateFrontendVersion(DateTime buildDate)
Serilog.Log.Debug("Ensuring that latest SQL Docker image is present");
DockerPull(c => c.SetName("dangl/mssql-tmpfs:latest"));

var testProjects = GlobFiles(TestsDirectory, "**/*.csproj")
var testProjects = TestsDirectory.GlobFiles("**/*.csproj")
// The test utilities are excluded as they don't contain any tests
.Where(t => !t.EndsWith("Dangl.OpenCDE.TestUtilities.csproj"));
.Where(t => !t.ToString().EndsWith("Dangl.OpenCDE.TestUtilities.csproj"));
try
{
DotNetTest(c => c
Expand Down Expand Up @@ -309,7 +308,7 @@ void GenerateFrontendVersion(DateTime buildDate)

private void EnsureTestFilesHaveUniqueTimestamp()
{
var testResults = GlobFiles(OutputDirectory, "*_testresults.xml").ToList();
var testResults = OutputDirectory.GlobFiles("*_testresults.xml").ToList();
var runtime = DateTime.Now;

foreach (var testResultFile in testResults)
Expand Down Expand Up @@ -362,8 +361,8 @@ private void EnsureTestFilesHaveUniqueTimestamp()
.After(Clean)
.Executes(() =>
{
EnsureCleanDirectory(SourceDirectory / "server" / "dangl-opencde-ui" / "node_modules");
DeleteDirectory(SourceDirectory / "server" / "dangl-opencde-ui" / "node_modules");
(SourceDirectory / "server" / "dangl-opencde-ui" / "node_modules").CreateOrCleanDirectory();
(SourceDirectory / "server" / "dangl-opencde-ui" / "node_modules").DeleteDirectory();
Npm("ci", SourceDirectory / "server" / "dangl-opencde-ui");
});

Expand All @@ -372,14 +371,14 @@ private void EnsureTestFilesHaveUniqueTimestamp()
.DependsOn(FrontEndRestore)
.Executes(() =>
{
EnsureCleanDirectory(SourceDirectory / "server" / "Dangl.OpenCDE" / "wwwroot" / "dist");
(SourceDirectory / "server" / "Dangl.OpenCDE" / "wwwroot" / "dist").CreateOrCleanDirectory();
NpmRun(x => x
.SetProcessWorkingDirectory(SourceDirectory / "server" / "dangl-opencde-ui")
.SetCommand("build:production"));

var assetsSrc = SourceDirectory / "server" / "dangl-opencde-ui" / "src" / "assets";
var assetsDest = SourceDirectory / "server" / "Dangl.OpenCDE" / "wwwroot" / "assets";
EnsureCleanDirectory(assetsDest);
assetsDest.CreateOrCleanDirectory();
CopyDirectoryRecursively(assetsSrc, assetsDest, DirectoryExistsPolicy.Merge);
});

Expand All @@ -404,7 +403,7 @@ private void EnsureTestFilesHaveUniqueTimestamp()

CopyDirectoryRecursively(PublishDirectory, OutputDirectory / "Docker");

foreach (var configFileToDelete in GlobFiles(OutputDirectory / "Docker", "web*.config"))
foreach (var configFileToDelete in (OutputDirectory / "Docker").GlobFiles("web*.config"))
{
File.Delete(configFileToDelete);
}
Expand All @@ -417,7 +416,7 @@ private void EnsureTestFilesHaveUniqueTimestamp()
.SetPath(".")
.SetProcessWorkingDirectory(OutputDirectory / "Docker"));

EnsureCleanDirectory(OutputDirectory / "Docker");
(OutputDirectory / "Docker").CreateOrCleanDirectory();
});

Target PushDocker => _ => _
Expand Down Expand Up @@ -597,7 +596,7 @@ await PublishRelease(x => x
SignExecutablesInFolder(OutputDirectory / "electron");
});

private void SignExecutablesInFolder(string folderPath)
private void SignExecutablesInFolder(AbsolutePath folderPath)
{
if (!IsWin)
{
Expand All @@ -612,18 +611,18 @@ private void SignExecutablesInFolder(string folderPath)
Assert.True(!string.IsNullOrWhiteSpace(CodeSigningCertificateName), "!string.IsNullOrWhitespace(CodeSigningCertificateName)");

Serilog.Log.Debug("Searching for files to sign in " + folderPath);
var inputFiles = GlobFiles(folderPath, "*.exe");
var inputFiles = folderPath.GlobFiles("*.exe");

if (!inputFiles.Any())
{
Serilog.Log.Debug("No files to sign found");
return;
}

Serilog.Log.Debug("Signing " + inputFiles.Join(", "));
Serilog.Log.Debug("Signing " + inputFiles.Select(f => f.ToString()).Join(", "));

var filesListPath = OutputDirectory / $"{Guid.NewGuid()}.txt";
WriteAllText(filesListPath, inputFiles.Join(Environment.NewLine) + Environment.NewLine);
filesListPath.WriteAllText(inputFiles.Select(f => f.ToString()).Join(Environment.NewLine) + Environment.NewLine);

try
{
Expand All @@ -642,13 +641,13 @@ private void SignExecutablesInFolder(string folderPath)
}
finally
{
DeleteFile(filesListPath);
filesListPath.DeleteFile();
}
}

void BuildElectronAppInternal(ElectronBuildConfig electronBuildConfig)
{
EnsureCleanDirectory(SourceDirectory / "client" / "Dangl.OpenCDE.Client" / "bin");
(SourceDirectory / "client" / "Dangl.OpenCDE.Client" / "bin").CreateOrCleanDirectory();

// Electron Build
SetVersionInElectronManifest();
Expand All @@ -675,7 +674,7 @@ void BuildElectronAppInternal(ElectronBuildConfig electronBuildConfig)
.AssertWaitForExit();
}

var clientFiles = GlobFiles(SourceDirectory / "client" / "Dangl.OpenCDE.Client" / "bin" / "Desktop", "*.exe", "*.snap", "*.AppImage", "*.zip", "*.dmg");
var clientFiles = (SourceDirectory / "client" / "Dangl.OpenCDE.Client" / "bin" / "Desktop").GlobFiles("*.exe", "*.snap", "*.AppImage", "*.zip", "*.dmg");

foreach (var clientFile in clientFiles)
{
Expand Down Expand Up @@ -703,15 +702,15 @@ private class ElectronBuildConfig
.SetDocuBaseUrl(DocuBaseUrl)
.SetDocuApiKey(DocuApiKey)
.SetVersion(GitVersion.NuGetVersion)
.SetAssetFilePaths(GlobFiles(OutputDirectory / "electron", "*").ToArray()));
.SetAssetFilePaths((OutputDirectory / "electron").GlobFiles("*").Select(f => f.ToString()).ToArray()));
});

private void SetVersionInElectronManifest()
{
var manifestPath = SourceDirectory / "client" / "Dangl.OpenCDE.Client" / "electron.manifest.json";
var manifestJson = JObject.Parse(ReadAllText(manifestPath));
var manifestJson = JObject.Parse(manifestPath.ReadAllText());
manifestJson["build"]["buildVersion"] = GitVersion.SemVer;
WriteAllText(manifestPath, manifestJson.ToString(Formatting.Indented));
manifestPath.WriteAllText(manifestJson.ToString(Formatting.Indented));
}

Target SignExecutables => _ => _
Expand All @@ -733,7 +732,7 @@ private void SetVersionInElectronManifest()
.SetOutput(OutputDirectory / "Dangl.OpenCDE.DataSeed"));

ZipFile.CreateFromDirectory(OutputDirectory / "Dangl.OpenCDE.DataSeed", OutputDirectory / "Dangl.OpenCDE.DataSeed.zip");
DeleteDirectory(OutputDirectory / "Dangl.OpenCDE.DataSeed");
(OutputDirectory / "Dangl.OpenCDE.DataSeed").DeleteDirectory();
});

Target PublishDatabaseSeedUtility => _ => _
Expand All @@ -746,7 +745,7 @@ private void SetVersionInElectronManifest()
.SetDocuBaseUrl(DocuBaseUrl)
.SetDocuApiKey(DocuApiKey)
.SetVersion(GitVersion.NuGetVersion)
.SetAssetFilePaths(GlobFiles(OutputDirectory, "*.zip").ToArray()));
.SetAssetFilePaths(OutputDirectory.GlobFiles("*.zip").Select(f => f.ToString()).ToArray()));
});

Target GenerateModelsFromSwagger => _ => _
Expand Down Expand Up @@ -794,7 +793,7 @@ private async Task GenerateCSharpBackendServerSideModelsAsync()
using var zipArchive = new ZipArchive(generatedClientStream);

var targetDirectory = SourceDirectory / "server" / "Dangl.OpenCDE.Shared" / "OpenCdeSwaggerGenerated";
EnsureCleanDirectory(targetDirectory);
targetDirectory.CreateOrCleanDirectory();
var foldersToCopy = new[] { "Converters", "Models" };
foreach (var folderToCopy in foldersToCopy)
{
Expand All @@ -810,7 +809,7 @@ private async Task GenerateCSharpBackendServerSideModelsAsync()
fileContent = fileContent
.Replace($"Dangl.OpenCDE.Shared.{folder}", $"Dangl.OpenCDE.Shared.OpenCdeSwaggerGenerated.{folder}");
}
WriteAllText(targetDirectory / folderToCopy / entry.Name, fileContent);
(targetDirectory / folderToCopy / entry.Name).WriteAllText(fileContent);
}
}
}
Expand Down Expand Up @@ -853,7 +852,7 @@ private async Task GenerateTypeScriptFrontendModelsAsync()
using var zipArchive = new ZipArchive(generatedClientStream);

var targetDirectory = SourceDirectory / "client" / "dangl-opencde-client-ui" / "src" / "app" / "generated" / "open-cde-swagger";
EnsureCleanDirectory(targetDirectory);
targetDirectory.CreateOrCleanDirectory();
var foldersToCopy = new[] { "model" };
foreach (var folderToCopy in foldersToCopy)
{
Expand All @@ -864,7 +863,7 @@ private async Task GenerateTypeScriptFrontendModelsAsync()
using var entryStream = entry.Open();
using var streamReader = new StreamReader(entryStream);
var fileContent = await streamReader.ReadToEndAsync();
WriteAllText(targetDirectory / folderToCopy / entry.Name, fileContent);
(targetDirectory / folderToCopy / entry.Name).WriteAllText(fileContent);
}
}
}
Expand Down
Loading

0 comments on commit 4e19f84

Please sign in to comment.