|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Deploys a build to an Azure blob store |
| 4 | +
|
| 5 | +.PARAMETER AccountName |
| 6 | +The account name for the Azure account |
| 7 | +
|
| 8 | +.PARAMETER AccountKey |
| 9 | +The account key for the Azure account |
| 10 | +
|
| 11 | +.PARAMETER BuildNumber |
| 12 | +The build number of the current build |
| 13 | +
|
| 14 | +.PARAMETER BaseFeedUrl |
| 15 | +The base URI of the package feed (may be different than blobBaseUrl for private-only blobs) |
| 16 | +
|
| 17 | +.PARAMETER ContainerName |
| 18 | +The container name. Defaults to 'dotnet' |
| 19 | +
|
| 20 | +.PARAMETER ArtifactsPath |
| 21 | +The path to the build outputs |
| 22 | +#> |
| 23 | +[CmdletBinding(SupportsShouldProcess = $true)] |
| 24 | +param( |
| 25 | + [Parameter(Mandatory = $true)] |
| 26 | + $AccountName, |
| 27 | + [Parameter(Mandatory = $true)] |
| 28 | + $AccountKey, |
| 29 | + [Parameter(Mandatory = $true)] |
| 30 | + $BuildNumber, |
| 31 | + [Parameter(Mandatory = $true)] |
| 32 | + $ArtifactsPath, |
| 33 | + $BaseBlobFeedUrl, |
| 34 | + $ContainerName = 'dotnet' |
| 35 | +) |
| 36 | + |
| 37 | +$ErrorActionPreference = 'Stop' |
| 38 | +Set-StrictMode -Version 1 |
| 39 | + |
| 40 | +Import-Module -Scope Local "$PSScriptRoot/common.psm1" |
| 41 | + |
| 42 | +if (!(Get-Command 'az' -ErrorAction Ignore)) { |
| 43 | + Write-Error 'Missing required command: az. Please install the Azure CLI and ensure it is available on PATH.' |
| 44 | +} |
| 45 | + |
| 46 | +$repoRoot = Resolve-Path "$PSScriptRoot/.." |
| 47 | + |
| 48 | +$sleetVersion = '2.3.25' |
| 49 | +$sleet = "$repoRoot/.tools/sleet.$sleetVersion/tools/sleet.exe" |
| 50 | + |
| 51 | +if (-not (Test-Path $sleet)) { |
| 52 | + mkdir "$repoRoot/.tools/sleet.$sleetVersion" -ErrorAction Ignore | Out-Null |
| 53 | + $installScriptPath = "$repoRoot/.dotnet/dotnet-install.ps1" |
| 54 | + Invoke-WebRequest -UseBasicParsing -OutFile "$repoRoot/.tools/sleet.$sleetVersion.zip" https://www.nuget.org/api/v2/package/Sleet/$sleetVersion |
| 55 | + Expand-Archive "$repoRoot/.tools/sleet.$sleetVersion.zip" -DestinationPath "$repoRoot/.tools/sleet.$sleetVersion" |
| 56 | +} |
| 57 | + |
| 58 | +[xml] $versionProps = Get-Content "$repoRoot/version.props" |
| 59 | +$props = $versionProps.Project.PropertyGroup |
| 60 | +$VersionPrefix = "$($props.AspNetCoreMajorVersion).$($props.AspNetCoreMinorVersion).$($props.AspNetCorePatchVersion)" |
| 61 | + |
| 62 | +$blobFolder = "$ContainerName/aspnetcore/store/$VersionPrefix-$BuildNumber" |
| 63 | +$packagesFolder = "$blobFolder/packages/" |
| 64 | + |
| 65 | +$blobBaseUrl = "https://$AccountName.blob.core.windows.net/$blobFolder" |
| 66 | +$packageBlobUrl = "https://$AccountName.blob.core.windows.net/$packagesFolder" |
| 67 | + |
| 68 | +if (-not $BaseBlobFeedUrl) { |
| 69 | + $BaseBlobFeedUrl = "https://$AccountName.blob.core.windows.net/$packagesFolder" |
| 70 | +} |
| 71 | +else { |
| 72 | + $BaseBlobFeedUrl = "$BaseBlobFeedUrl/$packagesFolder" |
| 73 | +} |
| 74 | + |
| 75 | +$packageGlobPath = "$ArtifactsPath/packages/**/*.nupkg" |
| 76 | +$globs = ( |
| 77 | + @{ |
| 78 | + basePath = "$ArtifactsPath/lzma" |
| 79 | + pattern = "*" |
| 80 | + destination = $blobFolder |
| 81 | + }, |
| 82 | + @{ |
| 83 | + basePath = "$ArtifactsPath/installers" |
| 84 | + pattern = "*" |
| 85 | + destination = $blobFolder |
| 86 | + }) |
| 87 | + |
| 88 | +$sleetConfigObj = @{ |
| 89 | + sources = @( |
| 90 | + @{ |
| 91 | + name = "feed" |
| 92 | + type = "azure" |
| 93 | + path = $packageBlobUrl |
| 94 | + baseURI = $BaseBlobFeedUrl |
| 95 | + container = $ContainerName |
| 96 | + connectionString = "DefaultEndpointsProtocol=https;AccountName=$AccountName;AccountKey=$AccountKey" |
| 97 | + }) |
| 98 | +} |
| 99 | + |
| 100 | +$sleetConfig = "$repoRoot/.tools/sleet.json" |
| 101 | +$sleetConfigObj | ConvertTo-Json | Set-Content -Path $sleetConfig -Encoding Ascii |
| 102 | +if ($PSCmdlet.ShouldProcess("Initialize remote feed in $packageBlobUrl")) { |
| 103 | + Invoke-Block { & $sleet init --config $sleetConfig --verbose } |
| 104 | +} |
| 105 | + |
| 106 | +Get-ChildItem -Recurse $packageGlobPath ` |
| 107 | + | split-path -parent ` |
| 108 | + | select -Unique ` |
| 109 | + | % { |
| 110 | + if ($PSCmdlet.ShouldProcess("Push packages in $_ to $packageBlobUrl")) { |
| 111 | + Invoke-Block { & $sleet push --verbose --config $sleetConfig --source feed --force $_ } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +[string[]] $otherArgs = @() |
| 116 | + |
| 117 | +if ($VerbosePreference) { |
| 118 | + $otherArgs += '--verbose' |
| 119 | +} |
| 120 | + |
| 121 | +if ($WhatIfPreference) { |
| 122 | + $otherArgs += '--dryrun' |
| 123 | +} |
| 124 | + |
| 125 | +$globs | ForEach-Object { |
| 126 | + $pattern = $_.pattern |
| 127 | + $basePath = $_.basePath |
| 128 | + $destination = $_.destination |
| 129 | + if (!(Get-ChildItem -Recurse "$basePath/$pattern" -ErrorAction Ignore)) { |
| 130 | + Write-Warning "Expected files in $basePath/$pattern but found none" |
| 131 | + } |
| 132 | + |
| 133 | + Invoke-Block { & az storage blob upload-batch ` |
| 134 | + --account-name $AccountName ` |
| 135 | + --account-key $AccountKey ` |
| 136 | + --verbose ` |
| 137 | + --pattern $pattern ` |
| 138 | + --destination $destination.TrimEnd('/') ` |
| 139 | + --source $basePath ` |
| 140 | + --no-progress ` |
| 141 | + @otherArgs |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +Write-Host -f green "Done!" |
0 commit comments