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: 43 additions & 1 deletion build-utils/Build.Utilities.Tests/Versioning/VersioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public async Task ExactVersioningValid() {
[Test]
public void ExactVersioningWithNullThrows() {
// Arrange
var strategy = new ExactVersioning( Configuration.Release, " ", null!, null! );
var strategy = new ExactVersioning( Configuration.Release, " ", ReleaseType.None, null!, null! );

// Assert
Assert.ThrowsAsync<InvalidOperationException>( async () => await strategy.GetVersionAsync() );
Expand All @@ -302,6 +302,48 @@ public async Task ExactVersioningValidWithReleaseVersion() {
await Assert.That( strategy.GetType() ).IsEqualTo( typeof(ExactVersioning) );
await Assert.That( version.ToString() ).IsEqualTo( "1.5.0" );
}

[Test]
public async Task ExactVersioningReleaseImageReferencesIncludesLatest() {
// Arrange
var build = new TestNukeBuild()
.WithExecutionPlan( b => b.CreateRelease )
.WithReleaseType( ReleaseType.Release );

// Act
var factory = new VersioningStrategyFactory( build );
var strategy = factory.Create( Configuration.Release, null, "1.0.0-alpha.5", null!, null! );
var refs = await strategy.Release!.GetImageReferences();
var tags = refs.Select( r => r.Tag.ToString() ).ToList();

// Assert
using ( Assert.Multiple() ) {
await Assert.That( tags ).Contains( "latest" );
await Assert.That( tags ).Contains( "1.0.0-alpha.5" );
await Assert.That( tags ).Count().IsEqualTo( 2 );
}
}

[Test]
public async Task ExactVersioningPreReleaseImageReferencesDoesNotIncludeLatest() {
// Arrange
var build = new TestNukeBuild()
.WithExecutionPlan( b => b.CreatePreRelease )
.WithReleaseType( ReleaseType.PreRelease );

// Act
var factory = new VersioningStrategyFactory( build );
var strategy = factory.Create( Configuration.Release, null, "0.0.0-windows.10.20260319202632", null, null );
var refs = await strategy.Release!.GetImageReferences();
var tags = refs.Select( r => r.Tag.ToString() ).ToList();

// Assert
using ( Assert.Multiple() ) {
await Assert.That( tags ).DoesNotContain( "latest" );
await Assert.That( tags ).Contains( "0.0.0-windows.10.20260319202632" );
await Assert.That( tags ).Count().IsEqualTo( 1 );
}
}
}

internal sealed class NukeBuildWithArbitraryTarget : TestNukeBuild {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using HLabs.ImageReferences;
using Nuke.Common.Git;
using Octokit;
using Semver;
Expand All @@ -7,6 +8,7 @@ namespace Drift.Build.Utilities.Versioning.Strategies;
public sealed class ExactVersioning(
Configuration configuration,
string? version,
ReleaseType releaseType,
GitRepository repository,
IGitHubClient gitHubClient
) : ReleaseVersioningBase( configuration, repository, gitHubClient ) {
Expand All @@ -21,4 +23,13 @@ public override Task<SemVersion> GetVersionAsync() {
public override async Task<string> GetNameAsync() {
return CreateReleaseName( await GetVersionAsync(), includeMetadata: true );
}

public override async Task<ICollection<QualifiedImageRef>> GetImageReferences() {
var refs = await base.GetImageReferences();
if ( releaseType == ReleaseType.Release ) { // TODO not very clean location
return ["hojmark/drift".Image().Qualify( Tag.Latest ), ..refs];
}

return refs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GitRepository repository
);
}

var strategy = new ExactVersioning( configuration, exactVersion, repository, gitHubClient );
var strategy = new ExactVersioning( configuration, exactVersion, releaseType, repository, gitHubClient );
Log.Information( "Versioning strategy is {Strategy}", strategy.GetType().Name );
return strategy;
}
Expand Down
Loading