Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbf09be431 | ||
|
|
808f0e4564 | ||
|
|
0ca934cfa8 | ||
|
|
189cbe0ae8 | ||
|
|
0cdd2aa4be |
@@ -3,6 +3,13 @@
|
||||
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
|
||||
```
|
||||
@@ -26,7 +26,8 @@ namespace Cli
|
||||
var chosenService = await ChooseService(repoBasePath);
|
||||
var selection = await SelectVersion(repoBasePath, chosenService);
|
||||
await AddVersionTagToRepo(repoBasePath, selection.Version.ToString());
|
||||
await PushToRemote(repoBasePath);
|
||||
await PushTagsToRemote(repoBasePath);
|
||||
await PushCommitsToRemote(repoBasePath);
|
||||
}
|
||||
|
||||
private async Task<string> GetRepoBasePath(string workingDir)
|
||||
@@ -112,11 +113,27 @@ namespace Cli
|
||||
return selection;
|
||||
}
|
||||
|
||||
private async Task PushToRemote(string workingDir)
|
||||
private async Task PushTagsToRemote(string workingDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _mediator.Send(new PushCommitsToRemote.Command(workingDir));
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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.1.2</Version>
|
||||
<Version>0.1.7</Version>
|
||||
<Authors>Matthias Langhard</Authors>
|
||||
<Company>Novaloop AG</Company>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.updatetag</PackageProjectUrl>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.update-tag</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Application.Interfaces
|
||||
@@ -5,6 +6,7 @@ namespace Application.Interfaces
|
||||
public interface IGitRepoWriteService
|
||||
{
|
||||
void AddTag(string repoPath, string tag);
|
||||
Task Push(string repoPath);
|
||||
Task<string> PushTags(string repoPath, CancellationToken cancellationToken);
|
||||
Task<string> Push(string repoPath, CancellationToken ct);
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ namespace Application.Models
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version CreateRc()
|
||||
public Version CreatePatchRc()
|
||||
{
|
||||
if (Rc != null)
|
||||
{
|
||||
@@ -149,6 +149,36 @@ namespace Application.Models
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Patch++;
|
||||
nextVersion.Rc = 0;
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version CreateMinorRc()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public Version CreateMajorRc()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ namespace Application.Models
|
||||
}
|
||||
else
|
||||
{
|
||||
NextVersions.Add(new NextVersion("rc", currentVersion.CreateRc()));
|
||||
NextVersions.Add(new NextVersion("patch", currentVersion.NextPatch()));
|
||||
NextVersions.Add(new NextVersion("minor", currentVersion.NextMinor()));
|
||||
NextVersions.Add(new NextVersion("major", currentVersion.NextMajor()));
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Commands
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class PushCommitsToRemote : AsyncRequestHandler<PushCommitsToRemote.Command>
|
||||
public class PushCommitsToRemote : IRequestHandler<PushCommitsToRemote.Command, string>
|
||||
{
|
||||
private readonly IGitRepoWriteService _gitRepoWriteService;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Application.Commands
|
||||
_gitRepoWriteService = gitRepoWriteService;
|
||||
}
|
||||
|
||||
public class Command : IRequest
|
||||
public class Command : IRequest<string>
|
||||
{
|
||||
public string RepoPath { get; }
|
||||
|
||||
@@ -24,9 +24,10 @@ namespace Application.Commands
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
|
||||
public async Task<string> Handle(Command request, CancellationToken ct)
|
||||
{
|
||||
await _gitRepoWriteService.Push(request.RepoPath);
|
||||
return await _gitRepoWriteService.Push(request.RepoPath, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/Core/Queries/PushTagsToRemote.cs
Normal file
33
src/Core/Queries/PushTagsToRemote.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using CliWrap;
|
||||
@@ -14,12 +15,23 @@ namespace Infrastructure.Services
|
||||
repo.ApplyTag(tag);
|
||||
}
|
||||
|
||||
public async Task Push(string repoPath)
|
||||
public async Task<string> PushTags(string repoPath, CancellationToken ct)
|
||||
{
|
||||
await Cli.Wrap("git")
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("push --tags")
|
||||
.WithWorkingDirectory(repoPath)
|
||||
.ExecuteBufferedAsync();
|
||||
.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@ namespace UpdateTag.Tests
|
||||
var versions = versionInformation.NextVersions.Select(nv => nv.Version.ToString()).ToList();
|
||||
|
||||
// Assert
|
||||
Assert.Contains("1.0.1-RC.2", versions);
|
||||
Assert.Contains("1.0.1", versions);
|
||||
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 CorrectNextVersionsFromMinor()
|
||||
public void CorrectNextVersionsFromNonRc()
|
||||
|
||||
{
|
||||
// Arrange
|
||||
@@ -36,11 +36,13 @@ namespace UpdateTag.Tests
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Contains("1.0.1-RC.0", versions);
|
||||
Assert.Contains("1.0.2", versions);
|
||||
Assert.Contains("1.1.0", versions);
|
||||
Assert.Contains("2.0.0", versions);
|
||||
Assert.Equal(4, versions.Count);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,33 @@ namespace UpdateTag.Tests
|
||||
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")]
|
||||
|
||||
Reference in New Issue
Block a user