Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .config/dotnet-tools.json

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ jobs:
with:
fetch-depth: 0

- name: Install .NET SDK 8.0.x
- name: Install .NET SDK 8.0.x - 9.0.x
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x

- name: Install .NET SDK
uses: actions/setup-dotnet@v5
Expand Down Expand Up @@ -60,5 +61,5 @@ jobs:
AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
AZURE_STORAGE_ACCOUNT_CONTAINER: ${{ secrets.AZURE_STORAGE_ACCOUNT_CONTAINER }}${{ matrix.os }}
with:
cake-version: tool-manifest
file-path: cake.cs
target: GitHub-Actions
56 changes: 0 additions & 56 deletions build/helpers.cake

This file was deleted.

39 changes: 39 additions & 0 deletions build/helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*****************************
* Helpers
*****************************/

public partial class Program
{
static void Main_SetupExtensions()
{
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
TaskSetup(context => BuildSystem.GitHubActions.Commands.StartGroup(context.Task.Name));
TaskTeardown(context => BuildSystem.GitHubActions.Commands.EndGroup());
}
}
}


public static partial class CakeTaskBuilderExtensions
{
private static ExtensionHelper extensionHelper = new (Task, () => RunTarget(Argument("target", "Default")));

public static CakeTaskBuilder Then(this CakeTaskBuilder cakeTaskBuilder, string name)
=> extensionHelper
.TaskCreate(name)
.IsDependentOn(cakeTaskBuilder);


public static CakeReport Run(this CakeTaskBuilder cakeTaskBuilder)
=> extensionHelper.Run();

public static CakeTaskBuilder Default(this CakeTaskBuilder cakeTaskBuilder)
{
extensionHelper
.TaskCreate("Default")
.IsDependentOn(cakeTaskBuilder);
return cakeTaskBuilder;
}

}
23 changes: 11 additions & 12 deletions build/records.cake → build/records.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#load "helpers.cake"
using System.Text.Json.Serialization;

/*****************************
Expand All @@ -22,15 +21,15 @@ DirectoryPath OutputPath
public DirectoryPath BinaryOutputPath { get; } = OutputPath.Combine("bin");
public DirectoryPath IntegrationTestPath { get; } = OutputPath.Combine(IntegrationTest);

public string GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
public string GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GITHUB_TOKEN");
public string? GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
public string? GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GITHUB_TOKEN");

public bool ShouldPushGitHubPackages() => !ShouldNotPublish
&& !string.IsNullOrWhiteSpace(GitHubNuGetSource)
&& !string.IsNullOrWhiteSpace(GitHubNuGetApiKey);

public string NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
public string NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
public string? NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
public string? NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
public bool ShouldPushNuGetPackages() => IsMainBranch &&
!ShouldNotPublish &&
!string.IsNullOrWhiteSpace(NuGetSource) &&
Expand All @@ -49,9 +48,9 @@ public bool ShouldPushNuGetPackages() => IsMainBranch &&
System.Environment.GetEnvironmentVariable("AZURE_AUTHORITY_HOST")
);

public string AzureStorageAccount { get; } = System.Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT");
public string? AzureStorageAccount { get; } = System.Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT");

public string AzureStorageAccountContainer { get; } = System.Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT_CONTAINER");
public string? AzureStorageAccountContainer { get; } = System.Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT_CONTAINER");

public bool ShouldRunIntegrationTests() => !string.IsNullOrWhiteSpace(AzureStorageAccount) &&
!string.IsNullOrWhiteSpace(AzureStorageAccountContainer) &&
Expand All @@ -62,15 +61,15 @@ public bool ShouldRunIntegrationTests() => !string.IsNullOrWhiteSpace(AzureStor
}

public record AzureCredentials(
string TenantId,
string ClientId,
string ClientSecret,
string AuthorityHost = "login.microsoftonline.com"
string? TenantId,
string? ClientId,
string? ClientSecret,
string? AuthorityHost = "login.microsoftonline.com"
)
{
public bool AzureCredentialsSpecified { get; } = !string.IsNullOrWhiteSpace(TenantId) &&
!string.IsNullOrWhiteSpace(ClientId) &&
!string.IsNullOrWhiteSpace(ClientSecret) &&
!string.IsNullOrWhiteSpace(AuthorityHost);
}
private record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);
internal record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);
85 changes: 42 additions & 43 deletions build.cake → cake.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#tool dotnet:?package=GitVersion.Tool&version=6.5.1
#load "build/records.cake"
#load "build/helpers.cake"
#:sdk Cake.Sdk@6.0.0
#:property IncludeAdditionalFiles=./build/*.cs

/*****************************
* Setup
*****************************/
Setup(
static context => {
var assertedVersions = context.GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json
});

var branchName = assertedVersions.BranchName;
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);

var gh = context.GitHubActions();
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=6.5.1");
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=DPI&version=2025.12.17.349");

var buildDate = DateTime.UtcNow;
var runNumber = gh.IsRunningOnGitHubActions
? gh.Environment.Workflow.RunNumber
: (short)((buildDate - buildDate.Date).TotalSeconds/3);
var runNumber = GitHubActions.IsRunningOnGitHubActions
? GitHubActions.Environment.Workflow.RunNumber
: 0;

var suffix = runNumber == 0
? $"-{(short)((buildDate - buildDate.Date).TotalSeconds/3)}"
: string.Empty;

var version = FormattableString
.Invariant($"{buildDate:yyyy.M.d}.{runNumber}");
.Invariant($"{buildDate:yyyy.M.d}.{runNumber}{suffix}");

var branchName = GitHubActions.Environment.Workflow.RefName;
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);

context.Information("Building version {0} (Branch: {1}, IsMain: {2})",
version,
Expand All @@ -41,7 +41,7 @@
version,
isMainBranch,
!context.IsRunningOnWindows(),
context.BuildSystem().IsLocalBuild,
BuildSystem.IsLocalBuild,
projectRoot,
projectPath,
new DotNetMSBuildSettings()
Expand All @@ -54,7 +54,7 @@
.WithProperty("PackageTags", "tool;blob;storage;azure")
.WithProperty("PackageDescription", ".NET Tool that archives local files to Azure Blob Storage")
.WithProperty("RepositoryUrl", "https://github.com/devlead/Blobify.git")
.WithProperty("ContinuousIntegrationBuild", gh.IsRunningOnGitHubActions ? "true" : "false")
.WithProperty("ContinuousIntegrationBuild", GitHubActions.IsRunningOnGitHubActions ? "true" : "false")
.WithProperty("EmbedUntrackedSources", "true"),
artifactsPath,
artifactsPath.Combine(version)
Expand All @@ -80,26 +80,23 @@
)
.Then("DPI")
.Does<BuildData>(
static (context, data) => context.DotNetTool(
"tool",
new DotNetToolSettings {
ArgumentCustomization = args => args
.Append("run")
.Append("dpi")
.Append("nuget")
.Append("--silent")
.AppendSwitchQuoted("--output", "table")
.Append(
(
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_SharedKey"))
&&
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_WorkspaceId"))
)
? "report"
: "analyze"
)
.AppendSwitchQuoted("--buildversion", data.Version)
}
static (context, data) => Command(
["dpi", "dpi.exe"],
new ProcessArgumentBuilder()
.Append("nuget")
.Append("--silent")
.AppendSwitchQuoted("--output", "table")
.Append(
(
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_SharedKey"))
&&
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_WorkspaceId"))
)
? "report"
: "analyze"
)
.AppendSwitchQuoted("--buildversion", data.Version)

)
)
.Then("Build")
Expand Down Expand Up @@ -138,11 +135,13 @@
.Then("Upload-Artifacts")
.WithCriteria(BuildSystem.IsRunningOnGitHubActions, nameof(BuildSystem.IsRunningOnGitHubActions))
.Does<BuildData>(
static (context, data) => context
.GitHubActions() is var gh && gh != null
? gh.Commands
.UploadArtifact(data.ArtifactsPath, $"Artifact_{gh.Environment.Runner.ImageOS ?? gh.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}")
: throw new Exception("GitHubActions not available")
static (context, data)
=> GitHubActions
.Commands
.UploadArtifact(
data.ArtifactsPath,
$"Artifact_{GitHubActions.Environment.Runner.ImageOS ?? GitHubActions.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}"
)
)
.Then("Integration-Tests-Tool-Manifest")
.Does<BuildData>(
Expand Down