Skip to content

Commit 425b2dc

Browse files
committed
[Build] Refactor versioning system and improve package changelog handling
1 parent b5a01e4 commit 425b2dc

9 files changed

Lines changed: 55 additions & 24 deletions

Nice3point.Revit.Extensions.slnx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,23 @@
2020
</Configurations>
2121
<Folder Name="/Automation/">
2222
<Project Path="build/Build.csproj">
23-
<BuildType Project="Debug" />
23+
<BuildType Solution="Debug R19|*" Project="Debug"/>
24+
<BuildType Solution="Debug R20|*" Project="Debug"/>
25+
<BuildType Solution="Debug R21|*" Project="Debug"/>
26+
<BuildType Solution="Debug R22|*" Project="Debug"/>
27+
<BuildType Solution="Debug R23|*" Project="Debug"/>
28+
<BuildType Solution="Debug R24|*" Project="Debug"/>
29+
<BuildType Solution="Debug R25|*" Project="Debug"/>
30+
<BuildType Solution="Debug R26|*" Project="Debug"/>
31+
<BuildType Solution="Release R19|*" Project="Release"/>
32+
<BuildType Solution="Release R20|*" Project="Release"/>
33+
<BuildType Solution="Release R21|*" Project="Release"/>
34+
<BuildType Solution="Release R22|*" Project="Release"/>
35+
<BuildType Solution="Release R23|*" Project="Release"/>
36+
<BuildType Solution="Release R24|*" Project="Release"/>
37+
<BuildType Solution="Release R25|*" Project="Release"/>
38+
<BuildType Solution="Release R26|*" Project="Release"/>
39+
<BuildType Solution="Release Tests|*" Project="Release"/>
2440
</Project>
2541
</Folder>
2642
<Folder Name="/Solution Items/">
@@ -39,6 +55,7 @@
3955
<BuildType Solution="Debug R24|*" Project="Debug" />
4056
<BuildType Solution="Debug R25|*" Project="Debug" />
4157
<BuildType Solution="Debug R26|*" Project="Debug" />
58+
<BuildType Solution="Release R19|*" Project="Release"/>
4259
<BuildType Solution="Release R20|*" Project="Release" />
4360
<BuildType Solution="Release R21|*" Project="Release" />
4461
<BuildType Solution="Release R22|*" Project="Release" />
@@ -55,6 +72,7 @@
5572
<Build Solution="Debug R24|*" Project="false" />
5673
<Build Solution="Debug R25|*" Project="false" />
5774
<Build Solution="Debug R26|*" Project="false" />
75+
<Build Solution="Release R19|*" Project="false"/>
5876
<Build Solution="Release R20|*" Project="false" />
5977
<Build Solution="Release R21|*" Project="false" />
6078
<Build Solution="Release R22|*" Project="false" />

build/Modules/CreateChangelogModule.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99

1010
namespace Build.Modules;
1111

12-
public sealed class CreateChangelogModule(IOptions<BuildOptions> buildOptions) : Module<StringBuilder>
12+
public sealed class CreateChangelogModule(IOptions<PublishOptions> publishOptions) : Module<StringBuilder>
1313
{
1414
protected override async Task<StringBuilder?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
1515
{
1616
var changelogFile = context.Git().RootDirectory.GetFile("Changelog.md");
17-
var version = buildOptions.Value.Version;
18-
17+
var version = publishOptions.Value.Version;
18+
1919
var changelog = await BuildChangelog(changelogFile, version);
2020
changelog.Length.ShouldBePositive($"No version entry exists in the changelog: {version}");
21-
21+
2222
return changelog;
2323
}
24-
25-
24+
2625
private static async Task<StringBuilder> BuildChangelog(File changelogFile, string version)
2726
{
2827
const string separator = "# ";

build/Modules/CreateGitHubChangelogModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Build.Modules;
1010

1111
[DependsOn<CreateChangelogModule>]
12-
public sealed class CreateGitHubChangelogModule(IOptions<BuildOptions> buildOptions) : Module<string>
12+
public sealed class CreateGitHubChangelogModule(IOptions<PublishOptions> publishOptions) : Module<string>
1313
{
1414
protected override async Task<string?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
1515
{
@@ -27,7 +27,7 @@ private async Task<StringBuilder> AppendGitHubCompareUrlAsync(IPipelineContext c
2727

2828
if (changelog[^1] != '\r' || changelog[^1] != '\n') changelog.AppendLine(Environment.NewLine);
2929
changelog.Append("Full changelog: ");
30-
changelog.Append($"https://github.com/{repositoryInfo.Identifier}/compare/{latestRelease.TagName}...{buildOptions.Value.Version}");
30+
changelog.Append($"https://github.com/{repositoryInfo.Identifier}/compare/{latestRelease.TagName}...{publishOptions.Value.Version}");
3131

3232
return changelog;
3333
}

build/Modules/PackProjectsModule.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ namespace Build.Modules;
1414

1515
[DependsOn<CleanProjectsModule>]
1616
[DependsOn<CreatePackageReadmeModule>]
17-
[DependsOn<CreatePackageChangelogModule>]
1817
[DependsOn<ParseSolutionConfigurationsModule>]
1918
public sealed class PackProjectsModule(IOptions<BuildOptions> buildOptions, IOptions<PackOptions> packOptions) : Module
2019
{
2120
protected override async Task<IDictionary<string, object>?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
2221
{
2322
var configurations = await GetModule<ParseSolutionConfigurationsModule>();
24-
var changelog = await GetModule<CreatePackageChangelogModule>();
23+
var changelogModule = GetModuleIfRegistered<CreatePackageChangelogModule>();
24+
25+
var changelog = changelogModule is null ? null : await changelogModule;
2526
var outputFolder = context.Git().RootDirectory.GetFolder(packOptions.Value.OutputDirectory);
2627

2728
foreach (var configuration in configurations.Value!)
2829
{
29-
await SubModule(configuration, async () => await PackAsync(context, configuration, outputFolder.Path, changelog.Value!, cancellationToken));
30+
await SubModule(configuration, async () => await PackAsync(context, configuration, outputFolder.Path, changelog?.Value, cancellationToken));
3031
}
3132

3233
return await NothingAsync();
3334
}
3435

35-
private async Task<CommandResult> PackAsync(IPipelineContext context, string configuration, string output, string changelog, CancellationToken cancellationToken)
36+
private async Task<CommandResult> PackAsync(IPipelineContext context, string configuration, string output, string? changelog, CancellationToken cancellationToken)
3637
{
3738
buildOptions.Value.Versions
3839
.TryGetValue(configuration, out var version)
@@ -46,7 +47,7 @@ private async Task<CommandResult> PackAsync(IPipelineContext context, string con
4647
Properties = new List<KeyValue>
4748
{
4849
("Version", version.ToString()),
49-
("PackageReleaseNotes", changelog),
50+
("PackageReleaseNotes", changelog ?? string.Empty),
5051
},
5152
OutputDirectory = output
5253
}, cancellationToken);

build/Modules/PublishGithubModule.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Build.Modules;
1717
[SkipIfNoGitHubToken]
1818
[DependsOn<PackProjectsModule>]
1919
[DependsOn<CreateGitHubChangelogModule>]
20-
public sealed class PublishGithubModule(IOptions<BuildOptions> buildOptions, IOptions<PackOptions> packOptions) : Module<ReleaseAsset[]?>
20+
public sealed class PublishGithubModule(IOptions<PublishOptions> publishOptions, IOptions<PackOptions> packOptions) : Module<ReleaseAsset[]?>
2121
{
2222
protected override async Task<ReleaseAsset[]?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
2323
{
@@ -27,12 +27,12 @@ public sealed class PublishGithubModule(IOptions<BuildOptions> buildOptions, IOp
2727
targetFiles.ShouldNotBeEmpty("No artifacts were found to create the Release");
2828

2929
var repositoryInfo = context.GitHub().RepositoryInfo;
30-
var newRelease = new NewRelease(buildOptions.Value.Version)
30+
var newRelease = new NewRelease(publishOptions.Value.Version)
3131
{
32-
Name = buildOptions.Value.Version,
32+
Name = publishOptions.Value.Version,
3333
Body = changelog.Value,
3434
TargetCommitish = context.Git().Information.LastCommitSha,
35-
Prerelease = buildOptions.Value.Version.Contains('-')
35+
Prerelease = publishOptions.Value.Version.Contains('-')
3636
};
3737

3838
var release = await context.GitHub().Client.Repository.Release.Create(repositoryInfo.Owner, repositoryInfo.RepositoryName, newRelease);
@@ -57,7 +57,7 @@ protected override async Task OnAfterExecute(IPipelineContext context)
5757
await context.Git().Commands.Push(new GitPushOptions
5858
{
5959
Delete = true,
60-
Arguments = ["origin", buildOptions.Value.Version]
60+
Arguments = ["origin", publishOptions.Value.Version]
6161
});
6262
}
6363
}

build/Options/BuildOptions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ namespace Build.Options;
66
public sealed record BuildOptions
77
{
88
[Required] public string ConfigurationFilter { get; init; } = null!;
9-
[Required] public string Version { get; init; } = null!;
10-
[Required] public Dictionary<string, Version> Versions { get; init; } = null!;
9+
[Required] public Dictionary<string, string> Versions { get; init; } = null!;
1110
}

build/Options/PublishOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Build.Options;
4+
5+
[Serializable]
6+
public sealed record PublishOptions
7+
{
8+
[Required] public string Version { get; init; } = null!;
9+
}

build/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ await PipelineHostBuilder.Create()
2323
return;
2424
}
2525

26+
collection.AddOptions<BuildOptions>().Bind(context.Configuration.GetSection("Build")).ValidateDataAnnotations();
2627
collection.AddModule<ParseSolutionConfigurationsModule>();
2728

2829
if (args.Length == 0)
@@ -36,8 +37,6 @@ await PipelineHostBuilder.Create()
3637
collection.AddOptions<PackOptions>().Bind(context.Configuration.GetSection("Pack")).ValidateDataAnnotations();
3738

3839
collection.AddModule<CleanProjectsModule>();
39-
collection.AddModule<CreateChangelogModule>();
40-
collection.AddModule<CreatePackageChangelogModule>();
4140
collection.AddModule<CreatePackageReadmeModule>();
4241
collection.AddModule<PackProjectsModule>();
4342
collection.AddModule<RestoreReadmeModule>();
@@ -50,8 +49,11 @@ await PipelineHostBuilder.Create()
5049
throw new InvalidOperationException("Publish can only be run in production");
5150
}
5251

52+
collection.AddOptions<PublishOptions>().Bind(context.Configuration.GetSection("Publish")).ValidateDataAnnotations();
5353
collection.AddOptions<NuGetOptions>().Bind(context.Configuration.GetSection("NuGet")).ValidateDataAnnotations();
5454

55+
collection.AddModule<CreateChangelogModule>();
56+
collection.AddModule<CreatePackageChangelogModule>();
5557
collection.AddModule<CreateGitHubChangelogModule>();
5658
collection.AddModule<PublishNugetModule>();
5759
collection.AddModule<PublishGithubModule>();

build/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Build": {
33
"ConfigurationFilter": "Release R*",
4-
"Version": "2026.0.2-preview.1.20251113",
54
"Versions": {
5+
"Release R19": "2019.4.2-preview.1.20251113",
66
"Release R20": "2020.4.2-preview.1.20251113",
77
"Release R21": "2021.4.2-preview.1.20251113",
88
"Release R22": "2022.4.2-preview.1.20251113",
@@ -15,6 +15,9 @@
1515
"Pack": {
1616
"OutputDirectory": "output"
1717
},
18+
"Publish": {
19+
"Version": ""
20+
},
1821
"NuGet": {
1922
"ApiKey": "",
2023
"Source": "https://api.nuget.org/v3/index.json"

0 commit comments

Comments
 (0)