Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jun 11, 2023
2 parents c84f35b + c0d31ae commit 79a0959
Show file tree
Hide file tree
Showing 36 changed files with 1,429 additions and 1,527 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

jobs:
build:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:

#-----------------------------------------------------------------------
Expand All @@ -19,11 +19,10 @@ jobs:

- name: Extract branch name
id: extract_branch_name
# if: startsWith( github.ref, 'refs/tags/' )
run: |
$branch_name=$(git name-rev --name-only --exclude=tags/* HEAD)
export branch_name=`git name-rev --name-only --exclude=tags/* HEAD`
echo "Detected current branch: ${branch_name}"
echo "::set-output name=branch_name::${branch_name}"
echo "branch_name=${branch_name}" >> $GITHUB_OUTPUT
#-----------------------------------------------------------------------
# Setup environments
Expand Down Expand Up @@ -51,38 +50,38 @@ jobs:

- name: Setup NuGet package reference
run: |
dotnet nuget add source ${{secrets.GH_LOCAL_NUGET_URL}} -n ref1 -u ${{secrets.GH_LOCAL_NUGET_USER}} -p ${{secrets.GH_LOCAL_NUGET_PASSWORD}} --store-password-in-clear-text --configfile nuget.config
# dotnet nuget add source ${{secrets.GH_LOCAL_NUGET_URL}} -n ref1 -u ${{secrets.GH_LOCAL_NUGET_USER}} -p ${{secrets.GH_LOCAL_NUGET_PASSWORD}} --store-password-in-clear-text --configfile nuget.config
# dotnet nuget add source ${{secrets.GH_NUGET_URL}} -n ref2 -u ${{secrets.GH_NUGET_USER}} -p ${{secrets.GH_NUGET_PASSWORD}} --store-password-in-clear-text --configfile nuget.config

#-----------------------------------------------------------------------
# Build

- name: NuGet restore
run: dotnet restore -p:Configuration=Release CenterCLR.RelaxVersioner.sln

- name: Build
run: dotnet build -p:Configuration=Release -p:BuildIdentifier=${GITHUB_RUN_NUMBER} CenterCLR.RelaxVersioner.sln

- name: Build NuGet packages
run: dotnet pack -p:Configuration=Release -p:BuildIdentifier=${GITHUB_RUN_NUMBER} -o artifacts CenterCLR.RelaxVersioner\CenterCLR.RelaxVersioner.csproj
run: dotnet pack -p:Configuration=Release -p:BuildIdentifier=${GITHUB_RUN_NUMBER} -o artifacts CenterCLR.RelaxVersioner.sln

#-----------------------------------------------------------------------
# Test

#- name: Test
# run: dotnet test --no-restore --verbosity normal -p:CITest=True CenterCLR.RelaxVersioner.sln
# timeout-minutes: 10
- name: Test
run: dotnet test --no-restore --verbosity normal -p:CITest=True CenterCLR.RelaxVersioner.sln
timeout-minutes: 2

#-----------------------------------------------------------------------
# Deploy packages (develop)

- name: Deploy NuGet package (develop/ref1)
if: startsWith( github.ref, 'refs/tags/' )
run: dotnet nuget push artifacts\RelaxVersioner.*.nupkg --source ref1
#- name: Deploy NuGet package (develop/ref1)
# if: startsWith( github.ref, 'refs/tags/' )
# run: dotnet nuget push artifacts/RelaxVersioner.*.nupkg --source ref1

#-----------------------------------------------------------------------
# Deploy packages (main)

#- name: Deploy NuGet package (main/ref2)
# if: (startsWith( github.ref, 'refs/tags/' )) && (endsWith(steps.extract_branch_name.outputs.branch_name, 'main'))
# run: dotnet nuget push artifacts\RelaxVersioner.*.nupkg --source ref2 --api-key ${{secrets.GH_NUGET_APIKEY}}
# run: dotnet nuget push artifacts/RelaxVersioner.*.nupkg --source ref1
114 changes: 114 additions & 0 deletions CenterCLR.RelaxVersioner.Core/Analyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
////////////////////////////////////////////////////////////////////////////////////////
//
// RelaxVersioner - Git tag/branch based, full-automatic version information inserter.
// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud)
//
// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0
//
////////////////////////////////////////////////////////////////////////////////////////

#nullable enable

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using GitReader.Structures;

namespace RelaxVersioner;

internal static class Analyzer
{
private readonly struct TargetCommit
{
public readonly int StartDepth;
public readonly Commit Commit;

public TargetCommit(int startDepth, Commit commit)
{
this.StartDepth = startDepth;
this.Commit = commit;
}

public override string ToString() =>
$"StartDepth={this.StartDepth}, {this.Commit}";
}

public static async Task<Version> LookupVersionLabelAsync(
Branch targetBranch, CancellationToken ct)
{
var topCommit = await targetBranch.GetHeadCommitAsync(ct);

var reached = new HashSet<Commit>();
var scheduled = new Stack<TargetCommit>();
scheduled.Push(new TargetCommit(0, topCommit));

var mainDepth = 0;

while (scheduled.Count >= 1)
{
// Extract an analysis commit.
var entry = scheduled.Pop();

var currentCommit = entry.Commit;
var currentDepth = entry.StartDepth;

while (true)
{
// Rejoined parent branch.
if (!reached.Add(currentCommit))
{
break;
}

// If found be applied tags at this commit:
if (currentCommit.Tags.Count >= 1)
{
var filteredTags = currentCommit.Tags.
Select(tag => Version.TryParse(tag.Name, out var version) ? (Version?)version : null).
Where(version => version.HasValue).
Select(version => Utilities.IncrementLastVersionComponent(version!.Value, currentDepth)).
ToArray();

// Found first valid tag.
if (filteredTags.Length >= 1)
{
return filteredTags[0];
}
}

// Found parents.
if (await currentCommit.GetParentCommitsAsync(ct) is { Length: >= 1 } parents)
{
// Dive parent commit.
currentDepth++;

// Next commit is a primary parent.
currentCommit = parents[0];

// Enqueue analysis scheduling if it has multiple parents.
foreach (var parentCommit in parents.Skip(1))
{
scheduled.Push(new TargetCommit(currentDepth, parentCommit));
}
}
// Bottom of branch.
else
{
// Save depth if it's on boarding the main branch.
if (mainDepth == 0)
{
mainDepth = currentDepth;
}

// Goes to next scheduled commit.
break;
}
}
}

// Finally got the main branch depth.
return Utilities.IncrementLastVersionComponent(Version.Default, mainDepth);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NamingFormatter" Version="2.1.0" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0096" />
<PackageReference Include="GitReader" Version="0.12.0" />
<PackageReference Include="NamingFormatter" Version="2.2.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
<PackageReference Include="RelaxVersioner" Version="2.13.10" PrivateAssets="all" />
<PackageReference Include="RelaxVersioner" Version="2.14.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
26 changes: 13 additions & 13 deletions CenterCLR.RelaxVersioner.Core/DefaultRuleSet.rules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
RelaxVersioner - Easy-usage, Git-based, auto-generate version informations toolset.
RelaxVersioner - Git tag/branch based, full-automatic version information inserter.
Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud)
Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0
Expand Down Expand Up @@ -30,39 +30,39 @@

<!--
"safeVersion" extracts committed date (from commmiter) from git repository HEAD.
"safeVersion" specialized from "committer.When".
(The format is safe-numerical-notate version string [2016.2.14.12345]. (Last number is 2sec prec.))
-->
<Rule name="AssemblyFileVersion">{safeVersion}</Rule>

<!--
"commitId" extracts commit id from git repository HEAD.
"commitId" alias to "commit.Sha".
"commitId" alias to "commit.Hash".
-->
<Rule name="AssemblyInformationalVersion">{versionLabel}-{commitId}</Rule>

<Rule name="AssemblyConfiguration">{Configuration}</Rule>

<!--
"key" attribute can only use with "AssemblyMetadataAttribute".
"committer.When" or you can use another choice "author.When".
"branch" can use property "FriendlyName" and "CanonicalName". (Derived from libgit2sharp)
"author" and "committer" can use property "Name", "Email", and "When". (Derived from libgit2sharp)
"buildIdentifier" is passing from MSBuild property named "RelaxVersionerBuildIdentifier" or "BuildIdentifier". We can use in CI building.
"branch" can use field "Name". (Derived from GitReader)
"author" and "committer" can use field "Name", "MailAddress", and "Date". (Derived from GitReader)
"buildIdentifier" is passing from MSBuild property named "RelaxVersionerBuildIdentifier" or "BuildIdentifier".
We can use in CI building.
"generated" is generated date by RelaxVersioner.
You can apply format directives same as string.Format().
-->
<Rule name="AssemblyMetadata" key="CommitId">{commitId}</Rule>
<Rule name="AssemblyMetadata" key="Date">{committer.When:R}</Rule>
<Rule name="AssemblyMetadata" key="Branch">{branch.FriendlyName}</Rule>
<Rule name="AssemblyMetadata" key="Date">{commitDate:F} {commitDate.Offset:hhmm}</Rule>
<Rule name="AssemblyMetadata" key="Branch">{branch.Name}</Rule>
<Rule name="AssemblyMetadata" key="Tags">{tags}</Rule>
<Rule name="AssemblyMetadata" key="Author">{author}</Rule>
<Rule name="AssemblyMetadata" key="Committer">{committer}</Rule>
<Rule name="AssemblyMetadata" key="Message">{commit.MessageShort}</Rule>
<Rule name="AssemblyMetadata" key="Subject">{commit.Subject}</Rule>
<Rule name="AssemblyMetadata" key="Body">{commit.Body}</Rule>
<Rule name="AssemblyMetadata" key="Build">{buildIdentifier}</Rule>
<Rule name="AssemblyMetadata" key="Generated">{generated:R}</Rule>
<Rule name="AssemblyMetadata" key="Generated">{generated:F}</Rule>
<Rule name="AssemblyMetadata" key="TargetFramework">{tfm}</Rule>

<!--
Both "ApplicationVersion" and "ApplicationDisplayVersion" are used for .NET MAUI versioning.
"ApplicationVersion" contains a integer value of seconds since epoch date (1970/1/1) from `committer.When`.
Expand Down
109 changes: 54 additions & 55 deletions CenterCLR.RelaxVersioner.Core/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////////////
//
// RelaxVersioner - Easy-usage, Git-based, auto-generate version informations toolset.
// RelaxVersioner - Git tag/branch based, full-automatic version information inserter.
// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud)
//
// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0
Expand All @@ -12,75 +12,74 @@
using System;
using System.IO;

namespace RelaxVersioner
namespace RelaxVersioner;

public enum LogImportance
{
public enum LogImportance
{
Low = 1,
Normal = 2,
High =3
}
Low = 1,
Normal = 2,
High =3
}

public abstract class Logger
{
protected readonly string Header;
public abstract class Logger
{
protected readonly string Header;

protected Logger(string header) =>
this.Header = header;
protected Logger(string header) =>
this.Header = header;

public abstract void Message(LogImportance importance, string message);
public abstract void Message(LogImportance importance, string message);

public virtual void Message(LogImportance importance, string format, params object?[] args) =>
this.Message(importance, $"{this.Header}: {string.Format(format, args)}");
public virtual void Message(LogImportance importance, Exception ex, string format, params object?[] args) =>
this.Message(importance, $"{this.Header}: {ex.GetType().Name}={ex.Message}, {string.Format(format, args)}");
public virtual void Message(LogImportance importance, string format, params object?[] args) =>
this.Message(importance, $"{this.Header}: {string.Format(format, args)}");
public virtual void Message(LogImportance importance, Exception ex, string format, params object?[] args) =>
this.Message(importance, $"{this.Header}: {ex.GetType().Name}={ex.Message}, {string.Format(format, args)}");

public abstract void Warning(string message);
public abstract void Warning(string message);

public virtual void Warning(string format, params object?[] args) =>
this.Warning($"{this.Header}: {string.Format(format, args)}");
public virtual void Warning(Exception ex, string format, params object?[] args) =>
this.Warning($"{this.Header}: {ex.GetType().Name}={ex.Message}, {string.Format(format, args)}");
public virtual void Warning(string format, params object?[] args) =>
this.Warning($"{this.Header}: {string.Format(format, args)}");
public virtual void Warning(Exception ex, string format, params object?[] args) =>
this.Warning($"{this.Header}: {ex.GetType().Name}={ex.Message}, {string.Format(format, args)}");

public abstract void Error(string message);
public abstract void Error(string message);

public virtual void Error(string format, params object?[] args) =>
this.Error($"{this.Header}: {string.Format(format, args)}");
public virtual void Error(Exception ex, string format, params object?[] args) =>
this.Error($"{this.Header}: {ex.GetType().Name}={ex.Message}, {string.Format(format, args)}");
public virtual void Error(string format, params object?[] args) =>
this.Error($"{this.Header}: {string.Format(format, args)}");
public virtual void Error(Exception ex, string format, params object?[] args) =>
this.Error($"{this.Header}: {ex.GetType().Name}={ex.Message}, {string.Format(format, args)}");

public static Logger Create(string header, LogImportance lowerImportance, TextWriter @out, TextWriter warning, TextWriter error) =>
new TextWriterLogger(header, lowerImportance, @out, warning, error);
}
public static Logger Create(string header, LogImportance lowerImportance, TextWriter @out, TextWriter warning, TextWriter error) =>
new TextWriterLogger(header, lowerImportance, @out, warning, error);
}

internal sealed class TextWriterLogger : Logger
{
private readonly LogImportance lowerImportance;
private readonly TextWriter @out;
private readonly TextWriter warning;
private readonly TextWriter error;
internal sealed class TextWriterLogger : Logger
{
private readonly LogImportance lowerImportance;
private readonly TextWriter @out;
private readonly TextWriter warning;
private readonly TextWriter error;

public TextWriterLogger(string header, LogImportance lowerImportance, TextWriter @out, TextWriter warning, TextWriter error) :
base(header)
{
this.lowerImportance = lowerImportance;
this.@out = @out;
this.warning = warning;
this.error = error;
}
public TextWriterLogger(string header, LogImportance lowerImportance, TextWriter @out, TextWriter warning, TextWriter error) :
base(header)
{
this.lowerImportance = lowerImportance;
this.@out = @out;
this.warning = warning;
this.error = error;
}

public override void Message(LogImportance importance, string message)
public override void Message(LogImportance importance, string message)
{
if (importance >= lowerImportance)
{
if (importance >= lowerImportance)
{
@out.WriteLine(message);
}
@out.WriteLine(message);
}
}

public override void Warning(string message) =>
warning.WriteLine(message);
public override void Warning(string message) =>
warning.WriteLine(message);

public override void Error(string message) =>
error.WriteLine(message);
}
public override void Error(string message) =>
error.WriteLine(message);
}
Loading

0 comments on commit 79a0959

Please sign in to comment.