-
Notifications
You must be signed in to change notification settings - Fork 166
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
rewrite the script using sparse checkout #3392
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,89 @@ | |
$ErrorActionPreference = 'Stop' | ||
$ProgressPreference = 'SilentlyContinue' | ||
|
||
function DownloadAll([string[]]$files, [string]$baseUrl, [string]$downloadPath) | ||
{ | ||
foreach ($file in $files) | ||
{ | ||
Write-Host "Downloading" $file | ||
$text = (Invoke-WebRequest -Uri "$baseUrl/$file").Content | ||
$text.Trim() | Out-File (Join-Path $downloadPath $file) | ||
$sparseCheckoutFile = ".git/info/sparse-checkout" | ||
$gitRemoteUrl = "https://github.com/Azure/azure-sdk-for-net.git" | ||
$gitRemoteBranchName = "main" | ||
$azCoreSharedPath = "sdk/core/Azure.Core/src/Shared/" | ||
$armCoreSharedPath = "sdk/resourcemanager/Azure.ResourceManager/src/Shared/" | ||
|
||
function InitializeSparseGitClone([string]$repo) { | ||
git clone --no-checkout --filter=tree:0 $repo . | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
git sparse-checkout init | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
Remove-Item $sparseCheckoutFile -Force | ||
} | ||
|
||
function AddSparseCheckoutPath([string]$subDirectory) { | ||
if (!(Test-Path $sparseCheckoutFile) -or !((Get-Content $sparseCheckoutFile).Contains($subDirectory))) { | ||
Write-Output $subDirectory >> $sparseCheckoutFile | ||
} | ||
} | ||
|
||
function GetSDKCloneDir() { | ||
$root = git rev-parse --show-toplevel | ||
|
||
$sparseSpecCloneDir = "$root/sdk" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use a place out of this repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes lets put this somewhere not inside the existing repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be run in 2 pipelines where the current repo is one of several in the agent work folder and possibly on dev machines. I wouldn't write outside of the repo on dev machines unless we take the location as a parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend we put it in a gitignored folder within the repo. I think under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This sound reasonable. |
||
New-Item $sparseSpecCloneDir -Type Directory -Force | Out-Null | ||
$createResult = Resolve-Path $sparseSpecCloneDir | ||
return $createResult | ||
} | ||
|
||
$sdkCloneDir = GetSDKCloneDir | ||
Write-Host "Setting up sparse clone for $gitRemoteUrl at $sdkCloneDir" | ||
|
||
Push-Location $sdkCloneDir.Path | ||
try { | ||
if (!(Test-Path ".git")) { | ||
Write-Host "Initializing sparse clone for $gitRemoteUrl" | ||
InitializeSparseGitClone $gitRemoteUrl | ||
AddSparseCheckoutPath $azCoreSharedPath | ||
AddSparseCheckoutPath $armCoreSharedPath | ||
$commitHash = git rev-parse $gitRemoteBranchName | ||
git checkout $commitHash | ||
} | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
} | ||
finally { | ||
Pop-Location | ||
} | ||
|
||
function CopyFilesToDestination([string]$sdkCloneRoot, [string]$dirName, [string]$dest, [string[]]$files) { | ||
$source = Join-Path $sdkCloneRoot $dirName | ||
foreach ($file in $files) { | ||
$sourceFile = Join-Path $source $file | ||
$destFile = Join-Path $dest $file | ||
# to avoid the format issues (the file is required to end by a newline) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this issue. If the newlines don't match then we should fix this in the .NET repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed this in the .NET repo: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no standard encoding or trailing new-line rule in the .NET repo but this repo's build enforces trailing new lines. We should either relax that rule here or start enforcing the rule for shared code in azure-sdk-for-net There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then let me change it back so that those unwanted changes will disappear as well. |
||
# here we read all the content in the source file, and then output it into the destination file | ||
Write-Host "Copying $file" | ||
$text = Get-Content -Path $sourceFile | ||
$text | Out-File -FilePath $destFile | ||
} | ||
} | ||
|
||
$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 | ||
|
||
#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 | ||
try { | ||
Write-Host "Downloading Azure.Core.Shared" | ||
$downloadPath = Resolve-Path (Join-Path $PSScriptRoot '..' 'src' 'assets' 'Azure.Core.Shared') | ||
Write-Host "Removing the existing files in " $downloadPath | ||
Get-ChildItem $downloadPath -Filter *.cs | Remove-Item; | ||
$files = @('AsyncLockWithValue.cs', 'ClientDiagnostics.cs', 'DiagnosticScope.cs', 'DiagnosticScopeFactory.cs', 'ContentTypeUtilities.cs', 'HttpMessageSanitizer.cs', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I this every file in the directory? Ideally we would sync the entire directory and not have to maintain this list of files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. This is a subset we need. We only included things we need. |
||
'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') | ||
|
||
CopyFilesToDestination $sdkCloneDir $azCoreSharedPath $downloadPath $files | ||
|
||
Write-Host "Downloading management Shared" | ||
$downloadPath = Resolve-Path (Join-Path $PSScriptRoot '..' 'src' 'assets' 'Management.Shared') | ||
Write-Host "Removing the existing files in " $downloadPath | ||
Get-ChildItem $downloadPath -Filter *.cs | Remove-Item; | ||
$files = 'SharedExtensions.cs', 'ManagedServiceIdentityTypeV3Converter.cs' | ||
|
||
CopyFilesToDestination $sdkCloneDir $armCoreSharedPath $downloadPath $files | ||
} | ||
finally { | ||
Write-Host "Removing the sparse checkout files in" $sdkCloneDir | ||
Remove-Item $sdkCloneDir -Force -Recurse | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know why there is this difference (I did not even see what this difference is), but if we keep this script, and we do not need to care about this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you set core.autocrlf to false so that the eol difference between your file and azure.core file shows up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's please revert all of these. I'm not sure what the change is, but I don't think we intended to make it. |
||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you copied this from another script but I think you can simplify this to something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want to download outside of the repo root? Also, we should delete the folder if it exists and maybe clean up when we're done:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with putting it under a gitignored directory as well.