Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Switch to MinVer for versioning #2028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ jobs:
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- name: Run ${{ matrix.tfm }} tests
run: |
git_command="git config --global --add safe.directory /app"
test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=${{ matrix.tfm }} --logger "GitHubActions" -p:ExtraDefine=LEAKS_IDENTIFYING"
docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$test_command"
docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$git_command && $test_command"

10 changes: 5 additions & 5 deletions LibGit2Sharp.Tests/GlobalSettingsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ public void CanGetMinimumCompiledInFeatures()
public void CanRetrieveValidVersionString()
{
// Version string format is:
// Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features)
// Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)
// Example output:
// "0.25.0-preview.52+871d13a67f.libgit2-15e1193 (x86 - Threads, Https)"
// "0.27.0-preview.0.1896+libgit2-c058aa8.c1ac3ed74487da5fac24cf1e48dc8ea71e917b75 (x64 - Threads, Https, NSec)"

string versionInfo = GlobalSettings.Version.ToString();

// The GlobalSettings.Version returned string should contain :
// version: '0.25.0[-previewTag]' LibGit2Sharp version number.
// git2SharpHash: '871d13a67f' LibGit2Sharp hash.
// git2SharpHash: 'c1ac3ed74487da5fac24cf1e48dc8ea71e917b75' LibGit2Sharp hash.
// arch: 'x86' or 'x64' libgit2 target.
// git2Features: 'Threads, Ssh' libgit2 features compiled with.
string regex = @"^(?<version>\d+\.\d+\.\d+(-[\w\-\.]+)?\+((?<git2SharpHash>[a-f0-9]{10})\.)?libgit2-[a-f0-9]{7}) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
string regex = @"^(?<version>\d+\.\d+\.\d+(-[\w\-\.]+)?)\+libgit2-[a-f0-9]{7}\.((?<git2SharpHash>[a-f0-9]{40}))? \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";

Assert.NotNull(versionInfo);

Match regexResult = Regex.Match(versionInfo, regex);

Assert.True(regexResult.Success, "The following version string format is enforced:" +
"Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features). " +
"Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features). " +
"But found \"" + versionInfo + "\" instead.");
}

Expand Down
5 changes: 2 additions & 3 deletions LibGit2Sharp.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.202
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibGit2Sharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}"
EndProject
Expand All @@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
Targets\GenerateNativeDllName.targets = Targets\GenerateNativeDllName.targets
nuget.config = nuget.config
version.json = version.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeLibraryLoadTestApp.x86", "NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj", "{86453D2C-4953-4DF4-B12A-ADE579608BAA}"
Expand Down
8 changes: 5 additions & 3 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<PackageIcon>square-logo.png</PackageIcon>
<PackageLicenseFile>App_Readme/LICENSE.md</PackageLicenseFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerBuildMetadata Condition="'$(libgit2_hash)' != ''">libgit2-$(libgit2_hash.Substring(0,7))</MinVerBuildMetadata>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,15 +34,15 @@
<ItemGroup>
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="[2.0.319]" PrivateAssets="none" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220" PrivateAssets="all" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="all" />
</ItemGroup>

<Import Project="..\Targets\CodeGenerator.targets" />
<Import Project="..\Targets\GenerateNativeDllName.targets" />

<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<PackageReleaseNotes>https://github.com/libgit2/libgit2sharp/blob/$(GitCommitIdShort)/CHANGES.md#libgit2sharp-changes</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/libgit2/libgit2sharp/blob/$(SourceRevisionId)/CHANGES.md</PackageReleaseNotes>
</PropertyGroup>
</Target>

Expand Down
12 changes: 10 additions & 2 deletions LibGit2Sharp/Version.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Reflection;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
Expand All @@ -22,7 +23,14 @@ internal static Version Build()
/// <summary>
/// Returns version of the LibGit2Sharp library.
/// </summary>
public virtual string InformationalVersion => ThisAssembly.AssemblyInformationalVersion;
public virtual string InformationalVersion
{
get
{
var attribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return attribute.InformationalVersion;
}
}

/// <summary>
/// Returns all the optional features that were compiled into
Expand Down Expand Up @@ -55,7 +63,7 @@ private string RetrieveAbbrevShaFrom(string sha)
/// </summary>
/// <para>
/// The format of the version number is as follows:
/// <para>Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features)</para>
/// <para>Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)</para>
/// </para>
/// <returns></returns>
public override string ToString()
Expand Down
37 changes: 13 additions & 24 deletions Targets/CodeGenerator.targets
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<Project>

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<Target Name="DefineProperties">
<PropertyGroup>
<SourceRevisionIdPath>$(IntermediateOutputPath)SourceRevisionId.txt</SourceRevisionIdPath>
<UniqueIdentifierPath>$(IntermediateOutputPath)UniqueIdentifier.g.cs</UniqueIdentifierPath>
<AssemblyCommitIdsPath>$(IntermediateOutputPath)AssemblyCommitIds.g.cs</AssemblyCommitIdsPath>
</PropertyGroup>
</Target>

<Target Name="WriteSourceRevisionIdToFile" AfterTargets="AddSourceRevisionToInformationalVersion" DependsOnTargets="DefineProperties">
<WriteLinesToFile File="$(SourceRevisionIdPath)" Lines="$(SourceRevisionId)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<ItemGroup>
<FileWrites Include="$(SourceRevisionIdPath)" />
</ItemGroup>
</Target>

<Target Name="GenerateUniqueIdentifierCs" Inputs="$(VersionSourceFile)" Outputs="$(UniqueIdentifierPath)" BeforeTargets="CoreCompile" AfterTargets="GenerateAssemblyVersionInfo" DependsOnTargets="DefineProperties">

<Target Name="GenerateUniqueIdentifierCs" Inputs="$(SourceRevisionIdPath)" Outputs="$(UniqueIdentifierPath)" BeforeTargets="CoreCompile" AfterTargets="WriteSourceRevisionIdToFile" DependsOnTargets="DefineProperties">
<PropertyGroup>
<UniqueIdentifier>$([System.Guid]::NewGuid())</UniqueIdentifier>
<UniqueIdentifier Condition="'$(GitCommitId)' != ''">$(GitCommitId)</UniqueIdentifier>
<UniqueIdentifier>$(SourceRevisionId)</UniqueIdentifier>
<UniqueIdentifier Condition="'$(UniqueIdentifier)' == ''">$([System.Guid]::NewGuid())</UniqueIdentifier>
<UniqueIdSourceLines>
namespace LibGit2Sharp.Core
{
Expand All @@ -34,24 +36,12 @@
<Compile Include="$(UniqueIdentifierPath)" />
<FileWrites Include="$(UniqueIdentifierPath)" />
</ItemGroup>

</Target>


<Target Name="AddNativeDllCommitShaToBuildMetadata" BeforeTargets="GetBuildVersion">

<ItemGroup>
<BuildMetadata Include="libgit2-$(libgit2_hash.Substring(0,7))" />
</ItemGroup>

</Target>


<Target Name="GenerateAssemblyCommitIdsCs" Inputs="$(libgit2_propsfile);$(VersionSourceFile)" Outputs="$(AssemblyCommitIdsPath)" BeforeTargets="CoreCompile" AfterTargets="GenerateAssemblyVersionInfo" DependsOnTargets="DefineProperties">

<Target Name="GenerateAssemblyCommitIdsCs" Inputs="$(libgit2_propsfile);$(SourceRevisionIdPath)" Outputs="$(AssemblyCommitIdsPath)" BeforeTargets="CoreCompile" AfterTargets="WriteSourceRevisionIdToFile" DependsOnTargets="DefineProperties">
<PropertyGroup>
<LibGit2SharpCommitSha>unknown</LibGit2SharpCommitSha>
<LibGit2SharpCommitSha Condition="'$(GitCommitId)' != ''">$(GitCommitId)</LibGit2SharpCommitSha>
<LibGit2SharpCommitSha>$(SourceRevisionId)</LibGit2SharpCommitSha>
<LibGit2SharpCommitSha Condition="'$(LibGit2SharpCommitSha)' == ''">unknown</LibGit2SharpCommitSha>
<AssemblyCommitIdsSourceLines>
namespace LibGit2Sharp
{
Expand All @@ -70,7 +60,6 @@
<Compile Include="$(AssemblyCommitIdsPath)" />
<FileWrites Include="$(AssemblyCommitIdsPath)" />
</ItemGroup>

</Target>

</Project>
5 changes: 1 addition & 4 deletions Targets/GenerateNativeDllName.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<Project>

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<Target Name="DefineNativeDllName">
<PropertyGroup>
<NativeDllNamePath>$(IntermediateOutputPath)NativeDllName.g.cs</NativeDllNamePath>
Expand All @@ -30,4 +26,5 @@
<FileWrites Include="$(NativeDllNamePath)" />
</ItemGroup>
</Target>

</Project>
13 changes: 0 additions & 13 deletions version.json

This file was deleted.