Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5f16453e4 |
14
README.md
14
README.md
@@ -1,15 +1,3 @@
|
||||
# update-tag
|
||||
|
||||
Updates the tag of a repo to the next chosen version according the semver symantic.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
dotnet tool install --global Novaloop.UpdateTag
|
||||
```
|
||||
|
||||
## Update
|
||||
|
||||
```
|
||||
dotnet tool update --global Novaloop.UpdateTag
|
||||
```
|
||||
Updates the tag of a repo to the next chosen version according the semver symantic.
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Commands;
|
||||
using Application.Queries;
|
||||
@@ -20,38 +19,13 @@ namespace Cli
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task Run(string workingDir)
|
||||
{
|
||||
var repoBasePath = await GetRepoBasePath(workingDir);
|
||||
var chosenService = await ChooseService(repoBasePath);
|
||||
var selection = await SelectVersion(repoBasePath, chosenService);
|
||||
await AddVersionTagToRepo(repoBasePath, selection.Version.ToString());
|
||||
await PushTagsToRemote(repoBasePath);
|
||||
await PushCommitsToRemote(repoBasePath);
|
||||
}
|
||||
|
||||
private async Task<string> GetRepoBasePath(string workingDir)
|
||||
{
|
||||
var repoBasePath = "";
|
||||
try
|
||||
{
|
||||
repoBasePath = await _mediator.Send(new GetRepoBasePath.Query(workingDir));
|
||||
}
|
||||
catch (CliWrap.Exceptions.CommandExecutionException)
|
||||
{
|
||||
AnsiConsole.Markup("[red]Error:[/] Unable to extract Versions. Are we running inside a git repository?\n\n");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
return repoBasePath;
|
||||
}
|
||||
|
||||
private async Task<string> ChooseService(string repoBasePath)
|
||||
public async Task Run(string repoPath)
|
||||
{
|
||||
// Check if git dir
|
||||
var services = new List<string>();
|
||||
try
|
||||
{
|
||||
services = await _mediator.Send(new GetServicesFromGitRepo.Query(repoBasePath));
|
||||
services = await _mediator.Send(new GetServicesFromGitRepo.Query(repoPath));
|
||||
}
|
||||
catch (LibGit2Sharp.RepositoryNotFoundException)
|
||||
{
|
||||
@@ -70,12 +44,8 @@ namespace Cli
|
||||
.AddChoices(services));
|
||||
}
|
||||
|
||||
return chosenService;
|
||||
}
|
||||
|
||||
private async Task<Selection> SelectVersion(string repoBasePath, string chosenService)
|
||||
{
|
||||
var versionInfo = await _mediator.Send(new GetVersionInformationFromRepo.Query(repoBasePath, chosenService));
|
||||
var versionInfo = await _mediator.Send(new GetVersionInformationFromRepo.Query(repoPath, chosenService));
|
||||
Selection selection;
|
||||
if (versionInfo != null)
|
||||
{
|
||||
@@ -84,10 +54,10 @@ namespace Cli
|
||||
.Title($"Select new version. (Current version is [green]{versionInfo.CurrentVersion}[/])")
|
||||
.PageSize(10)
|
||||
.AddChoices(
|
||||
versionInfo
|
||||
.NextVersions
|
||||
.Select(nv => new Selection(nv.Title, nv.Version))
|
||||
.ToList()
|
||||
new Selection("rc ", versionInfo.NextMinorRcVersion),
|
||||
new Selection("patch", versionInfo.NextPatchVersion),
|
||||
new Selection("minor", versionInfo.NextMinorVersion),
|
||||
new Selection("major", versionInfo.NextMajorVersion)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -103,15 +73,6 @@ namespace Cli
|
||||
new Selection("no", null)
|
||||
)
|
||||
);
|
||||
var serviceName = AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("[grey][[Optional]][/] Enter [green]service name[/]:")
|
||||
.AllowEmpty()
|
||||
);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(serviceName))
|
||||
{
|
||||
selection.Version.SetService(serviceName.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (selection.Version == null)
|
||||
@@ -119,44 +80,9 @@ namespace Cli
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
private async Task PushTagsToRemote(string workingDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
var output = await _mediator.Send(new PushTagsToRemote.Command(workingDir));
|
||||
AnsiConsole.Write(output);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.Markup("[red]Error:[/] Tag was written but unable to push to remote\n\n");
|
||||
AnsiConsole.WriteException(ex);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PushCommitsToRemote(string workingDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
var output = await _mediator.Send(new PushCommitsToRemote.Command(workingDir));
|
||||
AnsiConsole.Write(output);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.Markup("[red]Error:[/] Tag was written but unable to push to remote\n\n");
|
||||
AnsiConsole.WriteException(ex);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddVersionTagToRepo(string workingDir, string tag)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _mediator.Send(new AddTagToGitRepo.Command(workingDir, tag));
|
||||
await _mediator.Send(new AddTagToGitRepo.Command(repoPath, selection.Version.ToString()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -164,6 +90,17 @@ namespace Cli
|
||||
AnsiConsole.WriteException(ex);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _mediator.Send(new PushCommitsToRemote.Command(repoPath));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.Markup("[red]Error:[/] Tag was written but unable to push to remote\n\n");
|
||||
AnsiConsole.WriteException(ex);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@
|
||||
<PackageId>Novaloop.UpdateTag</PackageId>
|
||||
<title>Updates the tag of a repo to the next chosen version according the semver symantic.</title>
|
||||
<PackageTags>semver;update-tag;tag;git</PackageTags>
|
||||
<Version>0.2.1</Version>
|
||||
<Version>0.1.0</Version>
|
||||
<Authors>Matthias Langhard</Authors>
|
||||
<Company>Novaloop AG</Company>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.update-tag</PackageProjectUrl>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.updatetag</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
namespace Application.Commands
|
||||
{
|
||||
public class PushCommitsToRemote : IRequestHandler<PushCommitsToRemote.Command, string>
|
||||
public class PushCommitsToRemote : RequestHandler<PushCommitsToRemote.Command>
|
||||
{
|
||||
private readonly IGitRepoWriteService _gitRepoWriteService;
|
||||
|
||||
@@ -14,7 +12,7 @@ namespace Application.Queries
|
||||
_gitRepoWriteService = gitRepoWriteService;
|
||||
}
|
||||
|
||||
public class Command : IRequest<string>
|
||||
public class Command : IRequest
|
||||
{
|
||||
public string RepoPath { get; }
|
||||
|
||||
@@ -25,9 +23,9 @@ namespace Application.Queries
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Handle(Command request, CancellationToken ct)
|
||||
protected override void Handle(Command request)
|
||||
{
|
||||
return await _gitRepoWriteService.Push(request.RepoPath, ct);
|
||||
_gitRepoWriteService.Push(request.RepoPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Models;
|
||||
|
||||
namespace Application.Interfaces
|
||||
{
|
||||
public interface IGitRepoReadService
|
||||
{
|
||||
IEnumerable<Version> GetAllVersions(string repoPath);
|
||||
Task<string> GetRepoBasePath(string workingDir);
|
||||
public IEnumerable<Version> GetAllVersions(string repoPath);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Application.Interfaces
|
||||
{
|
||||
public interface IGitRepoWriteService
|
||||
{
|
||||
void AddTag(string repoPath, string tag);
|
||||
Task<string> PushTags(string repoPath, CancellationToken cancellationToken);
|
||||
Task<string> Push(string repoPath, CancellationToken ct);
|
||||
void Push(string repoPath);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -20,7 +19,7 @@ namespace Application.Models
|
||||
Patch = patch;
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, int? rc)
|
||||
public Version(int major, int minor, int patch, int rc)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
@@ -33,16 +32,7 @@ namespace Application.Models
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = rc == null ? null : ExtractNumberFromRcString(rc);
|
||||
Service = service ?? "";
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, int? rc, string service)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = rc;
|
||||
Rc = ExtractNumberFromRcString(rc);
|
||||
Service = service ?? "";
|
||||
}
|
||||
|
||||
@@ -57,7 +47,7 @@ namespace Application.Models
|
||||
public int Minor { get; private set; }
|
||||
public int Patch { get; private set; }
|
||||
public int? Rc { get; private set; }
|
||||
public string Service { get; private set; }
|
||||
public string Service { get; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
@@ -85,123 +75,62 @@ namespace Application.Models
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private Version Copy()
|
||||
{
|
||||
return new Version(Major, Minor, Patch, Rc, Service);
|
||||
}
|
||||
|
||||
public Version NextMajor()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next Major. Release RC first.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Major++;
|
||||
nextVersion.Minor = 0;
|
||||
nextVersion.Patch = 0;
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpMajor();
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version NextMinor()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next Minor. Release RC first.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Minor++;
|
||||
nextVersion.Patch = 0;
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpMinor();
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version NextPatch()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next Patch. Release RC first.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Patch++;
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpPatch();
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version NextRc()
|
||||
{
|
||||
if (Rc == null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next RC. Not an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Rc++;
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpRc();
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version CreatePatchRc()
|
||||
public void BumpMajor()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create RC. Already an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Patch++;
|
||||
nextVersion.Rc = 0;
|
||||
return nextVersion;
|
||||
Major++;
|
||||
Minor = 0;
|
||||
Patch = 0;
|
||||
Rc = null;
|
||||
}
|
||||
|
||||
public Version CreateMinorRc()
|
||||
public void BumpMinor()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create RC. Already an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Minor++;
|
||||
nextVersion.Patch = 0;
|
||||
nextVersion.Rc = 0;
|
||||
return nextVersion;
|
||||
Minor++;
|
||||
Patch = 0;
|
||||
Rc = null;
|
||||
}
|
||||
|
||||
public Version CreateMajorRc()
|
||||
public void BumpPatch()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create RC. Already an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Major++;
|
||||
nextVersion.Minor = 0;
|
||||
nextVersion.Patch = 0;
|
||||
nextVersion.Rc = 0;
|
||||
return nextVersion;
|
||||
Patch++;
|
||||
Rc = null;
|
||||
}
|
||||
|
||||
public Version ReleaseRc()
|
||||
public void BumpRc()
|
||||
{
|
||||
if (Rc == null)
|
||||
{
|
||||
throw new ArgumentException("Cannot release RC. Not an RC.");
|
||||
BumpMinor();
|
||||
}
|
||||
|
||||
var nextVersion = new Version(Major, Minor, Patch, (string)null, Service);
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public bool IsRc()
|
||||
{
|
||||
return Rc != null;
|
||||
}
|
||||
|
||||
public void SetService(string service)
|
||||
{
|
||||
Service = service;
|
||||
Rc = Rc == null ? 0 : Rc + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Application.Models
|
||||
{
|
||||
public class VersionInformation
|
||||
@@ -7,36 +5,16 @@ namespace Application.Models
|
||||
public VersionInformation(Version currentVersion)
|
||||
{
|
||||
CurrentVersion = currentVersion;
|
||||
if (currentVersion.IsRc())
|
||||
{
|
||||
NextVersions.Add(new NextVersion("next rc", currentVersion.NextRc()));
|
||||
NextVersions.Add(new NextVersion("release", currentVersion.ReleaseRc()));
|
||||
}
|
||||
else
|
||||
{
|
||||
NextVersions.Add(new NextVersion("patch-rc", currentVersion.CreatePatchRc()));
|
||||
NextVersions.Add(new NextVersion("minor-rc", currentVersion.CreateMinorRc()));
|
||||
NextVersions.Add(new NextVersion("minor-rc", currentVersion.CreateMajorRc()));
|
||||
NextVersions.Add(new NextVersion("patch ", currentVersion.NextPatch()));
|
||||
NextVersions.Add(new NextVersion("minor ", currentVersion.NextMinor()));
|
||||
NextVersions.Add(new NextVersion("major ", currentVersion.NextMajor()));
|
||||
}
|
||||
NextMajorVersion = currentVersion.NextMajor();
|
||||
NextMinorVersion = currentVersion.NextMinor();
|
||||
NextPatchVersion = currentVersion.NextPatch();
|
||||
NextMinorRcVersion = currentVersion.NextRc();
|
||||
}
|
||||
|
||||
public Version CurrentVersion { get; }
|
||||
|
||||
public List<NextVersion> NextVersions = new List<NextVersion>();
|
||||
}
|
||||
|
||||
public class NextVersion
|
||||
{
|
||||
public NextVersion(string title, Version version)
|
||||
{
|
||||
Title = title;
|
||||
Version = version;
|
||||
}
|
||||
|
||||
public string Title { get; }
|
||||
public Version Version { get; }
|
||||
public Version NextMajorVersion { get; }
|
||||
public Version NextMinorVersion { get; }
|
||||
public Version NextPatchVersion { get; }
|
||||
public Version NextMinorRcVersion { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class GetRepoBasePath : IRequestHandler<GetRepoBasePath.Query, string>
|
||||
{
|
||||
public class Query : IRequest<string>
|
||||
{
|
||||
public Query(string workingDir)
|
||||
{
|
||||
WorkingDir = workingDir;
|
||||
}
|
||||
|
||||
public string WorkingDir { get; }
|
||||
}
|
||||
|
||||
private readonly IGitRepoReadService _gitRepoReadService;
|
||||
|
||||
public GetRepoBasePath(IGitRepoReadService gitRepoReadService)
|
||||
{
|
||||
_gitRepoReadService = gitRepoReadService;
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Handle(Query request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _gitRepoReadService.GetRepoBasePath(request.WorkingDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using Application.Models;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class GetVersionInformationFromRepo : IRequestHandler<GetVersionInformationFromRepo.Query, VersionInformation>
|
||||
public class GetVersionInformationFromRepo : RequestHandler<GetVersionInformationFromRepo.Query, VersionInformation>
|
||||
{
|
||||
public class Query : IRequest<VersionInformation>
|
||||
{
|
||||
@@ -29,7 +27,7 @@ namespace Application.Queries
|
||||
_gitRepoReadService = gitRepoReadService;
|
||||
}
|
||||
|
||||
public async Task<VersionInformation> Handle(Query request, CancellationToken cancellationToken)
|
||||
protected override VersionInformation Handle(Query request)
|
||||
{
|
||||
var versions = _gitRepoReadService
|
||||
.GetAllVersions(request.RepositoryPath);
|
||||
@@ -44,11 +42,10 @@ namespace Application.Queries
|
||||
.OrderByDescending(v => v.Major)
|
||||
.ThenByDescending(v => v.Minor)
|
||||
.ThenByDescending(v => v.Patch)
|
||||
.ThenByDescending(v => v.Rc == null)
|
||||
.ThenByDescending(v => v.Rc)
|
||||
.FirstOrDefault();
|
||||
|
||||
return await Task.FromResult(currentVersion == null ? null : new VersionInformation(currentVersion));
|
||||
return currentVersion == null ? null : new VersionInformation(currentVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class PushTagsToRemote : IRequestHandler<PushTagsToRemote.Command, string>
|
||||
{
|
||||
private readonly IGitRepoWriteService _gitRepoWriteService;
|
||||
|
||||
public PushTagsToRemote(IGitRepoWriteService gitRepoWriteService)
|
||||
{
|
||||
_gitRepoWriteService = gitRepoWriteService;
|
||||
}
|
||||
|
||||
public class Command : IRequest<string>
|
||||
{
|
||||
public string RepoPath { get; }
|
||||
|
||||
public Command(string repoPath)
|
||||
{
|
||||
RepoPath = repoPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Handle(Command request, CancellationToken ct)
|
||||
{
|
||||
return await _gitRepoWriteService.PushTags(request.RepoPath, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliWrap" Version="3.3.3" />
|
||||
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="semver" Version="2.0.6" />
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using CliWrap;
|
||||
using CliWrap.Buffered;
|
||||
using LibGit2Sharp;
|
||||
using Semver;
|
||||
using Version = Application.Models.Version;
|
||||
@@ -11,15 +8,6 @@ namespace Infrastructure.Services
|
||||
{
|
||||
public class GitRepoReadService : IGitRepoReadService
|
||||
{
|
||||
public async Task<string> GetRepoBasePath(string workingDir)
|
||||
{
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("rev-parse --show-toplevel")
|
||||
.WithWorkingDirectory(workingDir)
|
||||
.ExecuteBufferedAsync();
|
||||
return result.StandardOutput.Trim();
|
||||
}
|
||||
|
||||
public IEnumerable<Version> GetAllVersions(string repoPath)
|
||||
{
|
||||
using var repo = new Repository(repoPath);
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using CliWrap;
|
||||
using CliWrap.Buffered;
|
||||
using LibGit2Sharp;
|
||||
|
||||
namespace Infrastructure.Services
|
||||
@@ -15,23 +11,10 @@ namespace Infrastructure.Services
|
||||
repo.ApplyTag(tag);
|
||||
}
|
||||
|
||||
public async Task<string> PushTags(string repoPath, CancellationToken ct)
|
||||
public void Push(string repoPath)
|
||||
{
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("push --tags")
|
||||
.WithWorkingDirectory(repoPath)
|
||||
.ExecuteBufferedAsync(ct);
|
||||
return result.StandardOutput.Trim();
|
||||
}
|
||||
|
||||
public async Task<string> Push(string repoPath, CancellationToken ct)
|
||||
{
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("push")
|
||||
.WithWorkingDirectory(repoPath)
|
||||
.ExecuteBufferedAsync(ct);
|
||||
|
||||
return result.StandardOutput.Trim();
|
||||
using var repo = new Repository(repoPath);
|
||||
repo.Network.Push(repo.Head);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Application.Interfaces;
|
||||
using Application.Models;
|
||||
using Application.Queries;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace UpdateTag.Tests
|
||||
{
|
||||
public class GetVersionInformationFromRepoTests
|
||||
{
|
||||
[Fact]
|
||||
public async void DoesReadCurrentVersionCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var mockedVersionList = new List<Version>
|
||||
{
|
||||
new Version(0, 1, 5),
|
||||
new Version(0, 1, 7),
|
||||
new Version(0, 2, 0),
|
||||
new Version(0, 2, 0, 0),
|
||||
new Version(0, 2, 0, 1),
|
||||
new Version(0, 2, 0, 2)
|
||||
};
|
||||
var gitRepoMock = new Mock<IGitRepoReadService>();
|
||||
gitRepoMock.Setup(m => m.GetAllVersions(It.IsAny<string>()))
|
||||
.Returns(mockedVersionList);
|
||||
var handler = new GetVersionInformationFromRepo(gitRepoMock.Object);
|
||||
var query = new GetVersionInformationFromRepo.Query("");
|
||||
|
||||
// Act
|
||||
var versionInformation = await handler.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("0.2.0", versionInformation.CurrentVersion.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using System.Linq;
|
||||
using Application.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace UpdateTag.Tests
|
||||
{
|
||||
public class VersionInformationTests
|
||||
{
|
||||
[Fact]
|
||||
public void CorrectNextVersionsFromRc()
|
||||
|
||||
{
|
||||
// Arrange
|
||||
var version = new Version(1, 0, 1, 1);
|
||||
|
||||
// Act
|
||||
var versionInformation = new VersionInformation(version);
|
||||
var versions = versionInformation.NextVersions.Select(nv => nv.Version.ToString()).ToList();
|
||||
|
||||
// Assert
|
||||
Assert.Contains("1.0.1-RC.2", versions); // next rc
|
||||
Assert.Contains("1.0.1", versions); // release rc
|
||||
Assert.Equal(2, versions.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CorrectNextVersionsFromNonRc()
|
||||
|
||||
{
|
||||
// Arrange
|
||||
var version = new Version(1, 0, 1);
|
||||
|
||||
// Act
|
||||
var versionInformation = new VersionInformation(version);
|
||||
var versions = versionInformation.NextVersions.Select(nv => nv.Version.ToString()).ToList();
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Contains("1.0.2-RC.0", versions); // patch RC
|
||||
Assert.Contains("1.1.0-RC.0", versions); // minor RC
|
||||
Assert.Contains("2.0.0-RC.0", versions); // major RC
|
||||
Assert.Contains("1.0.2", versions); // next patch
|
||||
Assert.Contains("1.1.0", versions); // next minor
|
||||
Assert.Contains("2.0.0", versions); // next major
|
||||
Assert.Equal(6, versions.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,13 @@ namespace UpdateTag.Tests
|
||||
[InlineData(1, 0, 0, "", "", "2.0.0")]
|
||||
[InlineData(1, 1, 0, "", "", "2.0.0")]
|
||||
[InlineData(1, 1, 1, "", "", "2.0.0")]
|
||||
public void NextMajor(int major, int minor, int patch, string rc, string service, string expected)
|
||||
[InlineData(1, 1, 1, "RC.4", "", "2.0.0")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "2.0.0+ErpNext")]
|
||||
public void BumpMajor(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).NextMajor();
|
||||
var version = new Version(major, minor, patch, rc, service);
|
||||
version.BumpMajor();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
@@ -21,10 +24,13 @@ namespace UpdateTag.Tests
|
||||
[InlineData(1, 0, 0, "", "", "1.1.0")]
|
||||
[InlineData(1, 1, 0, "", "", "1.2.0")]
|
||||
[InlineData(1, 1, 1, "", "", "1.2.0")]
|
||||
public void NextMinor(int major, int minor, int patch, string rc, string service, string expected)
|
||||
[InlineData(1, 1, 1, "RC.4", "", "1.2.0")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "1.2.0+ErpNext")]
|
||||
public void BumpMinor(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).NextMinor();
|
||||
var version = new Version(major, minor, patch, rc, service);
|
||||
version.BumpMinor();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
@@ -32,56 +38,27 @@ namespace UpdateTag.Tests
|
||||
[InlineData(1, 0, 0, "", "", "1.0.1")]
|
||||
[InlineData(1, 1, 0, "", "", "1.1.1")]
|
||||
[InlineData(1, 1, 1, "", "", "1.1.2")]
|
||||
public void NextPatch(int major, int minor, int patch, string rc, string service, string expected)
|
||||
[InlineData(1, 1, 1, "RC.4", "", "1.1.2")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "1.1.2+ErpNext")]
|
||||
public void BumpPatch(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).NextPatch();
|
||||
var version = new Version(major, minor, patch, rc, service);
|
||||
version.BumpPatch();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 0, 0, "", "", "1.1.0-RC.0")]
|
||||
[InlineData(1, 1, 0, "", "", "1.2.0-RC.0")]
|
||||
[InlineData(1, 1, 1, "", "", "1.2.0-RC.0")]
|
||||
[InlineData(1, 1, 1, "RC.4", "", "1.1.1-RC.5")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "1.1.1-RC.5+ErpNext")]
|
||||
public void NextRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
public void BumpRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).NextRc();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, null, "", "1.1.2-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "1.1.2-RC.0+ErpNext")]
|
||||
public void CreatePatchRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).CreatePatchRc();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, null, "", "1.2.0-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "1.2.0-RC.0+ErpNext")]
|
||||
public void CreateMinorRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).CreateMinorRc();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, null, "", "2.0.0-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "2.0.0-RC.0+ErpNext")]
|
||||
public void CreateMajroRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).CreateMajorRc();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, "RC.4", "", "1.1.1")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "1.1.1+ErpNext")]
|
||||
public void ReleaseRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
{
|
||||
var version = new Version(major, minor, patch, rc, service).ReleaseRc();
|
||||
var version = new Version(major, minor, patch, rc, service);
|
||||
version.BumpRc();
|
||||
Assert.Equal(expected, version.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
Reference in New Issue
Block a user