Skip to content

Commit d4ef427

Browse files
committed
Add retry of finding and using Tar
1 parent ec2fed0 commit d4ef427

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

eng/scripts/InstallTar.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Set-StrictMode -Version 1
2121

2222
# Find tar. If not found, install Git to get it.
2323
$repoRoot = (Join-Path $PSScriptRoot "..\.." -Resolve)
24-
$installDir = "$repoRoot\.tools\Git\win-x64\"
24+
$installDir = "$repoRoot\.tools\Git\win-x64"
2525
$tarCommand = "$installDir\usr\bin\tar.exe"
2626

2727
if (Test-Path "$env:SystemRoot\System32\tar.exe") {
@@ -48,17 +48,16 @@ else {
4848
$Uri = "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/git/Git-${GitVersion}-64-bit.zip"
4949

5050
Import-Module -Name (Join-Path $PSScriptRoot "..\common\native\CommonLibrary.psm1" -Resolve)
51-
$InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri -InstallDirectory "$installDir" -Force:$Force -Verbose
51+
$InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri -InstallDirectory "$installDir\" -Force:$Force -Verbose
5252

5353
if ($InstallStatus -Eq $False) {
5454
Write-Error "Installation failed"
5555
exit 1
5656
}
5757
}
5858

59+
Write-Host "Tar now available at `"$tarCommand`""
60+
$env:TarCommand = "`"$tarCommand`""
5961
if ($env:TF_BUILD) {
60-
Write-Host "##vso[task.setvariable variable=TarCommand;]$tarCommand"
61-
}
62-
else {
63-
Write-Host "Tar now available at '$tarCommand'"
62+
Write-Host "##vso[task.setvariable variable=TarCommand]`"$tarCommand`""
6463
}

src/Framework/ref/Microsoft.AspNetCore.App.Ref.csproj

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ This package is an internal implementation of the .NET Core SDK and is not meant
171171
Condition="'$(IsPackable)' == 'true'">
172172
<PropertyGroup>
173173
<TarCommand Condition="'$(TarCommand)' == ''">tar</TarCommand>
174+
<_RetryCommand>PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command</_RetryCommand>
175+
<_RetryCommand>$(_RetryCommand) &quot;[System.Threading.Thread]::CurrentThread.CurrentCulture = '';</_RetryCommand>
176+
<_RetryCommand>$(_RetryCommand) [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';</_RetryCommand>
177+
<_RetryCommand>$(_RetryCommand) try { & '$(RepoRoot)\eng\scripts\InstallTar.ps1' -Verbose;</_RetryCommand>
178+
<_RetryCommand>$(_RetryCommand) & $env:TarCommand -czf $(_TarArchiveOutputPath) .;</_RetryCommand>
179+
<_RetryCommand>$(_RetryCommand) exit $LASTEXITCODE } catch { write-host $_; exit 1 }&quot;<_RetryCommand>
174180

175181
<!-- For the tar packed with git, transform e.g. "C:\root\AspNetCore\File.tar.gz" to "/C/root/AspNetCore/File.tar.gz". -->
176182
<_TarArchiveOutputPath>$(TarArchiveOutputPath)</_TarArchiveOutputPath>
@@ -184,9 +190,20 @@ This package is an internal implementation of the .NET Core SDK and is not meant
184190
Overwrite="true" />
185191

186192
<!-- Requires Windows 10 version 1803 or newer -->
187-
<Exec
188-
Command="$(TarCommand) -czf $(_TarArchiveOutputPath) ."
189-
WorkingDirectory="$(TargetingPackLayoutRoot)" />
193+
<Exec Command="$(TarCommand) -czf $(_TarArchiveOutputPath) ."
194+
WorkingDirectory="$(TargetingPackLayoutRoot)"
195+
IgnoreExitCode="true"
196+
Condition="'$(OS)' == 'Windows_NT'">
197+
<Output TaskParameter="ExitCode" PropertyName="_TarExitCode" />
198+
</Exec>
199+
<Exec Command="$(_RetryCommand)"
200+
WorkingDirectory="$(TargetingPackLayoutRoot)"
201+
Condition="'$(OS)' == 'Windows_NT' AND '$(_TarExitCode)' != '0'" />
202+
203+
<Exec Command="tar -czf $(_TarArchiveOutputPath) ."
204+
WorkingDirectory="$(TargetingPackLayoutRoot)"
205+
Condition="'$(OS)' != 'Windows_NT'" />
206+
190207
<Message Importance="High" Text="$(MSBuildProjectName) -> $(TarArchiveOutputPath)" />
191208
</Target>
192209

0 commit comments

Comments
 (0)