Sign the `*.VSInsertionMetadata` optprof package

This commit is contained in:
Andrew Arnott 2024-07-08 17:53:47 -06:00
Родитель 71b9db8237
Коммит 03d69cfcbb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F33A420C60ED9C6F
8 изменённых файлов: 83 добавлений и 50 удалений

Просмотреть файл

@ -105,6 +105,8 @@ try {
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
git mv test/Library.Tests "test/$LibraryName.Tests"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
git mv src/VSInsertionMetadata/Library.VSInsertionMetadata.proj "src/VSInsertionMetadata/$LibraryName.VSInsertionMetadata.proj"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# Refresh solution file both to update paths and give the projects unique GUIDs
dotnet sln remove src/Library/Library.csproj
@ -168,12 +170,6 @@ try {
'LibraryName' = $LibraryName;
}
Replace-Placeholders -Path "azure-pipelines/InsertionMetadataPackage.nuspec" -Replacements @{
'LibraryName' = $LibraryName;
}
Replace-Placeholders -Path "azure-pipelines/artifacts/VSInsertion.ps1" -Replacements @{
'LibraryName' = $LibraryName;
}
Replace-Placeholders -Path "azure-pipelines/OptProf.yml" -Replacements @{
'LibraryName' = $LibraryName;
}

Просмотреть файл

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<package>
<!-- This file is only used in repos where OptProf is enabled. -->
<metadata>
<id>LibraryName.VSInsertionMetadata</id>
<version>$version$</version>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<!-- <projectUrl>https://github.com/Microsoft/LibraryName</projectUrl> -->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Contains metadata for insertion into VS.</description>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
</metadata>
<files>
<file src="ProfilingInputs.props" target="InsertionVS/" />
</files>
</package>

Просмотреть файл

@ -29,30 +29,7 @@ $result = @{
if ($env:IsOptProf) {
$VSRepoPackages = "$RepoRoot/bin/Packages/$BuildConfiguration/VSRepo"
$ArtifactBasePath = "$RepoRoot\obj\_artifacts"
$ArtifactPath = "$ArtifactBasePath\VSInsertion"
if (-not (Test-Path $ArtifactPath)) { New-Item -ItemType Directory -Path $ArtifactPath | Out-Null }
$profilingInputs = [xml](Get-Content -Path "$PSScriptRoot\..\ProfilingInputs.props")
$profilingInputs.Project.ItemGroup.TestStore.Include = "vstsdrop:" + (& "$PSScriptRoot\..\variables\ProfilingInputsDropName.ps1")
$profilingInputs.Save("$ArtifactPath\ProfilingInputs.props")
$InsertionMetadataVersion = $(dotnet tool run nbgv get-version -p "$RepoRoot\src" -f json | ConvertFrom-Json).NuGetPackageVersion
if ($env:BUILD_BUILDID) {
# We must ensure unique versions for the insertion metadata package so
# it can contain information that is unique to this build.
# In particular it includes the ProfilingInputsDropName, which contains the BuildId.
# A non-unique package version here may collide with a prior run of this same commit,
# ultimately resulting in a failure of the optprof run.
$InsertionMetadataVersion += '.' + $env:BUILD_BUILDID
}
& (& "$PSScriptRoot\..\Get-NuGetTool.ps1") pack "$PSScriptRoot\..\InsertionMetadataPackage.nuspec" -OutputDirectory $VSRepoPackages -BasePath $ArtifactPath -Version $InsertionMetadataVersion | Out-Null
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$result["$VSRepoPackages"] = (Get-ChildItem "$VSRepoPackages\LibraryName.VSInsertionMetadata.$InsertionMetadataVersion.nupkg");
$result["$VSRepoPackages"] = (Get-ChildItem "$VSRepoPackages\*.VSInsertionMetadata.*.nupkg");
}
$result

Просмотреть файл

@ -17,9 +17,8 @@ steps:
condition: and(succeeded(), ${{ parameters.RunTests }})
- ${{ if parameters.IsOptProf }}:
# We have to artifically run this script so that the extra .nupkg is produced for variables/InsertPropsValues.ps1 to notice.
- powershell: azure-pipelines\artifacts\VSInsertion.ps1
displayName: 🔧 Prepare VSInsertion artifact
- script: dotnet pack src\VSInsertionMetadata -c $(BuildConfiguration) -warnaserror /bl:"$(Build.ArtifactStagingDirectory)/build_logs/VSInsertion-Pack.binlog"
displayName: 🔧 dotnet pack VSInsertionMetadata
- powershell: azure-pipelines/variables/_pipelines.ps1
failOnStderr: true

Просмотреть файл

@ -3,5 +3,8 @@
"version": "8.0.300",
"rollForward": "patch",
"allowPrerelease": false
},
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "3.7.56"
}
}

Просмотреть файл

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<PackageOutputPath>$(RepoRootPath)bin\Packages\$(Configuration)\VSRepo\</PackageOutputPath>
<IncludeSymbols>false</IncludeSymbols>
<EnableDefaultSignFiles>false</EnableDefaultSignFiles>
<Description>Contains metadata for insertion into VS.</Description>
</PropertyGroup>
<Import Project="VSInsertionMetadata.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,64 @@
<Project>
<UsingTask TaskName="ReplaceFileText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
File.WriteAllText(
OutputFilename,
Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
);
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<TargetsForTfmSpecificContentInPackage>
$(TargetsForTfmSpecificContentInPackage);
SubstituteProfilingInputsMacro;
SubstituteProfilingInputsMacroWarning;
</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="SubstituteProfilingInputsMacroWarning" Condition="'$(ProfilingInputsDropName)'==''">
<Warning Text="The ProfilingInputsDropName msbuild property has not been set, and the OptProf will not contain accurate content."/>
</Target>
<Target Name="SubstituteProfilingInputsMacro" Condition="'$(ProfilingInputsDropName)'!=''">
<ItemGroup>
<ProfilingInputsSource Include="ProfilingInputs.props" />
<ProfilingInputsTarget Include="$(IntermediateOutputPath)ProfilingInputs.props" />
</ItemGroup>
<ReplaceFileText
Condition="'$(ProfilingInputsDropName)' != ''"
InputFilename="@(ProfilingInputsSource)"
OutputFilename="@(ProfilingInputsTarget)"
MatchExpression="%TESTSTORE%"
ReplacementText="vstsdrop:$(ProfilingInputsDropName)" />
<ItemGroup>
<TfmSpecificPackageFile Include="@(ProfilingInputsTarget)" PackagePath="InsertionVS/" />
</ItemGroup>
</Target>
<Target Name="EnsureUniquePackageVersion"
Condition="'$(Build_BuildId)' != ''"
AfterTargets="GetBuildVersion">
<!--
We must ensure unique versions for the insertion metadata package so
it can contain information that is unique to this build.
In particular it includes the ProfilingInputsDropName, which contains the BuildId.
A non-unique package version here may collide with a prior run of this same commit,
ultimately resulting in a failure of the optprof run.
-->
<PropertyGroup>
<PackageVersion>$(PackageVersion).$(Build_BuildId)</PackageVersion>
</PropertyGroup>
</Target>
</Project>