Skip to content

Commit

Permalink
Merge branch 'master' into pr/399-add-path-filtering-support-to-versi…
Browse files Browse the repository at this point in the history
…on-json
  • Loading branch information
AArnott committed Dec 21, 2019
2 parents 9469c88 + 7ba0a2e commit 32d626e
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 61 deletions.
18 changes: 15 additions & 3 deletions azure-pipelines.yml
Expand Up @@ -18,6 +18,8 @@ resources:
image: andrewarnott/linux-buildagent
- container: bionic
image: microsoft/dotnet:2.1-sdk-bionic
- container: bionic-3.0
image: mcr.microsoft.com/dotnet/core/sdk:3.0-bionic
- container: disco
image: mcr.microsoft.com/dotnet/core/sdk:3.0-disco

Expand All @@ -37,7 +39,7 @@ jobs:
displayName: Install .NET Core SDK
inputs:
packageType: sdk
version: 2.1.500
version: 2.2.402
- script: dotnet --info
displayName: Show dotnet SDK info

Expand Down Expand Up @@ -67,6 +69,10 @@ jobs:
displayName: Build NuGet package and tests
workingDirectory: src

- script: dotnet publish -c $(BuildConfiguration) -o ..\nerdbank-gitversioning.npm\out\nbgv.cli\tools\netcoreapp2.1\any /bl:"$(Build.ArtifactStagingDirectory)/build_logs/nbgv_publish.binlog"
displayName: Build NuGet package and tests
workingDirectory: src\nbgv

- task: gulp@0
displayName: Build nerdbank-gitversioning NPM package
inputs:
Expand Down Expand Up @@ -151,6 +157,14 @@ jobs:
steps:
- template: azure-pipelines/xplattest-pipeline.yml

- job: Ubuntu_Bionic_3_0
dependsOn: Windows
pool:
vmImage: Ubuntu 16.04 # not a bug. we always use this pool, but use containers for the specific version
container: bionic-3.0
steps:
- template: azure-pipelines/xplattest-pipeline.yml

- job: Ubuntu_Disco
dependsOn: Windows
pool:
Expand All @@ -164,7 +178,5 @@ jobs:
dependsOn: Windows
pool:
vmImage: macOS 10.13
variables:
DOTNET_ROOT: /Users/vsts/.dotnet
steps:
- template: azure-pipelines/xplattest-pipeline.yml
2 changes: 2 additions & 0 deletions azure-pipelines/xplattest-pipeline.yml
Expand Up @@ -21,6 +21,8 @@ steps:
NBGV_NuGetPackageVersion=$([[ $PkgFileName =~ Nerdbank.GitVersioning\.(.*)\.nupkg ]] && echo "${BASH_REMATCH[1]}")
echo "<configuration><packageSources><add key='local' value='deployables' /></packageSources></configuration>" > nuget.config &&
dotnet new classlib -o lib &&
cd lib &&
echo '{"version":"42.42"}' > version.json &&
git init &&
git add version.json &&
Expand Down
2 changes: 1 addition & 1 deletion doc/nbgv-cli.md
Expand Up @@ -118,7 +118,7 @@ The behaviour of the `prepare-release` command can be customized in
| Property | Default value | Description |
|------------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| branchName | `v{version}` | Defines the format of release branch names. The value must include a `{version}` placeholder. |
| versionIncremnt | `minor` | Specifies which part of the version on the current branch is incremented when preparing a release. Allowed values are `major`, `minor` and `build`. |
| versionIncrement | `minor` | Specifies which part of the version on the current branch is incremented when preparing a release. Allowed values are `major`, `minor` and `build`. |
| firstUnstableTag | `alpha` | Specified the unstable tag to use for the main branch. |

## Learn more
Expand Down
2 changes: 1 addition & 1 deletion doc/versionJson.md
Expand Up @@ -51,7 +51,7 @@ The content of the version.json file is a JSON serialized object with these prop
"branchName" : "v{version}",
"versionIncrement" : "minor",
"firstUnstableTag" : "alpha"
}
},
"inherit": false // optional. Set to true in secondary version.json files used to tweak settings for subsets of projects.
}
```
Expand Down
2 changes: 1 addition & 1 deletion global.json
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.1.500"
"version": "2.2.402"
}
}
8 changes: 7 additions & 1 deletion readme.md
Expand Up @@ -111,7 +111,13 @@ Learn more about [public releases and the git commit ID suffix](doc/public_vs_st

### How do I translate from a version to a git commit and vice versa?

A pair of Powershell scripts are included in the Nerdbank.GitVersioning NuGet package
While Nerdbank.GitVersioning calculates the version and applies it to most builds automatically,
there can be occasions where you want to do so yourself or reverse the process to determine
the commit that produced a given version.

To do this use [the `nbgv` tool](doc/nbgv-cli.md) with the `get-version` or `get-commits` command.

Another (deprecated) option is to use a pair of Powershell scripts are included in the Nerdbank.GitVersioning NuGet package
that can help you to translate between the two representations.

tools\Get-CommitId.ps1
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Expand Up @@ -19,6 +19,6 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs
Expand Up @@ -80,7 +80,7 @@ private void Init()
}
}

private string CommitIdShort => this.Repo.Head.Commits.First().Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength);
private string CommitIdShort => this.Repo.Head.Tip.Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength);

protected override void Dispose(bool disposing)
{
Expand Down Expand Up @@ -183,8 +183,8 @@ public async Task GetBuildVersion_In_Git_But_Head_Lacks_VersionFile()
this.WriteVersionFile("3.4");
Assumes.True(repo.Index[VersionFile.JsonFileName] == null);
var buildResult = await this.BuildAsync();
Assert.Equal("3.4.0." + repo.Head.Commits.First().GetIdAsVersion().Revision, buildResult.BuildVersion);
Assert.Equal("3.4.0+" + repo.Head.Commits.First().Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion);
Assert.Equal("3.4.0." + repo.Head.Tip.GetIdAsVersion().Revision, buildResult.BuildVersion);
Assert.Equal("3.4.0+" + repo.Head.Tip.Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion);
}

[Fact]
Expand All @@ -208,8 +208,8 @@ public async Task GetBuildVersion_In_Git_No_VersionFile_At_All()
var repo = new Repository(this.RepoPath); // do not assign Repo property to avoid commits being generated later
repo.Commit("empty", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
var buildResult = await this.BuildAsync();
Assert.Equal("0.0.0." + repo.Head.Commits.First().GetIdAsVersion().Revision, buildResult.BuildVersion);
Assert.Equal("0.0.0+" + repo.Head.Commits.First().Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion);
Assert.Equal("0.0.0." + repo.Head.Tip.GetIdAsVersion().Revision, buildResult.BuildVersion);
Assert.Equal("0.0.0+" + repo.Head.Tip.Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion);
}

[Fact]
Expand Down Expand Up @@ -288,7 +288,7 @@ public async Task GetBuildVersion_StableRelease()
var buildResult = await this.BuildAsync();
this.AssertStandardProperties(VersionOptions.FromVersion(new Version(majorMinorVersion)), buildResult);

Version version = this.Repo.Head.Commits.First().GetIdAsVersion();
Version version = this.Repo.Head.Tip.GetIdAsVersion();
Assert.Equal($"{version.Major}.{version.Minor}.{buildResult.GitVersionHeight}", buildResult.NuGetPackageVersion);
}

Expand Down Expand Up @@ -1003,8 +1003,8 @@ private void AssertStandardProperties(VersionOptions versionOptions, BuildResult
Assert.Equal($"{idAsVersion.Major}.{idAsVersion.Minor}.{idAsVersion.Build}", buildResult.BuildVersion3Components);
Assert.Equal(idAsVersion.Build.ToString(), buildResult.BuildVersionNumberComponent);
Assert.Equal($"{idAsVersion.Major}.{idAsVersion.Minor}.{idAsVersion.Build}", buildResult.BuildVersionSimple);
Assert.Equal(this.Repo.Head.Commits.First().Id.Sha, buildResult.GitCommitId);
Assert.Equal(this.Repo.Head.Commits.First().Author.When.UtcTicks.ToString(CultureInfo.InvariantCulture), buildResult.GitCommitDateTicks);
Assert.Equal(this.Repo.Head.Tip.Id.Sha, buildResult.GitCommitId);
Assert.Equal(this.Repo.Head.Tip.Author.When.UtcTicks.ToString(CultureInfo.InvariantCulture), buildResult.GitCommitDateTicks);
Assert.Equal(commitIdShort, buildResult.GitCommitIdShort);
Assert.Equal(versionHeight.ToString(), buildResult.GitVersionHeight);
Assert.Equal($"{version.Major}.{version.Minor}", buildResult.MajorMinorVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning.Tests/VersionFileTests.cs
Expand Up @@ -128,7 +128,7 @@ public void SetVersion_WritesSimplestFile(string version, string assemblyVersion
VersionHeightOffset = versionHeightOffset,
Inherit = inherit,
};
string pathWritten = VersionFile.SetVersion(this.RepoPath, versionOptions);
string pathWritten = VersionFile.SetVersion(this.RepoPath, versionOptions, includeSchemaProperty: false);
string actualFileContent = File.ReadAllText(pathWritten);
this.Logger.WriteLine(actualFileContent);

Expand Down
8 changes: 4 additions & 4 deletions src/NerdBank.GitVersioning/GitExtensions.cs
Expand Up @@ -108,7 +108,7 @@ public static int GetVersionHeight(this Repository repo, string repoRelativeProj
/// <returns>The height of the branch till the version is changed.</returns>
public static int GetVersionHeight(this Branch branch, string repoRelativeProjectDirectory = null)
{
return GetVersionHeight(branch.Commits.First(), repoRelativeProjectDirectory);
return GetVersionHeight(branch.Tip ?? throw new InvalidOperationException("No commit exists."), repoRelativeProjectDirectory);
}

/// <summary>
Expand Down Expand Up @@ -177,7 +177,7 @@ public static int GetHeight(this Branch branch, Func<Commit, bool> continueStepp
/// <returns>The height of the branch.</returns>
public static int GetHeight(this Branch branch, string repoRelativeProjectDirectory, Func<Commit, bool> continueStepping = null)
{
return GetHeight(branch.Commits.First(), repoRelativeProjectDirectory, continueStepping);
return GetHeight(branch.Tip ?? throw new InvalidOperationException("No commit exists."), repoRelativeProjectDirectory, continueStepping);
}

/// <summary>
Expand Down Expand Up @@ -285,7 +285,7 @@ public static Version GetIdAsVersion(this Repository repo, string repoRelativePr
{
Requires.NotNull(repo, nameof(repo));

var headCommit = repo.Head.Commits.FirstOrDefault();
var headCommit = repo.Head.Tip;
VersionOptions workingCopyVersionOptions, committedVersionOptions;
if (IsVersionFileChangedInWorkingCopy(repo, repoRelativeProjectDirectory, out committedVersionOptions, out workingCopyVersionOptions))
{
Expand Down Expand Up @@ -889,7 +889,7 @@ internal static Version GetIdAsVersionHelper(this Commit commit, VersionOptions
private static bool IsVersionFileChangedInWorkingCopy(Repository repo, string repoRelativeProjectDirectory, out VersionOptions committedVersion, out VersionOptions workingCopyVersion)
{
Requires.NotNull(repo, nameof(repo));
Commit headCommit = repo.Head.Commits.FirstOrDefault();
Commit headCommit = repo.Head.Tip;
committedVersion = VersionFile.GetVersion(headCommit, repoRelativeProjectDirectory);

if (!repo.Info.IsBare)
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetMDDocs" Version="0.111.0" PrivateAssets="all" Condition=" '$(GenerateMarkdownApiDocs)' == 'true' " />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0029" PrivateAssets="none" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0034" PrivateAssets="none" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="System.Diagnostics.Tools" Version="4.3.0" Condition=" '$(TargetFramework)' == 'netcoreapp2.0' " />
Expand Down
7 changes: 4 additions & 3 deletions src/NerdBank.GitVersioning/VersionFile.cs
Expand Up @@ -128,7 +128,7 @@ public static VersionOptions GetVersion(LibGit2Sharp.Repository repo, string rep
return workingCopyVersion;
}

return GetVersion(repo.Head.Commits.FirstOrDefault(), repoRelativeProjectDirectory);
return GetVersion(repo.Head.Tip, repoRelativeProjectDirectory);
}

/// <summary>
Expand Down Expand Up @@ -226,6 +226,7 @@ public static bool IsVersionDefined(string projectDirectory)

/// <summary>
/// Writes the version.json file to a directory within a repo with the specified version information.
/// The $schema property is included.
/// </summary>
/// <param name="projectDirectory">
/// The path to the directory in which to write the version.json file.
Expand All @@ -234,7 +235,7 @@ public static bool IsVersionDefined(string projectDirectory)
/// </param>
/// <param name="version">The version information to write to the file.</param>
/// <returns>The path to the file written.</returns>
public static string SetVersion(string projectDirectory, VersionOptions version) => SetVersion(projectDirectory, version, includeSchemaProperty: false);
public static string SetVersion(string projectDirectory, VersionOptions version) => SetVersion(projectDirectory, version, includeSchemaProperty: true);

/// <summary>
/// Writes the version.json file to a directory within a repo with the specified version information.
Expand Down Expand Up @@ -291,7 +292,7 @@ public static string SetVersion(string projectDirectory, VersionOptions version,
/// <returns>The path to the file written.</returns>
public static string SetVersion(string projectDirectory, Version version, string unstableTag = null)
{
return SetVersion(projectDirectory, VersionOptions.FromVersion(version, unstableTag));
return SetVersion(projectDirectory, VersionOptions.FromVersion(version, unstableTag), includeSchemaProperty: false);
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Nerdbank.GitVersioning.Tasks/GitLoaderContext.cs
Expand Up @@ -15,6 +15,14 @@ internal class GitLoaderContext : AssemblyLoadContext
{
public static readonly GitLoaderContext Instance = new GitLoaderContext();

// When invoked as a MSBuild task, the native libraries will be at
// ../runtimes. When invoked from the nbgv CLI, the libraries
// will be at ./runtimes.
// This property allows code which consumes GitLoaderContext to
// differentiate between these different locations.
// In the case of the nbgv CLI, the value is set in Program.Main()
public static string RuntimePath = "../runtimes";

protected override Assembly Load(AssemblyName assemblyName)
{
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
Expand Down Expand Up @@ -53,7 +61,7 @@ protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
internal static string GetNativeLibraryDirectory()
{
var dir = Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location);
return Path.Combine(dir, "..", "runtimes", RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
return Path.Combine(dir, RuntimePath, RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
}

private static string GetNativeLibraryExtension()
Expand Down
24 changes: 23 additions & 1 deletion src/Nerdbank.GitVersioning.Tasks/RuntimeIdMap.cs
Expand Up @@ -166,6 +166,7 @@ internal static void ParseRuntimeId(string runtimeId, out string osName, out str
"centos.7-x64",
"debian-x64",
"debian.8-x64",
"debian.9-arm64",
"debian.9-x64",
"fedora-x64",
"fedora.23-x64",
Expand Down Expand Up @@ -237,12 +238,22 @@ internal static void ParseRuntimeId(string runtimeId, out string osName, out str
"ubuntu.14.10-x64",
"ubuntu.15.04-x64",
"ubuntu.15.10-x64",
"ubuntu.16.04-arm64",
"ubuntu.16.04-x64",
"ubuntu.16.10-arm64",
"ubuntu.16.10-x64",
"ubuntu.17.04-arm64",
"ubuntu.17.04-x64",
"ubuntu.17.10-arm64",
"ubuntu.17.10-x64",
"ubuntu.18.04-arm64",
"ubuntu.18.04-x64",
"ubuntu.18.10-arm64",
"ubuntu.18.10-x64",
"ubuntu.19.04-arm64",
"ubuntu.19.04-x64",
"ubuntu.19.10-arm64",
"ubuntu.19.10-x64",
"win-x64",
"win-x64-aot",
"win-x86",
Expand Down Expand Up @@ -296,6 +307,7 @@ internal static void ParseRuntimeId(string runtimeId, out string osName, out str
"linux-x64",
"linux-x64",
"linux-x64",
"debian.9-arm64",
"ubuntu.18.04-x64",
"rhel-x64",
"rhel-x64",
Expand Down Expand Up @@ -347,12 +359,22 @@ internal static void ParseRuntimeId(string runtimeId, out string osName, out str
"linux-x64",
"linux-x64",
"linux-x64",
"ubuntu.16.04-arm64",
"linux-x64",
"ubuntu.16.10-arm64",
"linux-x64",
"ubuntu.16.04-arm64",
"linux-x64",
"ubuntu.16.04-arm64",
"linux-x64",
"debian-arm64",
"ubuntu.18.04-x64",
"debian-arm64",
"ubuntu.18.04-x64",
"debian-arm64",
"ubuntu.18.04-x64",
"debian-arm64",
"ubuntu.18.04-x64",
"linux-x64",
"win-x64",
"win-x64",
"win-x86",
Expand Down

0 comments on commit 32d626e

Please sign in to comment.