Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 8019 (#29254)
Browse files Browse the repository at this point in the history
Sync eng/common directory with azure-sdk-tools for PR
Azure/azure-sdk-tools#8019 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

---------

Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
  • Loading branch information
azure-sdk and benbp committed Apr 10, 2024
1 parent 156d92c commit 5d45fe6
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions eng/common/pipelines/templates/steps/sparse-checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,34 @@ steps:
# 7.2 behavior for command argument passing. Newer behaviors will result
# in errors from git.exe.
$PSNativeCommandArgumentPassing = 'Legacy'
function Retry()
{
Run 3 @args
}
function Run()
{
$retries, $command, $arguments = $args
if ($retries -isnot [int]) {
$command, $arguments = $args
$retries = 0
}
Write-Host "==>" $command $arguments
$attempt = 0
$sleep = 5
while ($true) {
$attempt++
& $command $arguments
if (!$LASTEXITCODE) { return }
if ($attempt -gt $retries) { exit $LASTEXITCODE }
Write-Warning "Attempt $attempt failed: $_. Trying again in $sleep seconds..."
Start-Sleep -Seconds $sleep
$sleep *= 2
}
}
function SparseCheckout([Array]$paths, [Hashtable]$repository)
{
$dir = $repository.WorkingDirectory
Expand All @@ -47,23 +74,18 @@ steps:
Write-Host "Repository $($repository.Name) is being initialized."
if ($repository.Commitish -match '^refs/pull/\d+/merge$') {
Write-Host "git clone --no-checkout --filter=tree:0 -c remote.origin.fetch='+$($repository.Commitish):refs/remotes/origin/$($repository.Commitish)' https://github.com/$($repository.Name) ."
git clone --no-checkout --filter=tree:0 -c remote.origin.fetch=''+$($repository.Commitish):refs/remotes/origin/$($repository.Commitish)'' https://github.com/$($repository.Name) .
Retry git clone --no-checkout --filter=tree:0 -c remote.origin.fetch=''+$($repository.Commitish):refs/remotes/origin/$($repository.Commitish)'' https://github.com/$($repository.Name) .
} else {
Write-Host "git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) ."
git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) .
Retry git clone --no-checkout --filter=tree:0 https://github.com/$($repository.Name) .
}
# Turn off git GC for sparse checkout. Note: The devops checkout task does this by default
Write-Host "git config gc.auto 0"
git config gc.auto 0
Run git config gc.auto 0
Write-Host "git sparse-checkout init"
git sparse-checkout init
Run git sparse-checkout init
# Set non-cone mode otherwise path filters will not work in git >= 2.37.0
# See https://github.blog/2022-06-27-highlights-from-git-2-37/#tidbits
Write-Host "git sparse-checkout set --no-cone '/*' '!/*/' '/eng'"
git sparse-checkout set --no-cone '/*' '!/*/' '/eng'
}
Expand All @@ -82,10 +104,8 @@ steps:
$commitish = $repository.Commitish -replace '^refs/heads/', ''
# use -- to prevent git from interpreting the commitish as a path
Write-Host "git -c advice.detachedHead=false checkout $commitish --"
# This will use the default branch if repo.Commitish is empty
git -c advice.detachedHead=false checkout $commitish --
Retry git -c advice.detachedHead=false checkout $commitish --
} else {
Write-Host "Skipping checkout as repo has already been initialized"
}
Expand Down

0 comments on commit 5d45fe6

Please sign in to comment.