Skip to content

Commit

Permalink
Merge v3.4 to master (#645)
Browse files Browse the repository at this point in the history
* Switch from PInvoke nuget dependency to CsWin32

Fixes #615

* Update CsWin32 to fix `dotnet build`

* Remove dotnet/pinvoke from 3rd party licenses file

* include 5E and DA values in zlib header check

* ditch linq for exception

* Add new NuGet signing certificate

See https://devblogs.microsoft.com/nuget/the-nuget-org-repository-signing-certificate-will-be-updated-as-soon-as-march-15th-2021/ for more details

* Bump libgit2sharp to 0.27.0-preview-0102

* Run 32-bit tests

* GitPack: Don't use MemoryMappedFiles in 32-bit processes

* Make sure Streams are disposed of.

* Fix bugs with > 2 GB pack files

* Apply suggestions from code review

Co-authored-by: Andrew Arnott <andrewarnott@gmail.com>

* Apply `is null` pattern and analyzer

Co-authored-by: rhodosaur <hai@rsaur.me>
Co-authored-by: Frederik Carlier <frederik.carlier@quamotion.mobi>
Co-authored-by: Filip Navara <navara@emclient.com>
  • Loading branch information
4 people committed Aug 28, 2021
2 parents 5789043 + 813cbf1 commit aa11c77
Show file tree
Hide file tree
Showing 44 changed files with 215 additions and 152 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Expand Up @@ -79,3 +79,9 @@ csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true

# CSIsNull001: Use `is null` for null checks
dotnet_diagnostic.CSIsNull001.severity = warning

# CSIsNull002: Use `is object` for non-null checks
dotnet_diagnostic.CSIsNull002.severity = warning
25 changes: 0 additions & 25 deletions 3rdPartyNotices.txt
Expand Up @@ -127,31 +127,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

dotnet/PInvoke (https://github.com/dotnet/pinvoke)
==============

MIT License

Copyright (c) .NET Foundation and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Cake Contrib (https://github.com/cake-contrib/graphics)
============

Expand Down
42 changes: 32 additions & 10 deletions azure-pipelines.yml
Expand Up @@ -43,6 +43,7 @@ stages:
windows:
imageName: 'windows-2019'
testModifier:
dotnet32: "\"C:\\Program Files (x86)\\dotnet\\dotnet.exe\""
variables:
- ${{ if eq(variables['System.TeamFoundationCollectionUri'], 'https://dev.azure.com/andrewarnott/') }}:
- group: dotnetfoundation code signing
Expand All @@ -58,17 +59,24 @@ stages:
displayName: Configure git commit author for testing
- task: UseDotNet@2
displayName: Install .NET Core SDK 5.0.202
displayName: Install .NET Core 5.0.202 SDK
inputs:
packageType: sdk
version: 5.0.202

- task: UseDotNet@2
displayName: Install .NET Core 3.1
displayName: Install .NET Core 3.1 runtime
inputs:
packageType: runtime
version: 3.1.x

- pwsh: |
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
& .\dotnet-install.ps1 -Architecture x86 -Version 5.0.202 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose
& .\dotnet-install.ps1 -Architecture x86 -Channel 3.1 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose
displayName: Install 32-bit .NET Core SDK 5.0.202, 3.1
condition: ne(variables['dotnet32'], '')
- script: dotnet --info
displayName: Show dotnet SDK info

Expand Down Expand Up @@ -121,8 +129,22 @@ stages:
--collect:"XPlat Code Coverage"
--
RunConfiguration.DisableAppDomain=true
displayName: Run tests
displayName: Run x64 tests
workingDirectory: src
- script: >
$(dotnet32) test NerdBank.GitVersioning.Tests
--no-build $(testModifier)
-c $(BuildConfiguration)
--filter "TestCategory!=FailsOnAzurePipelines"
--logger "trx;LogFileName=$(Build.ArtifactStagingDirectory)/TestLogs/TestResults.trx"
--results-directory $(Build.ArtifactStagingDirectory)/CodeCoverage/
--collect:"XPlat Code Coverage"
--
RunConfiguration.DisableAppDomain=true
displayName: Run x86 tests
workingDirectory: src
condition: ne(variables['dotnet32'], '')
- task: PublishCodeCoverageResults@1
displayName: Publish code coverage results
Expand Down Expand Up @@ -296,17 +318,17 @@ stages:
vmImage: $(imageName)
steps:
- task: UseDotNet@2
displayName: Install .NET Core SDK 2.1.811
displayName: Install .NET Core 2.1 runtime
inputs:
packageType: sdk
version: 2.1.811
packageType: runtime
version: 2.1.x
- task: UseDotNet@2
displayName: Install .NET Core SDK 3.1.100
displayName: Install .NET Core 3.1 runtime
inputs:
packageType: sdk
version: 3.1.100
packageType: runtime
version: 3.1.x
- task: UseDotNet@2
displayName: Install .NET Core SDK 5.0.202
displayName: Install .NET Core 5.0.202 SDK
inputs:
packageType: sdk
version: 5.0.202
Expand Down
6 changes: 5 additions & 1 deletion src/Directory.Build.props
Expand Up @@ -24,9 +24,13 @@
<LibGit2SharpNativeVersion>2.0.312</LibGit2SharpNativeVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="CSharpIsNullAnalyzer" Version="0.1.288-beta">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\3rdPartyNotices.txt" Pack="true" PackagePath="" />
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs
Expand Up @@ -219,7 +219,7 @@ public async Task GetBuildVersion_In_Git_But_Head_Lacks_VersionFile()
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 });
this.WriteVersionFile("3.4");
Assumes.True(repo.Index[VersionFile.JsonFileName] == null);
Assumes.True(repo.Index[VersionFile.JsonFileName] is null);
var buildResult = await this.BuildAsync();
Assert.Equal("3.4.0." + this.GetVersion().Revision, buildResult.BuildVersion);
Assert.Equal("3.4.0+" + repo.Head.Tip.Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion);
Expand Down
Expand Up @@ -89,7 +89,7 @@ public void ReadStreamTest()

DeltaInstruction? current;

while ((current = DeltaStreamReader.Read(stream)) != null)
while ((current = DeltaStreamReader.Read(stream)) is not null)
{
instructions.Add(current.Value);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public void ReadStreamTest_Memory()

DeltaInstruction? current;

while ((current = DeltaStreamReader.Read(ref memory)) != null)
while ((current = DeltaStreamReader.Read(ref memory)) is not null)
{
instructions.Add(current.Value);
}
Expand Down
42 changes: 34 additions & 8 deletions src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs
Expand Up @@ -63,7 +63,15 @@ public void GetPackedObject()
// This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file.
var zlibStream = Assert.IsType<ZLibStream>(commitStream);
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);

if (IntPtr.Size > 4)
{
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
}
else
{
var pooledStream = Assert.IsType<FileStream>(deflateStream.BaseStream);
}

Assert.Equal(222, commitStream.Length);
Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
Expand All @@ -85,7 +93,15 @@ public void GetDeltafiedObject()
var deltaStream = Assert.IsType<GitPackDeltafiedStream>(commitStream);
var zlibStream = Assert.IsType<ZLibStream>(deltaStream.BaseStream);
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);

if (IntPtr.Size > 4)
{
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
}
else
{
var directAccessStream = Assert.IsType<FileStream>(deflateStream.BaseStream);
}

Assert.Equal(137, commitStream.Length);
Assert.Equal("lZu/7nGb0n1UuO9SlPluFnSvj4o=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
Expand Down Expand Up @@ -120,14 +136,24 @@ public void TryGetObjectTest()
using (SHA1 sha = SHA1.Create())
{
Assert.True(gitPack.TryGetObject(GitObjectId.Parse("f5b401f40ad83f13030e946c9ea22cb54cb853cd"), "commit", out Stream commitStream));
using (commitStream)
{
// This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file.
var zlibStream = Assert.IsType<ZLibStream>(commitStream);
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);

// This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file.
var zlibStream = Assert.IsType<ZLibStream>(commitStream);
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
if (IntPtr.Size > 4)
{
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
}
else
{
var directAccessStream = Assert.IsType<FileStream>(deflateStream.BaseStream);
}

Assert.Equal(222, commitStream.Length);
Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
Assert.Equal(222, commitStream.Length);
Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs
Expand Up @@ -320,7 +320,7 @@ public void PrepeareRelease_ReleaseBranchWithVersionDecrement(string initialVers

// prepare release
var releaseManager = new ReleaseManager();
releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion)), parameterVersionIncrement);
releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion is null ? null : Version.Parse(nextVersion)), parameterVersionIncrement);

// check if a branch was created
Assert.Contains(this.LibGit2Repository.Branches, branch => branch.FriendlyName == expectedBranchName);
Expand Down Expand Up @@ -394,7 +394,7 @@ public void PrepareRelease_MasterWithVersionDecrement(string initialVersion, str
// running PrepareRelease should result in an error
// because we're setting the version on master to a lower version
this.AssertError(
() => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion))),
() => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion is null ? null : Version.Parse(nextVersion))),
ReleasePreparationError.VersionDecrement);
}

Expand All @@ -412,7 +412,7 @@ public void PrepareRelease_MasterWithoutVersionIncrement(string initialVersion,
// running PrepareRelease should result in an error
// because we're trying to set master to the version it already has
this.AssertError(
() => new ReleaseManager().PrepareRelease(this.RepoPath, null, (nextVersion == null ? null : Version.Parse(nextVersion))),
() => new ReleaseManager().PrepareRelease(this.RepoPath, null, (nextVersion is null ? null : Version.Parse(nextVersion))),
ReleasePreparationError.NoVersionIncrement);
}

Expand Down
6 changes: 3 additions & 3 deletions src/NerdBank.GitVersioning.Tests/RepoTestBase.cs
Expand Up @@ -143,7 +143,7 @@ protected void AddCommits(int count = 1)

protected Commit? WriteVersionTxtFile(string version = "1.2", string prerelease = "", string? relativeDirectory = null)
{
if (relativeDirectory == null)
if (relativeDirectory is null)
{
relativeDirectory = string.Empty;
}
Expand All @@ -163,7 +163,7 @@ protected void AddCommits(int count = 1)
{
Requires.NotNull(versionData, nameof(versionData));

if (relativeDirectory == null)
if (relativeDirectory is null)
{
relativeDirectory = string.Empty;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ protected void AddCommits(int count = 1)
if (Path.GetExtension(relativeFilePath) == ".json")
{
string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt";
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.LibGit2Repository.Index[txtFilePath] != null)
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.LibGit2Repository.Index[txtFilePath] is not null)
{
this.LibGit2Repository.Index.Remove(txtFilePath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning.Tests/TestUtilities.cs
Expand Up @@ -54,7 +54,7 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract

using (var stream = GetEmbeddedResource(resourcePath))
{
Requires.Argument(stream != null, nameof(resourcePath), "Resource not found.");
Requires.Argument(stream is not null, nameof(resourcePath), "Resource not found.");
using (var extractedFile = File.OpenWrite(extractedFilePath))
{
stream.CopyTo(extractedFile);
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning.Tests/VersionFileTests.cs
Expand Up @@ -140,7 +140,7 @@ public void SetVersion_WritesSimplestFile(string version, string assemblyVersion
var versionOptions = new VersionOptions
{
Version = SemanticVersion.Parse(version),
AssemblyVersion = assemblyVersion != null || precision != null ? new VersionOptions.AssemblyVersionOptions(assemblyVersion != null ? new Version(assemblyVersion) : null, precision) : null,
AssemblyVersion = assemblyVersion is not null || precision is not null ? new VersionOptions.AssemblyVersionOptions(assemblyVersion is not null ? new Version(assemblyVersion) : null, precision) : null,
VersionHeightOffset = versionHeightOffset,
Inherit = inherit,
};
Expand Down
Expand Up @@ -51,7 +51,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var data = value as VersionOptions.AssemblyVersionOptions;
if (data != null)
if (data is not null)
{
if (data.PrecisionOrDefault == VersionOptions.DefaultVersionPrecision && !this.includeDefaults)
{
Expand Down
4 changes: 2 additions & 2 deletions src/NerdBank.GitVersioning/CloudBuildServices/GitLab.cs
Expand Up @@ -14,13 +14,13 @@
internal class GitLab : ICloudBuild
{
public string BuildingBranch =>
Environment.GetEnvironmentVariable("CI_COMMIT_TAG") == null ?
Environment.GetEnvironmentVariable("CI_COMMIT_TAG") is null ?
$"refs/heads/{Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME")}" : null;

public string BuildingRef => this.BuildingBranch ?? this.BuildingTag;

public string BuildingTag =>
Environment.GetEnvironmentVariable("CI_COMMIT_TAG") != null ?
Environment.GetEnvironmentVariable("CI_COMMIT_TAG") is not null ?
$"refs/tags/{Environment.GetEnvironmentVariable("CI_COMMIT_TAG")}" : null;

public string GitCommitId => Environment.GetEnvironmentVariable("CI_COMMIT_SHA");
Expand Down
Expand Up @@ -19,7 +19,7 @@ internal class SpaceAutomation : ICloudBuild

public string GitCommitId => Environment.GetEnvironmentVariable("JB_SPACE_GIT_REVISION");

public bool IsApplicable => this.GitCommitId != null;
public bool IsApplicable => this.GitCommitId is not null;

public bool IsPullRequest => false;

Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/CloudBuildServices/TeamCity.cs
Expand Up @@ -19,7 +19,7 @@ internal class TeamCity : ICloudBuild

public string GitCommitId => Environment.GetEnvironmentVariable("BUILD_VCS_NUMBER");

public bool IsApplicable => this.GitCommitId != null;
public bool IsApplicable => this.GitCommitId is not null;

public bool IsPullRequest => false;

Expand Down
4 changes: 2 additions & 2 deletions src/NerdBank.GitVersioning/FilterPathJsonConverter.cs
Expand Up @@ -22,7 +22,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
throw new NotSupportedException();
}

if (this.repoRelativeBaseDirectory == null)
if (this.repoRelativeBaseDirectory is null)
{
throw new ArgumentNullException(nameof(this.repoRelativeBaseDirectory), $"Base directory must not be null to be able to deserialize filter paths. Ensure that one was passed to {nameof(VersionOptions.GetJsonSettings)}, and that the version.json file is being written to a Git repository.");
}
Expand All @@ -37,7 +37,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
throw new NotSupportedException();
}

if (this.repoRelativeBaseDirectory == null)
if (this.repoRelativeBaseDirectory is null)
{
throw new ArgumentNullException(nameof(this.repoRelativeBaseDirectory), $"Base directory must not be null to be able to serialize filter paths. Ensure that one was passed to {nameof(VersionOptions.GetJsonSettings)}, and that the version.json file is being written to a Git repository.");
}
Expand Down

0 comments on commit aa11c77

Please sign in to comment.