Skip to content

Commit

Permalink
Adapt to New Zafiro (#57)
Browse files Browse the repository at this point in the history
* Adapt to new Zafiro

* Fix Build

* Update Zafiro

* Attempt to fix build
  • Loading branch information
SuperJMN authored Nov 22, 2024
1 parent b8521d0 commit d29e05b
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 209 deletions.
154 changes: 69 additions & 85 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Publish",
"PublishNugetPackages",
"PublishSite",
"RestoreWorkloads"
]
},
"Verbosity": {
"type": "string",
"description": "",
"enum": [
"Verbose",
"Normal",
"Minimal",
"Quiet"
]
},
"NukeBuild": {
"properties": {
"Configuration": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"GitHubAuthenticationToken": {
"type": "string",
"description": "GitHub Authentication Token",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"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",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
"$ref": "#/definitions/Host"
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"NuGetApiKey": {
"type": "string",
"description": "NuGet Authentication Token",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
Expand All @@ -71,22 +73,6 @@
"type": "string"
}
},
"PublishFramework": {
"type": "string",
"description": "publish-framework"
},
"PublishProject": {
"type": "string",
"description": "publish-project"
},
"PublishRuntime": {
"type": "string",
"description": "publish-runtime"
},
"PublishSelfContained": {
"type": "boolean",
"description": "publish-self-contained"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
Expand All @@ -95,49 +81,47 @@
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"Clean",
"Publish",
"PublishNugetPackages",
"PublishSite",
"RestoreWorkloads"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"type": "string",
"enum": [
"Clean",
"Publish",
"PublishNugetPackages",
"PublishSite",
"RestoreWorkloads"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
"enum": [
"Minimal",
"Normal",
"Quiet",
"Verbose"
]
"$ref": "#/definitions/Verbosity"
}
}
}
},
"allOf": [
{
"properties": {
"Force": {
"type": "boolean"
},
"GitHubApiKey": {
"type": "string",
"description": "GitHub Authentication Token",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NuGetApiKey": {
"type": "string",
"description": "NuGet Authentication Token",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"VersionSuffix": {
"Solution": {
"type": "string",
"description": "version-suffix"
"description": "Path to a solution file that is automatically loaded"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
}
]
}
Empty file modified build.cmd
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ $DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$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,6 +60,7 @@ 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 SDK version $(& $env:DOTNET_EXE --version)"
Expand Down
6 changes: 3 additions & 3 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
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,11 +53,12 @@ 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 SDK version $("$DOTNET_EXE" --version)"

if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "NUKE_ENTERPRISE_TOKEN" != "" ]]; then
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
Expand Down
87 changes: 25 additions & 62 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,26 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using CSharpFunctionalExtensions;
using Nuke.Common;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Octokit;
using Serilog;
using Zafiro.FileSystem.Core;
using Zafiro.Nuke;
using Zafiro.Deployment;
using Zafiro.Misc;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

class Build : NukeBuild
{
[Parameter("GitHub Authentication Token")] [Secret] readonly string GitHubApiKey;
[Parameter("NuGet Authentication Token")] [Secret] readonly string NuGetApiKey;

[Parameter] readonly bool Force;
[Solution] readonly Solution Solution;

[Parameter("version-suffix")] public string VersionSuffix { get; set; }

[Parameter("publish-framework")] public string PublishFramework { get; set; }

[Parameter("publish-runtime")] public string PublishRuntime { get; set; }

[Parameter("publish-project")] public string PublishProject { get; set; }

[Parameter("publish-self-contained")] public bool PublishSelfContained { get; set; } = true;

[GitVersion] readonly GitVersion GitVersion;

[GitRepository] readonly GitRepository Repository;

[Parameter]
readonly Configuration Configuration = IsServerBuild
? Configuration.Release
: Configuration.Debug;

Actions Actions;

AbsolutePath OutputDirectory => RootDirectory / "output";

protected override void OnBuildInitialized()
{
Actions = new Actions(Solution, Repository, RootDirectory, GitVersion, Configuration);
}

Target Clean => _ => _
.Executes(() =>
{
OutputDirectory.CreateOrCleanDirectory();
var absolutePaths = RootDirectory.GlobDirectories("**/bin", "**/obj").Where(a => !((string) a).Contains("build")).ToList();
Log.Information("Deleting {Dirs}", absolutePaths);
absolutePaths.DeleteDirectories();
});
public static int Main() => Execute<Build>(x => x.Publish);

Target RestoreWorkloads => td => td
.Executes(() =>
Expand All @@ -66,38 +30,37 @@ protected override void OnBuildInitialized()

Target PublishNugetPackages => d => d
.Requires(() => NuGetApiKey)
.DependsOn(Clean)
.OnlyWhenStatic(() => Repository.IsOnMainOrMasterBranch())
.Executes(() =>
.DependsOn(RestoreWorkloads)
.OnlyWhenStatic(() => Repository.IsOnMainOrMasterBranch() || Force)
.Executes(async () =>
{
Actions.PushNuGetPackages(NuGetApiKey)
.TapError(error => throw new ApplicationException(error));
var version = GitVersion.NuGetVersion;

await Deployer.Instance.PublishPackages(PackableProjects, version, NuGetApiKey)
.TapError(error => Assert.Fail(error.ToString()))
.LogInfo("Nuget packages published");
});

Target PublishSite => d => d
.Requires(() => GitHubApiKey)
.DependsOn(Clean)
.DependsOn(RestoreWorkloads)
.OnlyWhenStatic(() => Repository.IsOnMainOrMasterBranch() || Force)
.Executes(async () =>
{
var client = new GitHubClient(new ProductHeaderValue("Zafiro.Avalonia"))
{
Credentials = new Credentials(GitHubApiKey),
};

var github = new GitHub(client, "SuperJMN-Zafiro.github.io", "SuperJMN-Zafiro");

var project = Solution.AllProjects.TryFirst(project => project.Name.EndsWith(".Browser"))
.ToResult("Browser project not found");

await project
.Map(project1 => (ZafiroPath)project1.Path.ToString())
.Bind(zafiroPath => github.PublishAvaloniaAppToPages(zafiroPath))
.TapError(error => throw new ApplicationException(error));
await Solution.AllProjects.TryFirst(project => project.Name.EndsWith(".Browser"))
.ToResult("Browser project not found")
.Map(project => project.Path.ToString())
.Bind(projectPath => Deployer.Instance.PublishAvaloniaAppToGitHubPages(projectPath, "SuperJMN-Zafiro", "SuperJMN-Zafiro.github.io", GitHubApiKey))
.TapError(error => Assert.Fail(error.ToString()))
.LogInfo("Site published");
});

Target Publish => td => td
.DependsOn(PublishNugetPackages, PublishSite);

public static int Main() => Execute<Build>(x => x.Publish);
IEnumerable<string> PackableProjects =>
Solution.AllProjects
.Where(x => x.GetProperty<bool>("IsPackable"))
.Where(x => !(x.Path.ToString().Contains("Test", StringComparison.InvariantCultureIgnoreCase) || x.Path.ToString().Contains("Sample", StringComparison.InvariantCultureIgnoreCase)))
.Select(x => x.Path.ToString());
}
16 changes: 0 additions & 16 deletions build/Configuration.cs

This file was deleted.

Loading

0 comments on commit d29e05b

Please sign in to comment.