-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publishing: Add support for Az Modules instead of AzureRM Modules (#2362
- Loading branch information
Showing
20 changed files
with
3,994 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
param ( | ||
[string] $container = $null, # Identify the container that you want to check blank == all | ||
[string] $storeContainer = "cdn", # Identifies the destination storage account container | ||
[string] $cdnStorePath = "cdnstoragename", # Identifies the target Azure Storage account (by name) | ||
[string] $subscriptionId = $null, # Identifies the target Azure Subscription Id (if not encoded in the cdnStorePath) | ||
[string] $resourceGroup = $null, # Identifies the target Azure Subscription Resource Group (if not encoded in the cdnStorePath) | ||
[string] $sasToken = $null, # The SAS Token to use rather than using or attempting to login | ||
[string] $logPath = $null, # The location where logs should be written | ||
[switch] $showFiles = $false, # Show the individual files with details as well | ||
[switch] $inclExt = $false, # Include the extensions | ||
[switch] $activeOnly = $false, # Only show the active (deployed) versions | ||
[switch] $testOnly = $false, # Uploads to a "tst" test container on the storage account | ||
[switch] $cdn = $false # (No longer used -- kept for now for backward compatibility) | ||
) | ||
|
||
Import-Module -Force -Name "../../common/publish/Logging" | ||
Import-Module -Force -Name "../../common/publish/AzStorageHelper" | ||
|
||
[hashtable]$global:connectDetails = @{} | ||
$global:connectDetails.storeContainer = $storeContainer | ||
$global:connectDetails.cdnStorePath = $cdnStorePath | ||
$global:connectDetails.resourceGroup = $resourceGroup | ||
$global:connectDetails.storeName = $null # The endpoint needs to the base name of the endpoint, not the full URL (eg. “my-cdn” rather than “my-cdn.azureedge.net”) | ||
$global:connectDetails.subscriptionId = $subscriptionId | ||
$global:connectDetails.sasToken = $sasToken | ||
$global:connectDetails.storageContext = $null | ||
$global:connectDetails.testOnly = $testOnly | ||
|
||
Function Write-LogParams | ||
{ | ||
$logDir = Get-LogPath | ||
|
||
Write-Log "Container : $container" | ||
Write-Log "Storage Container : $storeContainer" | ||
Write-Log "Store Path : $cdnStorePath" | ||
Write-Log "Write-LogPath : $logDir" | ||
Write-Log "Show Files : $showFiles" | ||
Write-Log "Test Mode : $testOnly" | ||
|
||
if ([string]::IsNullOrWhiteSpace($global:connectDetails.sasToken) -eq $true) { | ||
Write-Log "Mode : User-Credentials" | ||
} else { | ||
Write-Log "Mode : Sas-Token" | ||
} | ||
} | ||
|
||
Function Validate-Params | ||
{ | ||
# Validate parameters | ||
if ([string]::IsNullOrWhiteSpace($container) -ne $true -and "beta","next","public", "dev", "nightly" -NotContains $container) { | ||
Write-LogFailure "[$($container)] is not a valid value, must be beta, next or public" | ||
} | ||
} | ||
|
||
Function Get-AllVersionFiles( | ||
[system.collections.generic.dictionary[string, system.collections.generic.list[hashtable]]] $files, | ||
[string] $storagePath | ||
) { | ||
Get-VersionFiles $files $storagePath "ai." $null | ||
if ($inclExt -eq $true) { | ||
Get-VersionFiles $files "$storagePath/ext" "ai.*" $null | ||
} | ||
} | ||
|
||
$Error.Clear() | ||
|
||
#----------------------------------------------------------------------------- | ||
# Start of Script | ||
#----------------------------------------------------------------------------- | ||
Set-LogPath $logPath "listCdnVersionsLog" | ||
|
||
Write-LogParams | ||
Validate-Params | ||
|
||
# Don't try and list anything if any errors have been logged | ||
if (Get-HasErrors -eq $true) { | ||
exit 2 | ||
} | ||
|
||
# You will need to at least have the Az modules installed | ||
InstallRequiredModules | ||
$global:connectDetails = ParseCdnStorePath $global:connectDetails | ||
|
||
if ([string]::IsNullOrWhiteSpace($global:connectDetails.sasToken) -eq $true) { | ||
Write-Log "**********************************************************************" | ||
Write-Log "Validating user access" | ||
Write-Log "**********************************************************************" | ||
$global:connectDetails = ValidateAccess $global:connectDetails | ||
} | ||
|
||
Write-Log "======================================================================" | ||
# List the files for each container | ||
$files = New-Object 'system.collections.generic.dictionary[string, system.collections.generic.list[hashtable]]' | ||
|
||
# Get the public files (scripts/b) | ||
if ([string]::IsNullOrWhiteSpace($container) -eq $true) { | ||
Get-AllVersionFiles $files "scripts/b" | ||
Get-AllVersionFiles $files "beta" | ||
Get-AllVersionFiles $files "next" | ||
Get-AllVersionFiles $files "dev" | ||
Get-AllVersionFiles $files "nightly" | ||
} | ||
|
||
if ([string]::IsNullOrWhiteSpace($container) -ne $true) { | ||
if ($container -eq "public") { | ||
Get-AllVersionFiles $files "scripts/b" | ||
} elseif ($container -eq "beta" -or $container -eq "next" -or $container -eq "dev" -or $container -eq "nightly") { | ||
Get-AllVersionFiles $files "$container" | ||
} else { | ||
$global:connectDetails.testOnly = $true | ||
$global:connectDetails.storeContainer = "tst" | ||
Get-AllVersionFiles $files "$container" | ||
} | ||
} | ||
|
||
ListVersions $files $activeOnly $showFiles | ||
|
||
Write-Log "======================================================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
param ( | ||
[string] $releaseFrom = $null, # The root path for where to find the files to be released | ||
[string] $storeContainer = "cdn", # Identifies the destination storage account container | ||
[string] $cdnStorePath = "cdnstoragename", # Identifies the target Azure Storage account (by name) | ||
[string] $subscriptionId = $null, # Identifies the target Azure Subscription Id (if not encoded in the cdnStorePath) | ||
[string] $resourceGroup = $null, # Identifies the target Azure Subscription Resource Group (if not encoded in the cdnStorePath) | ||
[string] $sasToken = $null, # The SAS Token to use rather than using or attempting to login | ||
[string] $logPath = $null, # The location where logs should be written | ||
[switch] $overwrite = $false, # Overwrite any existing files | ||
[switch] $testOnly = $false, # Uploads to a "tst" test container on the storage account | ||
[switch] $cdn = $false # (No longer used -- kept for now for backward compatibility) | ||
) | ||
|
||
Import-Module -Force -Name "../../common/publish/Logging" | ||
Import-Module -Force -Name "../../common/publish/AzStorageHelper" | ||
|
||
[hashtable]$global:connectDetails = @{} | ||
$global:connectDetails.storeContainer = $storeContainer | ||
$global:connectDetails.cdnStorePath = $cdnStorePath | ||
$global:connectDetails.resourceGroup = $resourceGroup | ||
$global:connectDetails.storeName = $null # The endpoint needs to the base name of the endpoint, not the full URL (eg. “my-cdn” rather than “my-cdn.azureedge.net”) | ||
$global:connectDetails.subscriptionId = $subscriptionId | ||
$global:connectDetails.sasToken = $sasToken | ||
$global:connectDetails.storageContext = $null | ||
$global:connectDetails.testOnly = $testOnly | ||
|
||
$global:cacheValue = $null | ||
|
||
Function Write-LogParams | ||
{ | ||
$logDir = Get-LogPath | ||
|
||
Write-Log "Storage Container : $storeContainer" | ||
Write-Log "Store Path : $($global:connectDetails.cdnStorePath)" | ||
Write-Log "Overwrite : $overwrite" | ||
Write-Log "Test Mode : $testOnly" | ||
Write-Log "SourcePath : $jsSdkDir" | ||
Write-Log "Log Path : $logDir" | ||
|
||
if ([string]::IsNullOrWhiteSpace($global:connectDetails.sasToken) -eq $true) { | ||
Write-Log "Mode : User-Credentials" | ||
} else { | ||
Write-Log "Mode : Sas-Token" | ||
} | ||
} | ||
|
||
Function GetReleaseFiles ( | ||
[hashtable] $verDetails | ||
) | ||
{ | ||
$version = $verDetails.full | ||
Write-Log "Version : $($verDetails.full)" | ||
Write-Log " Number : $($verDetails.ver)" | ||
Write-Log " Type : $($verDetails.type)" | ||
Write-Log " BldNum : $($verDetails.bldNum)" | ||
|
||
# check if the minified dir exists | ||
$jsSdkSrcDir = Join-Path $jssdkDir -ChildPath "browser\es5\"; | ||
|
||
if (-Not (Test-Path $jsSdkSrcDir)) { | ||
Write-LogWarning "'$jsSdkSrcDir' directory doesn't exist. Compile JSSDK first."; | ||
exit | ||
} | ||
|
||
$files = New-Object 'system.collections.generic.dictionary[string,string]' | ||
|
||
Write-Log "Adding files"; | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.integrity.json" $true | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.js" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.js.map" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.min.js" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.min.js.map" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.cjs.js" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.cjs.js.map" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.cjs.min.js" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.cjs.min.js.map" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.gbl.js" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.gbl.js.map" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.gbl.min.js" | ||
AddReleaseFile $files $jsSdkSrcDir "ai.$version.gbl.min.js.map" | ||
|
||
return $files | ||
} | ||
|
||
#----------------------------------------------------------------------------- | ||
# Start of Script | ||
#----------------------------------------------------------------------------- | ||
Set-LogPath $logPath "publishReleaseCdnLog" | ||
|
||
$jsSdkDir = $releaseFrom | ||
if ([string]::IsNullOrWhiteSpace($jsSdkDir) -eq $true) { | ||
$jsSdkDir = Split-Path (Split-Path $MyInvocation.MyCommand.Path) -Parent | ||
} | ||
|
||
$cacheControl1Year = "public, max-age=31536000, immutable, no-transform"; | ||
$contentType = "text/javascript; charset=utf-8"; | ||
|
||
Write-LogParams | ||
|
||
# You will need to at least have the Az modules installed | ||
InstallRequiredModules | ||
$global:connectDetails = ParseCdnStorePath $global:connectDetails | ||
|
||
if ([string]::IsNullOrWhiteSpace($global:connectDetails.sasToken) -eq $true) { | ||
Write-Log "**********************************************************************" | ||
Write-Log "Validating user access" | ||
Write-Log "**********************************************************************" | ||
$global:connectDetails = ValidateAccess $global:connectDetails | ||
} | ||
|
||
Write-Log "======================================================================" | ||
|
||
$version = GetPackageVersion $jsSdkDir | ||
|
||
$releaseFiles = GetReleaseFiles $version # Get the versioned files only | ||
if ($null -eq $releaseFiles -or $releaseFiles.Count -eq 0) { | ||
Write-LogFailure "Unable to find any release files" | ||
} | ||
|
||
Write-Log "Release Files : $($releaseFiles.Count)" | ||
|
||
Write-Log "----------------------------------------------------------------------" | ||
|
||
# Publish the full versioned files to all release folders | ||
if ($version.type -eq "release") { | ||
# Normal publishing deployment | ||
PublishFiles $releaseFiles "beta" $cacheControl1Year $contentType $overwrite | ||
PublishFiles $releaseFiles "next" $cacheControl1Year $contentType $overwrite | ||
PublishFiles $releaseFiles "scripts/b" $cacheControl1Year $contentType $overwrite | ||
} | ||
elseif ($version.type -eq "rc") { | ||
PublishFiles $releaseFiles "beta" $cacheControl1Year $contentType $overwrite | ||
PublishFiles $releaseFiles "next" $cacheControl1Year $contentType $overwrite | ||
} | ||
elseif ($version.type -eq "dev" -or $version.type -eq "beta") { | ||
# Publish to release type folder folder | ||
PublishFiles $releaseFiles "$($version.type)" $cacheControl1Year $contentType $overwrite | ||
} | ||
elseif ($version.type -eq "nightly" -or $version.type -eq "nightly3") { | ||
# Publish to release nightly folder folder | ||
PublishFiles $releaseFiles "nightly" $cacheControl1Year $contentType $overwrite | ||
} | ||
else { | ||
# Upload to the test container rather than the supplied one | ||
$global:connectDetails.testOnly = $true | ||
$global:connectDetails.storeContainer = "tst" | ||
PublishFiles $releaseFiles "$($version.type)" $cacheControl1Year $contentType $overwrite | ||
} | ||
|
||
Write-Log "======================================================================" |
Oops, something went wrong.