Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 21, 2024
2 parents f48dcb7 + 538fcbe commit f920fa8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup .NET
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.102
dotnet-version: 8.0.*
- name: Install dependencies
run: dotnet restore Synthesis.Bethesda.sln
- name: Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Synthesis.Bethesda.Execution.Settings;
using Synthesis.Bethesda.Execution.Versioning;
using Synthesis.Bethesda.UnitTests.AutoData;
using Xunit;
using ILogger = Serilog.ILogger;

namespace Synthesis.Bethesda.UnitTests.Execution.Patchers.Git.PrepareRunner;
Expand Down Expand Up @@ -65,10 +64,10 @@ public Commit AddACommit(string path)
}

[DebuggerStepThrough]
public GitPatcherVersioning TypicalPatcherVersioning() =>
public GitPatcherVersioning TypicalPatcherVersioning(string defaultBranchName) =>
new(
PatcherVersioningEnum.Branch,
DefaultBranch);
defaultBranchName);

[DebuggerStepThrough]
public NugetsVersioningTarget TypicalNugetVersioning() =>
Expand All @@ -95,11 +94,12 @@ public async Task CreatesRunnerBranch()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var resp = await Get(local).Checkout(
new CheckoutInput(
ProjPath,
TypicalPatcherVersioning(),
TypicalPatcherVersioning(defaultBranchName),
TypicalNugetVersioning()),
cancel: CancellationToken.None);
using var repo = new Repository(local);
Expand All @@ -111,11 +111,12 @@ public async Task NonExistentProjPath()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var resp = await Get(local).Checkout(
new CheckoutInput(
string.Empty,
TypicalPatcherVersioning(),
TypicalPatcherVersioning(defaultBranchName),
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.IsHaltingError.Should().BeTrue();
Expand All @@ -129,11 +130,12 @@ public async Task NonExistentSlnPath()
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local,
out var defaultBranchName,
createPatcherFiles: false);
var resp = await Get(local).Checkout(
new CheckoutInput(
ProjPath,
TypicalPatcherVersioning(),
TypicalPatcherVersioning(defaultBranchName),
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.IsHaltingError.Should().BeTrue();
Expand All @@ -146,7 +148,8 @@ public async Task UnknownSha()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Commit, "46c207318c1531de7dc2f8e8c2a91aced183bc30");
var resp = await Get(local).Checkout(
new CheckoutInput(
Expand All @@ -164,7 +167,8 @@ public async Task MalformedSha()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Commit, "derp");
var resp = await Get(local).Checkout(
new CheckoutInput(
Expand All @@ -182,7 +186,8 @@ public async Task TagTarget()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var tagStr = "1.3.4";
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;
Expand All @@ -194,6 +199,7 @@ public async Task TagTarget()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
repo.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
Expand All @@ -205,7 +211,8 @@ public async Task TagTargetNoLocal()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var tagStr = "1.3.4";
string tipSha;
{
Expand All @@ -228,6 +235,7 @@ public async Task TagTargetNoLocal()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
Expand All @@ -239,7 +247,8 @@ public async Task TagTargetJumpback()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var tag = "1.3.4";
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;
Expand All @@ -255,6 +264,7 @@ public async Task TagTargetJumpback()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
repo.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
Expand All @@ -266,7 +276,8 @@ public async Task TagTargetNewContent()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);

var clonePath = Path.Combine(repoPath.Dir.Path, "Clone");
using var clone = new Repository(Repository.Clone(remote, clonePath));
Expand All @@ -288,6 +299,7 @@ public async Task TagTargetNewContent()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(commitSha);
Expand All @@ -299,7 +311,8 @@ public async Task CommitTargetJumpback()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;

Expand All @@ -313,6 +326,7 @@ public async Task CommitTargetJumpback()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
repo.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
Expand All @@ -324,7 +338,8 @@ public async Task CommitTargetNoLocal()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
string tipSha;
{
using var repo = new Repository(local);
Expand All @@ -344,6 +359,7 @@ public async Task CommitTargetNoLocal()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
Expand All @@ -355,7 +371,8 @@ public async Task CommitTargetNewContent()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);

var clonePath = Path.Combine(repoPath.Dir.Path, "Clone");
using var clone = new Repository(Repository.Clone(remote, clonePath));
Expand All @@ -376,6 +393,7 @@ public async Task CommitTargetNewContent()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(commitSha);
Expand All @@ -387,7 +405,8 @@ public async Task BranchTargetJumpback()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;
var jbName = "Jumpback";
Expand All @@ -408,20 +427,22 @@ public async Task BranchTargetJumpback()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
repo.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
repo.Head.FriendlyName.Should().BeEquivalentTo(CheckoutRunnerBranch.RunnerBranch);
repo.Branches[jbName].Tip.Sha.Should().BeEquivalentTo(tipSha);
repo.Branches[DefaultBranch].Tip.Sha.Should().BeEquivalentTo(commit.Sha);
repo.Branches[defaultBranchName].Tip.Sha.Should().BeEquivalentTo(commit.Sha);
}

[Fact]
public async Task BranchTargetNoLocal()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var jbName = "Jumpback";
string tipSha;
string commitSha;
Expand All @@ -438,7 +459,7 @@ public async Task BranchTargetNoLocal()
repo.Branches.Remove(jbName);
commitSha = AddACommit(local).Sha;
repo.Head.Tip.Sha.Should().NotBeEquivalentTo(tipSha);
repo.Network.Push(repo.Branches[DefaultBranch]);
repo.Network.Push(repo.Branches[defaultBranchName]);
}

var clonePath = Path.Combine(repoPath.Dir.Path, "Clone");
Expand All @@ -451,20 +472,22 @@ public async Task BranchTargetNoLocal()
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
clone.Head.FriendlyName.Should().BeEquivalentTo(CheckoutRunnerBranch.RunnerBranch);
clone.Branches[jbName].Should().BeNull();
clone.Branches[DefaultBranch].Tip.Sha.Should().BeEquivalentTo(commitSha);
clone.Branches[defaultBranchName].Tip.Sha.Should().BeEquivalentTo(commitSha);
}

[Fact]
public async Task BranchNewContent()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
string tipSha;
string commitSha;

Expand All @@ -475,21 +498,22 @@ public async Task BranchNewContent()
tipSha = repo.Head.Tip.Sha;
commitSha = AddACommit(local).Sha;
repo.Head.Tip.Sha.Should().NotBeEquivalentTo(tipSha);
repo.Network.Push(repo.Branches[DefaultBranch]);
repo.Network.Push(repo.Branches[defaultBranchName]);
}

var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Branch, $"origin/{DefaultBranch}");
var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Branch, $"origin/{defaultBranchName}");
var resp = await Get(clonePath).Checkout(
new CheckoutInput(
ProjPath,
versioning,
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.RunnableState.Exception.Should().BeNull();
resp.IsHaltingError.Should().BeFalse();
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(commitSha);
clone.Head.FriendlyName.Should().BeEquivalentTo(CheckoutRunnerBranch.RunnerBranch);
clone.Branches[DefaultBranch].Tip.Sha.Should().BeEquivalentTo(tipSha);
clone.Branches[defaultBranchName].Tip.Sha.Should().BeEquivalentTo(tipSha);
}
#endregion
}
14 changes: 7 additions & 7 deletions Synthesis.Bethesda.UnitTests/RepoTestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using Mutagen.Bethesda.Synthesis.Versioning;
using Noggog;
using Noggog.IO;
using Noggog.Utility;

namespace Synthesis.Bethesda.UnitTests;

public class RepoTestUtility
{
public string DefaultBranch => "dev";
public string AFile => "Somefile.txt";
public string SlnPath => "Solution.sln";
public string ProjPath => "MyProj/MyProj.csproj";
Expand All @@ -21,6 +19,7 @@ public TempFolder GetRepository(
string folderName,
out DirectoryPath remote,
out DirectoryPath local,
out string defaultBranchName,
bool createPatcherFiles = true,
[CallerMemberName] string? testName = null)
{
Expand All @@ -38,7 +37,9 @@ public TempFolder GetRepository(
LibGit2Sharp.Commands.Stage(localRepo, AFile);
var sig = Signature;
localRepo.Commit("Initial commit", sig, sig);

var defaultBranch = localRepo.Branches.First();
defaultBranchName = defaultBranch.FriendlyName;

if (createPatcherFiles)
{
var files = new CreateSolutionFile(IFileSystemExt.DefaultFilesystem, new ExportStringToFile()).Create(Path.Combine(local, SlnPath))
Expand All @@ -57,12 +58,11 @@ public TempFolder GetRepository(
}

var remoteRef = localRepo.Network.Remotes.Add("origin", remote);
var master = localRepo.Branches[DefaultBranch];
localRepo.Branches.Update(
master,
defaultBranch,
b => b.Remote = remoteRef.Name,
b => b.UpstreamBranch = master.CanonicalName);
localRepo.Network.Push(master);
b => b.UpstreamBranch = defaultBranch.CanonicalName);
localRepo.Network.Push(defaultBranch);

return folder;
}
Expand Down

0 comments on commit f920fa8

Please sign in to comment.