Skip to content

Commit

Permalink
Merge branch 'feature/14' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jun 11, 2023
2 parents 70cea02 + ab12d10 commit c0d31ae
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 396 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
30 changes: 14 additions & 16 deletions CenterCLR.RelaxVersioner.Core/Analyzer.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 @@ -9,9 +9,12 @@

#nullable enable

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

using GitReader.Structures;

namespace RelaxVersioner;

Expand All @@ -32,17 +35,12 @@ public override string ToString() =>
$"StartDepth={this.StartDepth}, {this.Commit}";
}

public static Version LookupVersionLabel(
Branch targetBranch,
Dictionary<string, Tag[]> tagsDictionary)
public static async Task<Version> LookupVersionLabelAsync(
Branch targetBranch, CancellationToken ct)
{
var topCommit = targetBranch?.Commits?.FirstOrDefault();
if (topCommit == null)
{
return Version.Default;
}
var topCommit = await targetBranch.GetHeadCommitAsync(ct);

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

Expand All @@ -59,16 +57,16 @@ public static Version LookupVersionLabel(
while (true)
{
// Rejoined parent branch.
if (!reached.Add(currentCommit.Sha))
if (!reached.Add(currentCommit))
{
break;
}

// If found be applied tags at this commit:
if (tagsDictionary.TryGetValue(currentCommit.Sha, out var tags))
if (currentCommit.Tags.Count >= 1)
{
var filteredTags = tags.
Select(tag => Version.TryParse(tag.GetFriendlyName(), out var version) ? (Version?)version : null).
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();
Expand All @@ -81,7 +79,7 @@ public static Version LookupVersionLabel(
}

// Found parents.
if ((currentCommit.Parents?.ToArray() is { Length: >= 1 } parents))
if (await currentCommit.GetParentCommitsAsync(ct) is { Length: >= 1 } parents)
{
// Dive parent commit.
currentDepth++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NamingFormatter" Version="2.1.0" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0119" />
<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.14.0" PrivateAssets="all" />
</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
2 changes: 1 addition & 1 deletion 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 Down
Loading

0 comments on commit c0d31ae

Please sign in to comment.