Skip to content

Commit

Permalink
ci: Only run tests for modified code on presubmits.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-tarafa authored and anshuldavid13 committed Apr 29, 2022
1 parent 5c6d540 commit 8b07577
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions .kokoro/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ try {

# Import secrets:
.\.kokoro-windows\Import-Secrets.ps1


# The list of changed subdirectories.
git config --global --add safe.directory /tmpfs/src/github/dotnet-docs-samples
$changedDirs = ($(git diff main --name-only | cut -d/ -f 1 | uniq))

# The list of all subdirectories.
$allDirs = Get-ChildItem | Where-Object {$_.PSIsContainer} | Select-Object -ExpandProperty Name

# If no dirs have changed we run everything since we are most likely on CI.
if ($changedDirs.Count -gt 0)
{
$testDirs = $changedDirs
}
else
{
$testDirs = $allDirs
}

# There are too many tests to run in a single Kokoro job. So, we split
# the tests into groups. Each Kokoro job runs one group.

Expand All @@ -38,17 +52,20 @@ try {
$false # 3: Everything starting from s to z.
)

$groups[0] = $allDirs
$groups[1] = $allDirs | Where-Object { ($_.Substring(0, 1).CompareTo("a") -ge 0) -and ($_.Substring(0, 1).CompareTo("e") -le 0) }
$groups[2] = $allDirs | Where-Object { ($_.Substring(0, 1).CompareTo("f") -ge 0) -and ($_.Substring(0, 1).CompareTo("r") -le 0) -and ($IsRunningOnWindows -or -not ($_.Equals("iot"))) }
$groups[3] = $allDirs | Where-Object { ($_.Substring(0, 1).CompareTo("s") -ge 0) -and ($_.Substring(0, 1).CompareTo("z") -le 0) }
$groups[0] = $testDirs
$groups[1] = $testDirs | Where-Object { ($_.Substring(0, 1).CompareTo("a") -ge 0) -and ($_.Substring(0, 1).CompareTo("e") -le 0) }
$groups[2] = $testDirs | Where-Object { ($_.Substring(0, 1).CompareTo("f") -ge 0) -and ($_.Substring(0, 1).CompareTo("r") -le 0) -and ($IsRunningOnWindows -or -not ($_.Equals("iot"))) }
$groups[3] = $testDirs | Where-Object { ($_.Substring(0, 1).CompareTo("s") -ge 0) -and ($_.Substring(0, 1).CompareTo("z") -le 0) }
$dirs = $groups[$GroupNumber]

# Find all the runTest scripts.
$scripts = Get-ChildItem -Path $dirs -Filter *runTest*.ps* -Recurse
$scripts.VersionInfo.FileName `
| Sort-Object -Descending -Property {Get-GitTimeStampForScript $_} `
| Run-TestScripts -TimeoutSeconds 600
if ($dirs.Count -gt 0)
{
# Find all the runTest scripts.
$scripts = Get-ChildItem -Path $dirs -Filter *runTest*.ps* -Recurse
$scripts.VersionInfo.FileName `
| Sort-Object -Descending -Property {Get-GitTimeStampForScript $_} `
| Run-TestScripts -TimeoutSeconds 600
}
} finally {
Pop-Location
}
Expand Down

0 comments on commit 8b07577

Please sign in to comment.