Skip to content

Commit

Permalink
Merge pull request #771 from dotnet/libtemplateUpdate
Browse files Browse the repository at this point in the history
Merge latest Library.Template
  • Loading branch information
AArnott authored Oct 11, 2024
2 parents 886a3b3 + f206a2b commit 2078689
Show file tree
Hide file tree
Showing 22 changed files with 459 additions and 201 deletions.
8 changes: 4 additions & 4 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"isRoot": true,
"tools": {
"powershell": {
"version": "7.4.2",
"version": "7.4.5",
"commands": [
"pwsh"
]
},
"dotnet-coverage": {
"version": "17.11.0",
"version": "17.12.5",
"commands": [
"dotnet-coverage"
]
},
"nbgv": {
"version": "3.6.133",
"version": "3.6.143",
"commands": [
"nbgv"
]
}
}
}
}
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Refer to https://hub.docker.com/_/microsoft-dotnet-sdk for available versions
FROM mcr.microsoft.com/dotnet/sdk:8.0.201-jammy
FROM mcr.microsoft.com/dotnet/sdk:8.0.402-jammy

# Installing mono makes `dotnet test` work without errors even for net472.
# But installing it takes a long time, so it's excluded by default.
Expand Down
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ indent_size = 2
# Xml config files
[*.{ruleset,config,nuspec,resx,vsixmanifest,vsct,runsettings}]
indent_size = 2
indent_style = space

[*.{js,ts,json}]
indent_style = tab
Expand Down Expand Up @@ -188,5 +189,8 @@ dotnet_diagnostic.DOC202.severity = warning
# CA1062: Validate arguments of public methods
dotnet_diagnostic.CA1062.severity = warning

# CA2016: Forward the CancellationToken parameter
dotnet_diagnostic.CA2016.severity = warning

[*.sln]
indent_style = tab
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ bld/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# Jetbrains Rider cache directory
.idea/

# Visual Studio 2017 auto generated files
Generated\ Files/

Expand Down Expand Up @@ -352,3 +355,6 @@ MigrationBackup/

# mac-created file to track user view preferences for a directory
.DS_Store

# Analysis results
*.sarif
20 changes: 0 additions & 20 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<BaseIntermediateOutputPath>$(RepoRootPath)obj\$([MSBuild]::MakeRelative($(RepoRootPath), $(MSBuildProjectDirectory)))\</BaseIntermediateOutputPath>
<BaseOutputPath Condition=" '$(BaseOutputPath)' == '' ">$(RepoRootPath)bin\$(MSBuildProjectName)\</BaseOutputPath>
<PackageOutputPath>$(RepoRootPath)bin\Packages\$(Configuration)\NuGet\</PackageOutputPath>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AnalysisLevel>latest</AnalysisLevel>
Expand Down Expand Up @@ -64,23 +63,4 @@
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)NOTICE" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<PropertyGroup Condition="'$(IsWpfTempProject)' == ''">
<IsWpfTempProject>false</IsWpfTempProject>
<IsWpfTempProject Condition="$(MSBuildProjectName.EndsWith('_wpftmp'))">true</IsWpfTempProject>
</PropertyGroup>

<!--
Inspired by https://github.com/dotnet/arcade/blob/cbfa29d4e859622ada3d226f90f103f659665d31/src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.props#L14-L31
Disable Source Link and Xliff in WPF temp projects to avoid generating non-deterministic file names to obj dir.
The project name is non-deterministic and is included in the Source Link json file name and xlf directory names.
It's also not necessary to generate these assets.
-->
<PropertyGroup Condition="'$(IsWpfTempProject)' == 'true'">
<EnableSourceLink>false</EnableSourceLink>
<EmbedUntrackedSources>false</EmbedUntrackedSources>
<DeterministicSourcePaths>false</DeterministicSourcePaths>
<EnableXlfLocalization>false</EnableXlfLocalization>
</PropertyGroup>
</Project>
5 changes: 2 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<!-- Workaround https://github.com/dotnet/wpf/issues/1718 -->
<EmbedUntrackedSources Condition=" '$(UseWPF)' == 'true' ">false</EmbedUntrackedSources>
<LangVersion Condition="'$(Language)'=='C#'">12</LangVersion>
<LangVersion Condition="'$(Language)'=='VB'">16.9</LangVersion>
</PropertyGroup>

<ItemGroup>
<!-- Avoid compile error about missing namespace when combining ImplicitUsings with .NET Framework target frameworks. -->
<Using Remove="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'" />
Expand Down
15 changes: 6 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageVersion Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="$(VSThreadingVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="$(VSThreadingVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
Expand All @@ -28,20 +28,17 @@
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="xunit.combinatorial" Version="1.6.24" />
<PackageVersion Include="xunit.extensibility.core" Version="2.7.1" />
<PackageVersion Include="xunit.extensibility.core" Version="2.9.2" />
<PackageVersion Include="xunit.runner.console" Version="2.6.4" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.skippablefact" Version="1.4.13" />
<PackageVersion Include="xunit" Version="2.7.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="CSharpIsNullAnalyzer" Version="0.1.495" />
<GlobalPackageReference Include="CSharpIsNullAnalyzer" Version="0.1.593" />
<GlobalPackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.143" />
<GlobalPackageReference Include="Nullable" Version="1.3.1" />
<GlobalPackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions azure-pipelines/Get-LibTemplateBasis.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<#
.SYNOPSIS
Returns the name of the well-known branch in the Library.Template repository upon which HEAD is based.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
Param(
[switch]$ErrorIfNotRelated
)

# This list should be sorted in order of decreasing specificity.
$branchMarkers = @(
@{ commit = 'fd0a7b25ccf030bbd16880cca6efe009d5b1fffc'; branch = 'microbuild' };
@{ commit = '05f49ce799c1f9cc696d53eea89699d80f59f833'; branch = 'main' };
)

foreach ($entry in $branchMarkers) {
if (git rev-list HEAD | Select-String -Pattern $entry.commit) {
return $entry.branch
}
}

if ($ErrorIfNotRelated) {
Write-Error "Library.Template has not been previously merged with this repo. Please review https://github.com/AArnott/Library.Template/tree/main?tab=readme-ov-file#readme for instructions."
exit 1
}
4 changes: 2 additions & 2 deletions azure-pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- job: Linux
pool:
vmImage: Ubuntu 20.04
vmImage: Ubuntu-22.04
steps:
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
Expand All @@ -55,7 +55,7 @@ jobs:
- job: macOS
condition: ${{ parameters.includeMacOS }}
pool:
vmImage: macOS-12
vmImage: macOS-14
steps:
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
Expand Down
146 changes: 146 additions & 0 deletions azure-pipelines/libtemplate-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This pipeline schedules regular merges of Library.Template into a repo that is based on it.
# Only Azure Repos are supported. GitHub support comes via a GitHub Actions workflow.

trigger: none
pr: none
schedules:
- cron: "0 3 * * Mon" # Sun @ 8 or 9 PM Mountain Time (depending on DST)
displayName: Weekly trigger
branches:
include:
- main
always: true

parameters:
- name: AutoComplete
displayName: Auto-complete pull request
type: boolean
default: false

stages:
- stage: Merge
jobs:
- job: merge
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
fetchDepth: 0
clean: true
- pwsh: |
$LibTemplateBranch = & ./azure-pipelines/Get-LibTemplateBasis.ps1 -ErrorIfNotRelated
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
git fetch https://github.com/aarnott/Library.Template $LibTemplateBranch
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$LibTemplateCommit = git rev-parse FETCH_HEAD
if ((git rev-list FETCH_HEAD ^HEAD --count) -eq 0) {
Write-Host "There are no Library.Template updates to merge."
exit 0
}
$UpdateBranchName = 'auto/libtemplateUpdate'
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push origin -f FETCH_HEAD:refs/heads/$UpdateBranchName
Write-Host "Creating pull request"
$contentType = 'application/json';
$headers = @{ Authorization = 'Bearer $(System.AccessToken)' };
$rawRequest = @{
sourceRefName = "refs/heads/$UpdateBranchName";
targetRefName = "refs/heads/main";
title = 'Merge latest Library.Template';
description = "This merges the latest features and fixes from [Library.Template's $LibTemplateBranch branch](https://github.com/AArnott/Library.Template/tree/$LibTemplateBranch).";
}
$request = ConvertTo-Json $rawRequest
$prApiBaseUri = '$(System.TeamFoundationCollectionUri)/$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.ID)/pullrequests'
$prCreationUri = $prApiBaseUri + "?api-version=6.0"
Write-Host "POST $prCreationUri"
Write-Host $request
$prCreationResult = Invoke-RestMethod -uri $prCreationUri -method POST -Headers $headers -ContentType $contentType -Body $request
$prUrl = "$($prCreationResult.repository.webUrl)/pullrequest/$($prCreationResult.pullRequestId)"
Write-Host "Pull request: $prUrl"
$prApiBaseUri += "/$($prCreationResult.pullRequestId)"
$SummaryPath = Join-Path '$(Agent.TempDirectory)' 'summary.md'
Set-Content -Path $SummaryPath -Value "[Insertion pull request]($prUrl)"
Write-Host "##vso[task.uploadsummary]$SummaryPath"
# Tag the PR
$tagUri = "$prApiBaseUri/labels?api-version=7.0"
$rawRequest = @{
name = 'auto-template-merge';
}
$request = ConvertTo-Json $rawRequest
Invoke-RestMethod -uri $tagUri -method POST -Headers $headers -ContentType $contentType -Body $request | Out-Null
# Add properties to the PR that we can programatically parse later.
Function Set-PRProperties($properties) {
$rawRequest = $properties.GetEnumerator() |% {
@{
op = 'add'
path = "/$($_.key)"
from = $null
value = $_.value
}
}
$request = ConvertTo-Json $rawRequest
$setPrPropertyUri = "$prApiBaseUri/properties?api-version=7.0"
Write-Debug "$request"
$setPrPropertyResult = Invoke-RestMethod -uri $setPrPropertyUri -method PATCH -Headers $headers -ContentType 'application/json-patch+json' -Body $request -StatusCodeVariable setPrPropertyStatus -SkipHttpErrorCheck
if ($setPrPropertyStatus -ne 200) {
Write-Host "##vso[task.logissue type=warning]Failed to set pull request properties. Result: $setPrPropertyStatus. $($setPrPropertyResult.message)"
}
}
Write-Host "Setting pull request properties"
Set-PRProperties @{
'AutomatedMerge.SourceBranch' = $LibTemplateBranch
'AutomatedMerge.SourceCommit' = $LibTemplateCommit
}
# Add an *active* PR comment to warn users to *merge* the pull request instead of squash it.
$request = ConvertTo-Json @{
comments = @(
@{
parentCommentId = 0
content = "Do **not** squash this pull request when completing it. You must *merge* it."
commentType = 'system'
}
)
status = 'active'
}
$result = Invoke-RestMethod -uri "$prApiBaseUri/threads?api-version=7.1" -method POST -Headers $headers -ContentType $contentType -Body $request -StatusCodeVariable addCommentStatus -SkipHttpErrorCheck
if ($addCommentStatus -ne 200) {
Write-Host "##vso[task.logissue type=warning]Failed to post comment on pull request. Result: $addCommentStatus. $($result.message)"
}
# Set auto-complete on the PR
if ('${{ parameters.AutoComplete }}' -eq 'True') {
Write-Host "Setting auto-complete"
$mergeMessage = "Merged PR $($prCreationResult.pullRequestId): " + $commitMessage
$rawRequest = @{
autoCompleteSetBy = @{
id = $prCreationResult.createdBy.id
};
completionOptions = @{
deleteSourceBranch = $true;
mergeCommitMessage = $mergeMessage;
mergeStrategy = 'noFastForward';
};
}
$request = ConvertTo-Json $rawRequest
Write-Host $request
$uri = "$($prApiBaseUri)?api-version=6.0"
$result = Invoke-RestMethod -uri $uri -method PATCH -Headers $headers -ContentType $contentType -Body $request -StatusCodeVariable autoCompleteStatus -SkipHttpErrorCheck
if ($autoCompleteStatus -ne 200) {
Write-Host "##vso[task.logissue type=warning]Failed to set auto-complete on pull request. Result: $autoCompleteStatus. $($result.message)"
}
}
displayName: Create pull request
3 changes: 1 addition & 2 deletions azure-pipelines/publish-codecoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ steps:
condition: and(succeeded(), ${{ parameters.includeMacOS }})
- powershell: azure-pipelines/Merge-CodeCoverage.ps1 -Path '$(Pipeline.Workspace)' -OutputFile coveragereport/merged.cobertura.xml -Format Cobertura -Verbose
displayName: ⚙ Merge coverage
- task: PublishCodeCoverageResults@1
- task: PublishCodeCoverageResults@2
displayName: 📢 Publish code coverage results to Azure DevOps
inputs:
codeCoverageTool: cobertura
summaryFileLocation: coveragereport/merged.cobertura.xml
failIfCoverageEmpty: true
6 changes: 6 additions & 0 deletions azurepipelines-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://learn.microsoft.com/azure/devops/pipelines/test/codecoverage-for-pullrequests?view=azure-devops
coverage:
status:
comments: on # add comment to PRs reporting diff in coverage of modified files
diff: # diff coverage is code coverage only for the lines changed in a pull request.
target: 70% # set this to a desired %. Default is 70%
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.201",
"version": "8.0.402",
"rollForward": "patch",
"allowPrerelease": false
}
Expand Down
6 changes: 6 additions & 0 deletions src/AssemblyInfo.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
' Copyright (c) COMPANY-PLACEHOLDER. All rights reserved.
' Licensed under the MIT license. See LICENSE file in the project root for full license information.

Imports System.Runtime.InteropServices

<Assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)>
3 changes: 2 additions & 1 deletion src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" Condition=" '$(Language)'=='C#' " />
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.vb" Condition=" '$(Language)'=='VB' " />
</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove($(MSBuildThisFile), $(MSBuildThisFileDirectory)..))" />
Expand Down
2 changes: 1 addition & 1 deletion src/Nerdbank.Streams/NestedStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
return 0;
}

int bytesRead = await this.underlyingStream.ReadAsync(buffer, offset, count).ConfigureAwaitRunInline();
int bytesRead = await this.underlyingStream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwaitRunInline();
this.remainingBytes -= bytesRead;
return bytesRead;
}
Expand Down
Loading

0 comments on commit 2078689

Please sign in to comment.