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
48 changes: 47 additions & 1 deletion KtsuBuild.Tests/Publishing/ReleaseServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ReleaseServiceTests
private ReleaseService _service = null!;
private string _tempDir = null!;

public TestContext TestContext { get; set; } = null!;

[TestInitialize]
public void Setup()
{
Expand Down Expand Up @@ -56,6 +58,50 @@ await _dotNetService.Received(1).PackAsync(
_tempDir, config.StagingPath, "Release", Arg.Any<string?>(), Arg.Any<CancellationToken>()).ConfigureAwait(false);
}

[TestMethod]
[DoNotParallelize]
public async Task ExecuteReleaseAsync_ResolvesChangelogsAgainstTheWorkspace_NotTheCurrentDirectory()
{
// Run from a directory that has its own LATEST_CHANGELOG.md, as running from the KtsuBuild
// checkout does: neither that file nor the bare name may reach the pack or the release.
string elsewhere = TestHelpers.CreateTempDir("ReleaseSvcCwd");
await File.WriteAllTextAsync(Path.Combine(elsewhere, "LATEST_CHANGELOG.md"), "someone else's notes", TestContext.CancellationToken).ConfigureAwait(false);
string original = Directory.GetCurrentDirectory();
ReleaseOptions? captured = null;
_gitHubService.CreateReleaseAsync(Arg.Do<ReleaseOptions>(o => captured = o), Arg.Any<CancellationToken>())
.Returns(Task.CompletedTask);

try
{
Directory.SetCurrentDirectory(elsewhere);
await _service.ExecuteReleaseAsync(CreateDefaultConfig(), _tempDir, "Release", TestContext.CancellationToken).ConfigureAwait(false);
}
finally
{
Directory.SetCurrentDirectory(original);
Directory.Delete(elsewhere, recursive: true);
}

await _dotNetService.Received(1).PackAsync(
_tempDir, Arg.Any<string>(), "Release", Path.Combine(_tempDir, "LATEST_CHANGELOG.md"), Arg.Any<CancellationToken>()).ConfigureAwait(false);
Assert.IsNotNull(captured);
Assert.AreEqual(Path.Combine(_tempDir, "LATEST_CHANGELOG.md"), captured.LatestChangelogFile);
Assert.AreEqual(Path.Combine(_tempDir, "CHANGELOG.md"), captured.ChangelogFile);
}

[TestMethod]
public async Task ExecuteReleaseAsync_KeepsRootedChangelogPathsAsGiven()
{
string rooted = Path.Combine(_tempDir, "notes", "NOTES.md");
BuildConfiguration config = CreateDefaultConfig();
config.LatestChangelogFile = rooted;

await _service.ExecuteReleaseAsync(config, _tempDir, "Release", TestContext.CancellationToken).ConfigureAwait(false);

await _dotNetService.Received(1).PackAsync(
_tempDir, Arg.Any<string>(), "Release", rooted, Arg.Any<CancellationToken>()).ConfigureAwait(false);
}

[TestMethod]
public async Task ExecuteReleaseAsync_PublishesExecutableProjects_ForAllRuntimes()
{
Expand Down Expand Up @@ -342,7 +388,7 @@ private async Task<string> WriteProjectAsync(string relativeDirectory, string fi
{
string projPath = Path.Combine(_tempDir, relativeDirectory, fileName);
Directory.CreateDirectory(Path.GetDirectoryName(projPath)!);
await File.WriteAllTextAsync(projPath, "<Project />").ConfigureAwait(false);
await File.WriteAllTextAsync(projPath, "<Project />", TestContext.CancellationToken).ConfigureAwait(false);
return projPath;
}

Expand Down
17 changes: 14 additions & 3 deletions KtsuBuild/Publishing/ReleaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task ExecuteReleaseAsync(BuildConfiguration config, string workspac
Ensure.NotNull(configuration);

// Pack NuGet packages
await dotNetService.PackAsync(workspace, config.StagingPath, configuration, config.LatestChangelogFile, cancellationToken).ConfigureAwait(false);
await dotNetService.PackAsync(workspace, config.StagingPath, configuration, ResolveInWorkspace(workspace, config.LatestChangelogFile), cancellationToken).ConfigureAwait(false);

await PublishApplicationsAsync(config, workspace, configuration, cancellationToken).ConfigureAwait(false);
await WriteArchiveHashesAsync(config, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -184,8 +184,8 @@ private async Task CreateGitHubReleaseAsync(BuildConfiguration config, string wo
Version = config.Version,
CommitHash = config.ReleaseHash,
GithubToken = config.GithubToken,
ChangelogFile = config.ChangelogFile,
LatestChangelogFile = config.LatestChangelogFile,
ChangelogFile = ResolveInWorkspace(workspace, config.ChangelogFile),
LatestChangelogFile = ResolveInWorkspace(workspace, config.LatestChangelogFile),
AssetPaths = config.AssetPatterns,
IsPrerelease = config.Version.Contains("-pre", StringComparison.OrdinalIgnoreCase)
|| config.Version.Contains("-alpha", StringComparison.OrdinalIgnoreCase)
Expand All @@ -196,4 +196,15 @@ private async Task CreateGitHubReleaseAsync(BuildConfiguration config, string wo

await gitHubService.CreateReleaseAsync(releaseOptions, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Resolves a configured file name against the workspace, the directory the metadata step wrote it to.
/// </summary>
/// <remarks>
/// The changelog names are bare file names by default. Left relative, they resolve against the
/// process's current directory, so a run with <c>--workspace</c> pointing elsewhere shipped packages
/// and releases with no notes, or with the changelog of whatever directory it was started from.
/// </remarks>
private static string ResolveInWorkspace(string workspace, string fileName) =>
string.IsNullOrEmpty(fileName) || Path.IsPathRooted(fileName) ? fileName : Path.Combine(workspace, fileName);
}
Loading