Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,21 @@ jobs:
env:
MAP_KIND: ${{ steps.map.outputs.kind }}
MAP_RUN_ID: ${{ steps.map.outputs.run_id }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
# NOT the event's base sha: that is the base branch as it stood when the pull request was
# opened, so for a pull request behind master it attributes every commit master
# has gained since to the pull request. The selector verifies the checked-out merge commit's
# second parent is this head and diffs against its first parent - the base actually tested.
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
$all = @(yq -o=json -I=0 '.shard' .github/test-shards.yml | ConvertFrom-Json)
if ($all.Count -eq 0) {
Write-Host '::error::.github/test-shards.yml yielded no shards'
exit 1
}
# Test sources are never instrumented, so the coverage map cannot route them; the selector
# routes them through these same filters instead.
ConvertTo-Json -InputObject @($all | Select-Object name, project, filter) -Depth 3 |
Set-Content -LiteralPath shard-manifest.json -Encoding utf8

function Read-RequiredJsonBoolean {
param(
Expand Down Expand Up @@ -734,7 +742,7 @@ jobs:
$pathRequiresValidation = $true
try {
& ./tools/TestImpact/Select-Shards.ps1 -ClassifyOnly `
-BaseSha $env:PR_BASE_SHA -OutFile path-classification.json
-PullRequestHeadSha $env:PR_HEAD_SHA -OutFile path-classification.json
if ($LASTEXITCODE -ne 0) { throw "path classifier exited $LASTEXITCODE" }
$pathResult = Get-Content path-classification.json -Raw | ConvertFrom-Json
$pathRequiresValidation = Read-RequiredJsonBoolean `
Expand All @@ -750,12 +758,14 @@ jobs:
$selected = @()
}
elseif ($mapCertified) {
# No base ref: coverage selection diffs from the map's own commit, which is the only
# reference whose line numbers the map's ranges are expressed in.
# Line ranges still come from the map's own commit, the only reference whose line
# numbers the map's ranges are expressed in; the pull request head only decides WHICH
# paths are this pull request's change.
try {
& ./tools/TestImpact/Select-Shards.ps1 `
-MapFile map/shard-map.json `
-BaseSha $env:PR_BASE_SHA `
-PullRequestHeadSha $env:PR_HEAD_SHA `
-ShardManifestFile shard-manifest.json `
-ExpectedShards @($all.name) `
-OutFile selection.json
if ($LASTEXITCODE -ne 0) { throw "shard selector exited $LASTEXITCODE" }
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/test-impact-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ jobs:
& git checkout --quiet $sourceSha
if ($LASTEXITCODE -ne 0) { throw 'checkout of audited commit failed - refusing to audit the wrong tree' }

# The audited tree's own shard filters, so replayed test-source routing is exactly what a pull
# request on that tree receives. Without it every test-source change escalates and the routing
# heuristic would never be measured against a complete matrix.
$auditManifest = Join-Path $env:RUNNER_TEMP 'audit-shard-manifest.json'
$auditShards = @(yq -o=json -I=0 '.shard' .github/test-shards.yml | ConvertFrom-Json)
ConvertTo-Json -InputObject @($auditShards | Select-Object name, project, filter) -Depth 3 |
Set-Content -LiteralPath $auditManifest -Encoding utf8

$audit = $null
$auditExit = 0
$basis = ''
Expand All @@ -383,7 +391,8 @@ jobs:
& (Join-Path $auditTools 'Measure-SelectionMiss.ps1') `
-SelectorPath (Join-Path $auditTools 'Select-Shards.ps1') `
-MapFile prevmap/shard-map.json -OutcomesFile outcomes.json `
-CurrentChangeBaseSha $sourceSha -OutFile historical-audit.json
-CurrentChangeBaseSha $sourceSha -ShardManifestFile $auditManifest `
-OutFile historical-audit.json
$auditExit = $LASTEXITCODE
& (Join-Path $auditTools 'New-ShardMapCertificate.ps1') `
-MapFile prevmap/shard-map.json -AuditFile historical-audit.json `
Expand Down Expand Up @@ -416,7 +425,8 @@ jobs:
& (Join-Path $auditTools 'Measure-SelectionMiss.ps1') `
-SelectorPath (Join-Path $auditTools 'Select-Shards.ps1') `
-MapFile shard-map.json -OutcomesFile outcomes.json `
-CurrentChangeBaseSha $sourceSha -OutFile fresh-audit.json
-CurrentChangeBaseSha $sourceSha -ShardManifestFile $auditManifest `
-OutFile fresh-audit.json
$auditExit = $LASTEXITCODE
& (Join-Path $auditTools 'New-ShardMapCertificate.ps1') `
-MapFile shard-map.json -AuditFile fresh-audit.json -OutcomesFile outcomes.json `
Expand Down
9 changes: 9 additions & 0 deletions tools/TestImpact/Measure-SelectionMiss.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
from the map SHA; this second boundary prevents already-merged selector-control edits from
being mistaken for edits in every later pull request.

.PARAMETER ShardManifestFile
Optional { name, project, filter } manifest passed through to the selector, so the audit replays
the same test-source routing pull requests receive. Without it test-source changes escalate
and the routing heuristic would never be measured.

.PARAMETER OutFile
Optional path for the JSON report.
#>
Expand All @@ -57,6 +62,7 @@ param(
[Parameter(Mandatory, ParameterSetName = 'Measure')] [string] $OutcomesFile,
[Parameter(ParameterSetName = 'Measure')] [string] $SelectorPath = "$PSScriptRoot/Select-Shards.ps1",
[Parameter(ParameterSetName = 'Measure')] [string] $CurrentChangeBaseSha,
[Parameter(ParameterSetName = 'Measure')] [string] $ShardManifestFile,
[Parameter(ParameterSetName = 'Measure')] [string] $OutFile,
[Parameter(Mandatory, ParameterSetName = 'SelfTest')] [switch] $SelfTest
)
Expand Down Expand Up @@ -196,6 +202,9 @@ $selectorArguments = @{
if ($CurrentChangeBaseSha) {
$selectorArguments.BaseSha = $CurrentChangeBaseSha
}
if ($ShardManifestFile) {
$selectorArguments.ShardManifestFile = $ShardManifestFile
}
& $SelectorPath @selectorArguments | Out-Null
$selection = Get-Content -LiteralPath $selectionFile -Raw | ConvertFrom-Json
Remove-Item -LiteralPath $selectionFile -ErrorAction SilentlyContinue
Expand Down
Loading
Loading