Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git clone instead of http download for shared files #3396

Merged
merged 5 commits into from
May 17, 2023
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
50 changes: 38 additions & 12 deletions eng/DownloadSharedSource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,55 @@
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

function DownloadAll([string[]]$files, [string]$baseUrl, [string]$downloadPath)
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..')
$clonedPath = Join-Path $repoRoot 'artifacts/azure-sdk-for-net-shared'
$azCoreSharedPath = "sdk/core/Azure.Core/src/Shared/"
$armCoreSharedPath = "sdk/resourcemanager/Azure.ResourceManager/src/Shared/"

if(Test-Path $clonedPath)
{
Remove-Item $clonedPath -Recurse -Force
}

Write-Host "git clone --no-checkout --filter=tree:0 https://github.com/Azure/azure-sdk-for-net.git $clonedPath"
git clone --no-checkout --filter=tree:0 https://github.com/Azure/azure-sdk-for-net.git $clonedPath
Push-Location $clonedPath
Write-Host "git sparse-checkout init"
git sparse-checkout init
Write-Host "git sparse-checkout set --no-cone $azCoreSharedPath $armCoreSharedPath"
git sparse-checkout set --no-cone $azCoreSharedPath $armCoreSharedPath
Write-Host "git checkout"
git checkout
Pop-Location

function CopyAll([string[]]$files, [string]$source, [string]$destination)
{
foreach ($file in $files)
{
Write-Host "Downloading" $file
$text = (Invoke-WebRequest -Uri "$baseUrl/$file").Content
$text.Trim() | Out-File (Join-Path $downloadPath $file)
Write-Host "Copying $file to $destination"
Copy-Item (Join-Path $source $file) (Join-Path $destination $file)
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
}
}

$downloadPath = Resolve-Path (Join-Path $PSScriptRoot '..' 'src' 'assets' 'Azure.Core.Shared')
Get-ChildItem $downloadPath -Filter *.cs | Remove-Item;
$files = @('AsyncLockWithValue.cs', 'ClientDiagnostics.cs', 'DiagnosticScope.cs', 'DiagnosticScopeFactory.cs', 'ContentTypeUtilities.cs', 'HttpMessageSanitizer.cs',
'OperationInternalBase.cs', 'OperationInternal.cs', 'OperationInternalOfT.cs', 'TaskExtensions.cs', 'Argument.cs', 'Multipart/MultipartFormDataContent.cs',
'Multipart/MultipartContent.cs', 'AzureKeyCredentialPolicy.cs', 'AppContextSwitchHelper.cs',
'OperationPoller.cs', 'FixedDelayWithNoJitterStrategy.cs', 'SequentialDelayStrategy.cs',
'ForwardsClientCallsAttribute.cs', 'AsyncLockWithValue.cs', 'VoidValue.cs')
$baseUrl = 'https://raw.githubusercontent.com/Azure/azure-sdk-for-net/main/sdk/core/Azure.Core/src/Shared/'
DownloadAll $files $baseUrl $downloadPath
$sourcePath = "$clonedPath/sdk/core/Azure.Core/src/Shared/"
$destinationPath = "$repoRoot/src/assets/Azure.Core.Shared"

Get-ChildItem $destinationPath -Filter *.cs | Remove-Item;
CopyAll $files $sourcePath $destinationPath

#Download management Shared
$files = 'SharedExtensions.cs', 'ManagedServiceIdentityTypeV3Converter.cs'
$downloadPath = Resolve-Path (Join-Path $PSScriptRoot '..' 'src' 'assets' 'Management.Shared')
Get-ChildItem $downloadPath -Filter *.cs | Remove-Item;
$baseUrl = 'https://raw.githubusercontent.com/Azure/azure-sdk-for-net/main/sdk/resourcemanager/Azure.ResourceManager/src/Shared/'
DownloadAll $files $baseUrl $downloadPath
$sourcePath = "$clonedPath/sdk/resourcemanager/Azure.ResourceManager/src/Shared"
$destinationPath = "$repoRoot/src/assets/Management.Shared"

Get-ChildItem $destinationPath -Filter *.cs | Remove-Item;
CopyAll $files $sourcePath $destinationPath

# Waiting before deleting the cloned repo to avoid file locking issues
Start-Sleep -Seconds 1
hallipr marked this conversation as resolved.
Show resolved Hide resolved
Remove-Item $clonedPath -Recurse -Force -ErrorAction SilentlyContinue
7 changes: 3 additions & 4 deletions eng/SharedCodeCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 1

#uncomment when this is fixed https://github.com/Azure/autorest.csharp/pull/3392
#Write-Host 'Downloading shared source files...'
#& (Join-Path $PSScriptRoot 'DownloadSharedSource.ps1')
#Write-Host 'Shared source files are downloaded'
Write-Host 'Downloading shared source files...'
& (Join-Path $PSScriptRoot 'DownloadSharedSource.ps1')
Write-Host 'Shared source files are downloaded'

Write-Host 'Checking file difference...'
git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code
Expand Down