Compare commits
5 Commits
set-sast-c
...
v0.3.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d2c1d8f63 | ||
|
|
aeae68b5c4 | ||
|
|
3acdb3e38c | ||
|
|
350edb9763 | ||
|
|
9c313526e7 |
@@ -1,26 +1,18 @@
|
||||
# You can override the included template(s) by including variable overrides
|
||||
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
|
||||
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
|
||||
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
|
||||
# Note that environment variables can be set in several places
|
||||
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
|
||||
stages:
|
||||
- test
|
||||
- publish
|
||||
- test
|
||||
- publish
|
||||
|
||||
running tests for tag:
|
||||
image: mcr.microsoft.com/dotnet/sdk:5.0
|
||||
stage: test
|
||||
script:
|
||||
- dotnet test tests/update-tag.tests
|
||||
- dotnet test tests/update-tag.tests
|
||||
|
||||
publish to nuget:
|
||||
only:
|
||||
- "/^\\d*.\\d*.\\d*$/"
|
||||
- /^v+\d*.\d*.\d*$/ # gets triggered if the commit tag is in the form n.n.n where n is any number
|
||||
image: mcr.microsoft.com/dotnet/sdk:5.0
|
||||
stage: publish
|
||||
script:
|
||||
- dotnet pack src/Cli -o ./packaged
|
||||
- dotnet nuget push ./packaged/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json
|
||||
sast:
|
||||
stage: test
|
||||
include:
|
||||
- template: Security/SAST.gitlab-ci.yml
|
||||
- dotnet pack src/Cli -o ./packaged
|
||||
- dotnet nuget push ./packaged/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json
|
||||
|
||||
@@ -103,6 +103,15 @@ 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)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<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.7</Version>
|
||||
<Version>0.3.1</Version>
|
||||
<Authors>Matthias Langhard</Authors>
|
||||
<Company>Novaloop AG</Company>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.update-tag</PackageProjectUrl>
|
||||
|
||||
@@ -57,12 +57,13 @@ 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; }
|
||||
public string Service { get; private set; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append('v');
|
||||
sb.Append(Major);
|
||||
sb.Append('.');
|
||||
sb.Append(Minor);
|
||||
@@ -198,5 +199,10 @@ namespace Application.Models
|
||||
{
|
||||
return Rc != null;
|
||||
}
|
||||
|
||||
public void SetService(string service)
|
||||
{
|
||||
Service = service;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
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 : RequestHandler<GetVersionInformationFromRepo.Query, VersionInformation>
|
||||
public class GetVersionInformationFromRepo : IRequestHandler<GetVersionInformationFromRepo.Query, VersionInformation>
|
||||
{
|
||||
public class Query : IRequest<VersionInformation>
|
||||
{
|
||||
@@ -27,7 +29,7 @@ namespace Application.Queries
|
||||
_gitRepoReadService = gitRepoReadService;
|
||||
}
|
||||
|
||||
protected override VersionInformation Handle(Query request)
|
||||
public async Task<VersionInformation> Handle(Query request, CancellationToken cancellationToken)
|
||||
{
|
||||
var versions = _gitRepoReadService
|
||||
.GetAllVersions(request.RepositoryPath);
|
||||
@@ -42,10 +44,11 @@ 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 currentVersion == null ? null : new VersionInformation(currentVersion);
|
||||
return await Task.FromResult(currentVersion == null ? null : new VersionInformation(currentVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
39
tests/update-tag.tests/GetVersionInformationFromRepoTests.cs
Normal file
39
tests/update-tag.tests/GetVersionInformationFromRepoTests.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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("v0.2.0", versionInformation.CurrentVersion.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ namespace UpdateTag.Tests
|
||||
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.Contains("v1.0.1-RC.2", versions); // next rc
|
||||
Assert.Contains("v1.0.1", versions); // release rc
|
||||
Assert.Equal(2, versions.Count);
|
||||
}
|
||||
|
||||
@@ -36,12 +36,12 @@ namespace UpdateTag.Tests
|
||||
|
||||
|
||||
// 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.Contains("v1.0.2-RC.0", versions); // patch RC
|
||||
Assert.Contains("v1.1.0-RC.0", versions); // minor RC
|
||||
Assert.Contains("v2.0.0-RC.0", versions); // major RC
|
||||
Assert.Contains("v1.0.2", versions); // next patch
|
||||
Assert.Contains("v1.1.0", versions); // next minor
|
||||
Assert.Contains("v2.0.0", versions); // next major
|
||||
Assert.Equal(6, versions.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace UpdateTag.Tests
|
||||
public class VersionTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(1, 0, 0, "", "", "2.0.0")]
|
||||
[InlineData(1, 1, 0, "", "", "2.0.0")]
|
||||
[InlineData(1, 1, 1, "", "", "2.0.0")]
|
||||
[InlineData(1, 0, 0, "", "", "v2.0.0")]
|
||||
[InlineData(1, 1, 0, "", "", "v2.0.0")]
|
||||
[InlineData(1, 1, 1, "", "", "v2.0.0")]
|
||||
public void NextMajor(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
@@ -18,9 +18,9 @@ namespace UpdateTag.Tests
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 0, 0, "", "", "1.1.0")]
|
||||
[InlineData(1, 1, 0, "", "", "1.2.0")]
|
||||
[InlineData(1, 1, 1, "", "", "1.2.0")]
|
||||
[InlineData(1, 0, 0, "", "", "v1.1.0")]
|
||||
[InlineData(1, 1, 0, "", "", "v1.2.0")]
|
||||
[InlineData(1, 1, 1, "", "", "v1.2.0")]
|
||||
public void NextMinor(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
@@ -29,9 +29,9 @@ namespace UpdateTag.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 0, 0, "", "", "1.0.1")]
|
||||
[InlineData(1, 1, 0, "", "", "1.1.1")]
|
||||
[InlineData(1, 1, 1, "", "", "1.1.2")]
|
||||
[InlineData(1, 0, 0, "", "", "v1.0.1")]
|
||||
[InlineData(1, 1, 0, "", "", "v1.1.1")]
|
||||
[InlineData(1, 1, 1, "", "", "v1.1.2")]
|
||||
public void NextPatch(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
@@ -40,8 +40,8 @@ namespace UpdateTag.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, "RC.4", "", "1.1.1-RC.5")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "1.1.1-RC.5+ErpNext")]
|
||||
[InlineData(1, 1, 1, "RC.4", "", "v1.1.1-RC.5")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "v1.1.1-RC.5+ErpNext")]
|
||||
public void NextRc(int major, int minor, int patch, string rc, string service, string expected)
|
||||
|
||||
{
|
||||
@@ -50,8 +50,8 @@ namespace UpdateTag.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, null, "", "1.1.2-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "1.1.2-RC.0+ErpNext")]
|
||||
[InlineData(1, 1, 1, null, "", "v1.1.2-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "v1.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();
|
||||
@@ -59,8 +59,8 @@ namespace UpdateTag.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, null, "", "1.2.0-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "1.2.0-RC.0+ErpNext")]
|
||||
[InlineData(1, 1, 1, null, "", "v1.2.0-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "v1.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();
|
||||
@@ -68,8 +68,8 @@ namespace UpdateTag.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, null, "", "2.0.0-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "2.0.0-RC.0+ErpNext")]
|
||||
[InlineData(1, 1, 1, null, "", "v2.0.0-RC.0")]
|
||||
[InlineData(1, 1, 1, null, "ErpNext", "v2.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();
|
||||
@@ -77,8 +77,8 @@ namespace UpdateTag.Tests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1, 1, "RC.4", "", "1.1.1")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "1.1.1+ErpNext")]
|
||||
[InlineData(1, 1, 1, "RC.4", "", "v1.1.1")]
|
||||
[InlineData(1, 1, 1, "RC.4", "ErpNext", "v1.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();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<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