Use nerdbank.gitversioning to better deal with versioning (#476)

* Converting to use Nerdbank.GitVersioning

Thanks to @AArnott for this cool project that automatically increments our build numbers for us.

Co-authored-by: Steve Otteson <sotteson@microsoft.com>
This commit is contained in:
Steve Otteson 2021-05-14 16:09:07 -07:00 коммит произвёл GitHub
Родитель 0a0eb7feea
Коммит de5e2abfc0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 120 добавлений и 124 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -365,3 +365,4 @@ MigrationBackup/
/generation/emitter/functionPointerFixups.generated.rsp
/generation/scraper/functionPointerFixups.generated.rsp
/generation/emitter/enumsMakeFlags.generated.rsp
/sources/msbuild/sdk/sdk.stamped.props

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

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!--
Directory.Build.props is automatically picked up and imported by
Microsoft.Common.props. This file needs to exist, even if empty so that
@ -9,5 +8,10 @@
beforehand. We also don't need to add ourselves to MSBuildAllProjects, as
that is done by the file that imports us.
-->
</Project>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
<Version>3.4.194</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

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

@ -5,44 +5,6 @@ trigger:
pr: none
jobs:
- job: job_calc_nuget_version
displayName: Calculate published NuGet version
pool:
name: Package ES Standard Build
variables:
System.Debug: true
MainPatch: $[counter(variables['MainNugetVersion'], 0)]
MSBuildSDKPatch: $[counter(variables['MSBuildSDKNugetVersion'], 0)]
BuildNumberSuffix: $(Build.BuildNumber)
steps:
- checkout: none
- task: PowerShell@2
name: echoVersion
displayName: Update MainNugetVersion, set build number
inputs:
pwsh: true
targetType: 'inline'
script: |
$ver = "${env:MainNugetVersion}"
$parts = $ver.Split(".")
$parts[2] = ${env:MainPatch}
$nugetVer = [string]::Join(".", $parts) + "-preview"
Write-Output "##vso[task.setvariable variable=MainNugetVersion;isOutput=true;]$nugetVer"
$verSuffix = ${env:BuildNumberSuffix}
Write-Host "##vso[build.updatebuildnumber]$($nugetVer)_$($verSuffix)"
$ver = "${env:MSBuildSDKNugetVersion}"
$parts = $ver.Split(".")
$parts[2] = ${env:MSBuildSDKPatch}
$nugetVer = [string]::Join(".", $parts) + "-preview"
Write-Output "##vso[task.setvariable variable=MSBuildSDKNugetVersion;isOutput=true;]$nugetVer"
- script: echo MainNugetVersion = $(echoVersion.MainNugetVersion), MSBuildSDKNugetVersion = $(echoVersion.MSBuildSDKNugetVersion)
displayName: Echo publish nuget versions
- job: scrape_x64
displayName: "Scrape headers: x64"
pool:
@ -53,9 +15,6 @@ jobs:
- visualstudio -equals C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\
workspace:
clean: all
dependsOn: ['job_calc_nuget_version']
variables:
MainNugetVersion: $[ dependencies.job_calc_nuget_version.outputs['echoVersion.MainNugetVersion'] ]
steps:
- task: UseDotNet@2
@ -64,6 +23,17 @@ jobs:
packageType: 'sdk'
version: '3.x'
- task: PowerShell@2
displayName: Set build version
inputs:
targetType: inline
script: |
. .\scripts\CommonUtils.ps1
Install-DotNetTool nbgv
nbgv cloud
errorActionPreference: 'continue'
pwsh: true
- task: PowerShell@2
displayName: GenerateMetadataSource.ps1 - x64
inputs:
@ -76,7 +46,7 @@ jobs:
displayName: Scrape constants
inputs:
filePath: 'scripts\BuildMetadataBin.ps1'
arguments: '-assemblyVersion $(MainNugetVersion) -arch crossarch -SkipBinary'
arguments: '-arch crossarch -SkipBinary'
pwsh: true
- publish: 'generation\scraper\obj\x64'
@ -97,7 +67,6 @@ jobs:
- visualstudio -equals C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\
workspace:
clean: all
dependsOn: ['job_calc_nuget_version']
steps:
- task: UseDotNet@2
displayName: Use DotNet 3.x
@ -127,7 +96,6 @@ jobs:
- visualstudio -equals C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\
workspace:
clean: all
dependsOn: ['job_calc_nuget_version']
steps:
- task: UseDotNet@2
displayName: Use DotNet 3.x
@ -151,10 +119,8 @@ jobs:
displayName: Build, test, sign, package winmd
workspace:
clean: all
dependsOn: ['job_calc_nuget_version','scrape_x64','scrape_x86','scrape_arm64']
dependsOn: ['scrape_x64','scrape_x86','scrape_arm64']
variables:
MainNugetVersion: $[ dependencies.job_calc_nuget_version.outputs['echoVersion.MainNugetVersion']]
MSBuildSDKNugetVersion: $[ dependencies.job_calc_nuget_version.outputs['echoVersion.MSBuildSDKNugetVersion']]
OutputPackagesDir: $(Build.ArtifactStagingDirectory)\CreatedNugetPackages
pool:
name: Package ES Standard Build
@ -204,7 +170,7 @@ jobs:
displayName: Build metadata binary
inputs:
filePath: 'scripts\BuildMetadataBin.ps1'
arguments: '-assemblyVersion $(MainNugetVersion) -arch crossarch -SkipConstants'
arguments: '-arch crossarch -SkipConstants'
pwsh: true
- publish: 'bin'
@ -304,28 +270,23 @@ jobs:
MaxRetryAttempts: '2'
condition: eq(variables['SignFiles'], 'true')
# There's a problem on microsoft.visualstudio.com that requires the guid instead of NuGetCommand@2
- task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2
displayName: Pack metadata nuget package
- task: PowerShell@2
displayName: Pack metadata package
inputs:
command: 'pack'
packagesToPack: 'sources\nuget\Microsoft.Windows.SDK.Win32Metadata\Microsoft.Windows.SDK.Win32Metadata.nuspec'
packDestination: '$(OutputPackagesDir)'
versioningScheme: 'byEnvVar'
versionEnvVar: 'MainNugetVersion'
basePath: '$(Build.SourcesDirectory)'
targetType: inline
script: |
cd $(Build.SourcesDirectory)\sources\nuget\Microsoft.Windows.SDK.Win32Metadata
dotnet pack -o "$(OutputPackagesDir)"
errorActionPreference: 'continue'
pwsh: true
- task: PowerShell@2
displayName: Pack MSBuildSDK package
inputs:
targetType: inline
script: |
. $(Build.SourcesDirectory)\scripts\CommonUtils.ps1
[hashtable]$textToReplaceTable = @{ "10.0.19041.202-preview" = "$(MainNugetVersion)" }
Replace-Text "$(Build.SourcesDirectory)\sources\msbuild\sdk\sdk.props" $textToReplaceTable
cd $(Build.SourcesDirectory)\sources\msbuild\nuget
dotnet pack -p:NuspecProperties="version=$(MSBuildSDKNugetVersion)" -o "$(OutputPackagesDir)"
dotnet pack -o "$(OutputPackagesDir)"
errorActionPreference: 'continue'
pwsh: true

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

@ -1,8 +1,5 @@
param
(
[string]
$assemblyVersion,
[ValidateSet("crossarch", "x64", "x86", "arm64")]
[string]
$arch = "crossarch",
@ -20,15 +17,10 @@ if ($arch -eq "crossarch")
. "$PSScriptRoot\CommonUtils.ps1"
if (!$assemblyVersion)
{
$assemblyVersion = $defaultWinSDKNugetVersion
}
$assemblyVersion = FixVersionForAssembly($assemblyVersion)
Install-BuildTools
$assemblyVersion = nbgv get-version -v AssemblyVersion
& $PSScriptRoot\CreateRspsForFunctionPointerFixups.ps1 -arch $scraperArch
$constantsScraperPathBin = "$metadataToolsBin\ConstantsScraper.dll"

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

@ -24,22 +24,6 @@ if (!(Test-Path -Path $binDir))
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
}
function FixVersionForAssembly([string] $version)
{
$dash = $version.IndexOf('-')
if ($dash -ne -1)
{
$version = $version.Substring(0, $dash)
}
if ($version.Split('.').Length -eq 3)
{
$version += '.0'
}
return $version
}
function Create-Directory([string[]] $Path)
{
if (!(Test-Path -Path $Path))
@ -58,18 +42,30 @@ function Remove-Directory([string[]] $Path)
function Install-DotNetTool
{
Param ([string] $Name, [string] $Version)
Param ([string] $Name, [string] $Version = '')
$installed = & dotnet tool list -g | select-string "$Name\s+$Version"
if (!$installed.Length)
if ($Version -ne '')
{
& dotnet tool update --global $Name --version $Version
$installed = & dotnet tool list -g | select-string "$Name\s+$Version"
if (!$installed.Length)
{
& dotnet tool update --global $Name --version $Version
}
}
else
{
$installed = & dotnet tool list -g | select-string "$Name"
if (!$installed.Length)
{
& dotnet tool update --global $Name
}
}
}
function Install-BuildTools
{
Install-DotNetTool -Name ClangSharpPInvokeGenerator -Version 11.0.0-beta3
Install-DotNetTool -Name nbgv
& dotnet build "$rootDir\BuildTools\BuildTools.proj" -c Release
}

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

@ -19,7 +19,7 @@
<files>
<file src="images\windows.png" target="images"/>
<file src="sources\msbuild\sdk\sdk.props" target="sdk"/>
<file src="sources\msbuild\sdk\sdk.stamped.props" target="sdk\sdk.props"/>
<file src="sources\msbuild\sdk\sdk.targets" target="sdk"/>
<file src="tools\dumpbin.exe" target="tools"/>

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

@ -1,10 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PowerShell># 2>nul || type %~df0|find /v "setlocal"|find /v "errorlevel"|powershell.exe -noninteractive -&amp; exit %errorlevel% || #</PowerShell>
</PropertyGroup>
<Target Name="StampPropsFile" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
<PropertyGroup>
<StampPropsScript>
$(PowerShell)
$mainNugetVersion = nbgv get-version -v NuGetPackageVersion -p ..\..\..
. ..\..\..\scripts\CommonUtils.ps1
copy ..\sdk\sdk.props ..\sdk\sdk.stamped.props
[hashtable]$textToReplaceTable = @{ "10.0.19041.202-preview" = $mainNugetVersion }
Replace-Text "..\sdk\sdk.stamped.props" $textToReplaceTable
</StampPropsScript>
</PropertyGroup>
<Exec Command="$(StampPropsScript)" EchoOff="false" />
</Target>
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);Version=$(Version)</NuspecProperties>
</PropertyGroup>
</Target>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
<NuspecFile>BuildSdk.nuspec</NuspecFile>
<NuspecProperties></NuspecProperties>
<NuspecBasePath>..\..\..</NuspecBasePath>
<PackageType>MSBuildSdk</PackageType>
</PropertyGroup>

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

@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.2-preview",
"assemblyVersion": {
"precision": "revision"
},
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/v\\d+(?:\\.\\d+)?$"
]
}

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

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<package>
<metadata>
<id>Microsoft.Windows.SDK.Win32.TestCLR</id>
<version>$version$</version>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<title>Win32 Metadata</title>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<summary>This package is a test .NET projection of the Win32 API surface.</summary>
<description>This package is a test .NET projection of the Win32 API surface.</description>
<projectUrl>https://aka.ms/WinSDKProjectURL</projectUrl>
<tags>Win32</tags>
<licenseUrl>https://aka.ms/WinSDKPreviewLicenseURL</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<iconUrl>https://aka.ms/WinSDKIconURL</iconUrl>
<dependencies>
<group targetFramework="netstandard2.0" />
</dependencies>
</metadata>
<files>
<file src="CsWin32ProjectionLib\bin\Release\netstandard2.0\Microsoft.Windows.SDK.Win32.TestCLR.dll" target="lib\netstandard2.0\Microsoft.Windows.SDK.Win32.TestCLR.dll"/>
</files>
</package>

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

@ -14,11 +14,13 @@
<tags>Win32 Metadata</tags>
<licenseUrl>https://aka.ms/WinSDKLicenseURL</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<iconUrl>https://aka.ms/WinSDKIconURL</iconUrl>
<icon>images\windows.png</icon>
<repository type="git" url="https://github.com/microsoft/win32metadata.git" />
</metadata>
<files>
<file src="images\windows.png" target="images"/>
<file src="bin\Windows.Win32.winmd" target=""/>
<file src="bin\Windows.Win32.Interop.dll" target=""/>
<file src="buildTransitive\**" target="buildTransitive\"/>

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

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);Version=$(Version)</NuspecProperties>
</PropertyGroup>
</Target>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
<NuspecFile>Microsoft.Windows.SDK.Win32Metadata.nuspec</NuspecFile>
<NuspecProperties></NuspecProperties>
<NuspecBasePath>..\..\..</NuspecBasePath>
</PropertyGroup>
</Project>

11
version.json Normal file
Просмотреть файл

@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "10.2-preview",
"assemblyVersion": {
"precision": "revision"
},
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/v\\d+(?:\\.\\d+)?$"
]
}