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
44 changes: 44 additions & 0 deletions .github/workflows/DeleteRelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Delete release

on:
workflow_dispatch:
inputs:
ref:
description: 'Release tag to delete'
required: true
type: string

permissions:
contents: read
id-token: write

jobs:
windows:
name: windows-2025
runs-on: windows-2025
steps:

- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Cache packages
uses: actions/cache@v6
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', 'Directory.Build.props', 'Directory.Packages.props') }}
restore-keys: ${{ runner.os }}-nuget-

- name: Log in to NuGet
id: nuget
uses: NuGet/login@v1
with:
user: Nice3point

- name: Delete release
run: dotnet run -c Release -- delete
working-directory: "build"
env:
Delete__Ref: ${{ inputs.ref }}
NuGet__ApiKey: ${{ steps.nuget.outputs.NUGET_API_KEY }}
45 changes: 42 additions & 3 deletions build/Modules/DeleteNugetModule.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,67 @@
using System.Text;
using Build.Options;
using EnumerableAsyncProcessor.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using ModularPipelines.Context;
using ModularPipelines.DotNet.Extensions;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Git.Extensions;
using ModularPipelines.Git.Options;
using ModularPipelines.Models;
using ModularPipelines.Modules;
using ModularPipelines.Options;
using Shouldly;

namespace Build.Modules;

public sealed class DeleteNugetModule(IOptions<BuildOptions> buildOptions, IOptions<NuGetOptions> nuGetOptions) : Module<CommandResult[]?>
/// <summary>
/// Delete the NuGet packages published from the specified git reference.
/// </summary>
public sealed class DeleteNugetModule(IOptions<DeleteOptions> deleteOptions, IOptions<NuGetOptions> nuGetOptions) : Module<CommandResult[]?>
{
protected override async Task<CommandResult[]?> ExecuteAsync(IModuleContext context, CancellationToken cancellationToken)
{
return await buildOptions.Value.Versions.Values
var reference = deleteOptions.Value.Ref;
reference.ShouldNotBeNullOrWhiteSpace("No git reference was specified to delete");

var buildOptions = await ReadBuildOptionsAsync(context, reference, cancellationToken);
buildOptions.Versions.ShouldNotBeEmpty($"No NuGet versions were found to delete at: {reference}");

return await buildOptions.Versions.Values
.SelectAsync(async version => await context.DotNet().Nuget.Delete(new DotNetNugetDeleteOptions
{
PackageName = "Nice3point.BenchmarkDotNet.Revit",
Version = version.ToString(),
Version = version,
ApiKey = nuGetOptions.Value.ApiKey,
Source = nuGetOptions.Value.Source,
NonInteractive = true
}, cancellationToken: cancellationToken),
cancellationToken)
.ProcessInParallel();
}

/// <summary>
/// Read the build options from the settings file stored at the specified git reference.
/// </summary>
private static async Task<BuildOptions> ReadBuildOptionsAsync(IModuleContext context, string reference, CancellationToken cancellationToken)
{
var showResult = await context.Git().Commands.Show(
new GitShowOptions
{
Arguments = [$"{reference}:build/appsettings.json"]
},
new CommandExecutionOptions
{
LogSettings = CommandLoggingOptions.Silent
},
cancellationToken);

using var settingsStream = new MemoryStream(Encoding.UTF8.GetBytes(showResult.StandardOutput));
var configuration = new ConfigurationBuilder()
.AddJsonStream(settingsStream)
.Build();

return configuration.GetSection("Build").Get<BuildOptions>() ?? new BuildOptions();
}
}
11 changes: 11 additions & 0 deletions build/Options/DeleteOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Build.Options;

[PublicAPI]
public sealed record DeleteOptions
{
/// <summary>
/// The git reference of the release to delete.
/// </summary>
/// <example>2027.0.0</example>
public string Ref { get; init; } = string.Empty;
}
3 changes: 2 additions & 1 deletion build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
builder.Services.Configure<BuildOptions>(builder.Configuration.GetSection("Build"));
builder.Services.Configure<NuGetOptions>(builder.Configuration.GetSection("NuGet"));
builder.Services.Configure<PublishOptions>(builder.Configuration.GetSection("Publish"));
builder.Services.Configure<DeleteOptions>(builder.Configuration.GetSection("Delete"));

if (args.Length == 0)
{
builder.Services.AddModule<CompileProjectsModule>();
}

if (args.Contains("clean-nuget"))
if (args.Contains("delete"))
{
builder.Services.AddModule<DeleteNugetModule>();
}
Expand Down
3 changes: 3 additions & 0 deletions build/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"Publish": {
"Version": ""
},
"Delete": {
"Ref": ""
},
"NuGet": {
"InternalApiKey": "",
"ApiKey": "",
Expand Down