[ci] Remove unaffected ports from pull request builds (#21078)

* Rewrite to single invovation of 'vcpkg ci'

* Split caching args from common args

* Use parent hashes for pull request CI builds

* Completely switch to parent revision state and back
This commit is contained in:
Kai Pastor 2021-11-01 20:18:28 +01:00 committed by GitHub
parent 5bdb9d6012
commit eea02380aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,9 +23,14 @@ The type and parameters of the binary source. Shared across runs of this script.
this parameter is not set, binary caching will not be used. Example: "files,W:\"
.PARAMETER BuildReason
The reason Azure Pipelines is running this script (controls in which mode Binary Caching is used).
If BinarySourceStub is not set, this parameter has no effect. If BinarySourceStub is set and this is
not, binary caching will default to read-write mode.
The reason Azure Pipelines is running this script. For invocations caused by `PullRequest`,
modified ports are identified by changed hashes with regard to git HEAD~1 (subject to NoParentHashes),
and ports marked as failing in the CI baseline (or which depend on such ports) are skipped.
If BinarySourceStub is set and this parameter is set to a non-empty value other than `PullRequest`,
binary caching will be in write-only mode.
.PARAMETER NoParentHashes
Indicates to not use parent hashes even for pull requests.
.PARAMETER PassingIsPassing
Indicates that 'Passing, remove from fail list' results should not be emitted as failures. (For example, this is used
@ -49,6 +54,7 @@ Param(
[String]$BuildReason = $null,
[String[]]$AdditionalSkips = @(),
[String[]]$OnlyTest = $null,
[switch]$NoParentHashes = $false,
[switch]$PassingIsPassing = $false
)
@ -77,12 +83,13 @@ $commonArgs = @(
"--x-packages-root=$packagesRoot",
"--overlay-ports=scripts/test_ports"
)
$cachingArgs = @()
$skipFailures = $false
if ([string]::IsNullOrWhiteSpace($BinarySourceStub)) {
$commonArgs += @('--no-binarycaching')
$cachingArgs = @('--no-binarycaching')
} else {
$commonArgs += @('--binarycaching')
$cachingArgs = @('--binarycaching')
$binaryCachingMode = 'readwrite'
if ([string]::IsNullOrWhiteSpace($BuildReason)) {
Write-Host 'Build reason not specified, defaulting to using binary caching in read write mode.'
@ -96,7 +103,7 @@ if ([string]::IsNullOrWhiteSpace($BinarySourceStub)) {
$binaryCachingMode = 'write'
}
$commonArgs += @("--binarysource=clear;$BinarySourceStub,$binaryCachingMode")
$cachingArgs += @("--binarysource=clear;$BinarySourceStub,$binaryCachingMode")
}
if ($Triplet -eq 'x64-linux') {
@ -141,7 +148,7 @@ if ($null -ne $OnlyTest)
{
$OnlyTest | % {
$portName = $_
& "./vcpkg$executableExtension" install --triplet $Triplet @commonArgs $portName
& "./vcpkg$executableExtension" install --triplet $Triplet @commonArgs @cachingArgs $portName
if (-not $?)
{
[System.Console]::Error.WriteLine( `
@ -155,17 +162,35 @@ if ($null -ne $OnlyTest)
}
else
{
$hostArgs = @()
if ($Triplet -in @('x64-windows', 'x64-osx', 'x64-linux'))
{
# WORKAROUND: These triplets are native-targetting which triggers an issue in how vcpkg handles the skip list.
# The workaround is to pass the skip list as host-excludes as well.
& "./vcpkg$executableExtension" ci $Triplet --x-xunit=$xmlFile --exclude=$skipList --host-exclude=$skipList --failure-logs=$failureLogs @commonArgs
$hostArgs = @("--host-exclude=$skipList")
}
else
$parentHashes = @()
if (($BuildReason -eq 'PullRequest') -and -not $NoParentHashes)
{
& "./vcpkg$executableExtension" ci $Triplet --x-xunit=$xmlFile --exclude=$skipList --failure-logs=$failureLogs @commonArgs
# Prefetch tools for better output
& "./vcpkg$executableExtension" fetch cmake
& "./vcpkg$executableExtension" fetch ninja
& "./vcpkg$executableExtension" fetch git
Write-Host "Determining parent hashes using HEAD~1"
$parentHashesFile = Join-Path $WorkingRoot 'parent-hashes.json'
$parentHashes = @("--parent-hashes=$parentHashesFile")
& git revert -n -m 1 HEAD
& "./vcpkg$executableExtension" ci $Triplet --dry-run --exclude=$skipList @hostArgs @commonArgs --no-binarycaching "--output-hashes=$parentHashesFile" `
| ForEach-Object { if ($_ -match ' dependency information| determine pass') { Write-Host $_ } }
& git reset --hard HEAD
Write-Host "Running CI using parent hashes"
}
& "./vcpkg$executableExtension" ci $Triplet --x-xunit=$xmlFile --exclude=$skipList --failure-logs=$failureLogs @hostArgs @commonArgs @cachingArgs @parentHashes
$failureLogsEmpty = (-Not (Test-Path $failureLogs) -Or ((Get-ChildItem $failureLogs).count -eq 0))
Write-Host "##vso[task.setvariable variable=FAILURE_LOGS_EMPTY]$failureLogsEmpty"