Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Test CDN publishing and activation routing
shell: pwsh
run: .\common\publish\Tests\CdnPublishing.tests.ps1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
Expand Down
4 changes: 2 additions & 2 deletions AISKU/Tests/Unit/src/applicationinsights.e2e.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,11 @@ export class ApplicationInsightsTests extends AITestClass {
useFakeFetch: false,
fakeFetchAutoRespond: false,
steps: [() => {
// Use beta endpoint to pre-test any changes before public V3 cdn
// Use next endpoint to pre-test any changes before public V3 cdn
let random = utcNow();
// Under Cors Mode, Options request will be auto-triggered
try {
fetch(`https://js.monitor.azure.com/beta/ai.3.gbl.min.js?${random}`, {
fetch(`https://js.monitor.azure.com/next/ai.3.gbl.min.js?${random}`, {
method: "GET"
}).then((res) => {
this._ctx.res = res;
Expand Down
22 changes: 15 additions & 7 deletions AISKU/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ The Scripts and examples are included below, but as a summary they are

### ./publishAzReleaseToCdn.ps1

This script has been created to automate the deployment of the CDN resources at the same time as publishing of the NPM packages. This script will publish the full version (v2.#.#) of the current build to all staging folders (beta, next and public) of the source storage account, it does NOT change the major (ai.2.min.js) or minor (ai.2.#.min.js) release versions
This script has been created to automate the deployment of the CDN resources at the same time as publishing of the NPM packages. This script will publish the full release version (v2.#.#) to next and public. Release candidates are published only to next. Dev and nightly builds retain their own folders, while alpha builds remain isolated in test storage. It does NOT change the major (ai.2.min.js) or minor (ai.2.#.min.js) release versions.

Supported version types are `release`, `rc`, `dev`, `nightly` and `alpha`. Unsupported versions fail validation before connecting to Azure. Beta release/channel options are no longer supported by publishing, activation or listing tools; existing CDN files are not deleted. The dated example output below is retained as historical output.

Offline publishing and activation regression tests can be run from the repository root with
`pwsh -NoProfile -File common\publish\Tests\CdnPublishing.tests.ps1`; they do not connect to Azure.

Roll out these changes using freshly built release artifacts. Deployment pipelines execute the
publish and activation scripts bundled in those artifacts; reusing an older artifact can still write to beta.

__Command line arguments__

Expand All @@ -42,7 +50,7 @@ __Command line arguments__
| sasToken | string | [Optional] For automated deployments, it is recommended that you pass in a pre-generated Shared Access Signature (SAS) Token to avoid the script attempting to login the user which could cause a blocking UI to be displayed. When supplied the script bypasses the automated scan / checks and will just used the identified storage account name from the `cdnStorePath` argument. If this value is not specified the script will ensure that the user is logged into azure (displaying a login UI), enumerate all of the subscription Id's for the user to find full location of the storage account identified by the `cdnStorePath` argument, once identified it will then Generate a new SAS token for the script (as long as the user has permissions) for the target subscription.
| logPath | string | [Optional] Identifies the location where the automatic log file will be written. Defaults to <systemDrive>:\Logs
| overwrite | switch | By default the script will NOT overwrite any existing Blob with the same name in each container as it sets the CacheControl period to 1yr. As such this flag is provided primarily for testing and validation purposes, passing this switch will include the "-Force" switch for the Azure RM PowerShell functions to cause any existing blob to be overwritten.
| testOnly | switch | [Optional] By default the script will upload to the production containers (beta, next and scripts), for testing this switch will effectively cause the files to be uploaded to the "tst" container with and the normal container names will instead be prepended (simulating folders) to the name. ([tst] scripts/b/ai.2.min.js)
| testOnly | switch | [Optional] By default the script will upload to the next and scripts containers, for testing this switch will effectively cause the files to be uploaded to the "tst" container with and the normal container names will instead be prepended (simulating folders) to the name. ([tst] scripts/b/ai.2.min.js)
| useConnectedAccount | switch | [Optional] By default the script will use the current logged in user to authenticate with Azure using SAS tokens, if you have disabled SAS token support for the storage account then you will need to use this switch and grant the user "Storage Blob Data Contributor" role.

#### Example Usage and output
Expand Down Expand Up @@ -107,7 +115,7 @@ PS D:\git\ApplicationInsights-JS\AISKU\scripts> .\publishAzReleaseToCdn.ps1 -cdn

### ./setAzActiveCdnVersion.ps1

This script will set the active release for the specified release folder (beta, next, public) to the requested full version (2.x.x) number. By default it will set both the major (ai.2.min.js) and minor (ai.2.x.min.js) versions to the requested full version, you can optionally only update the minor version.
This script will set the active release for the specified release folder (next, public) to the requested full version (2.x.x) number. Release candidates can only be activated in next; dev and nightly versions retain their corresponding folders. By default it will set both the major (ai.2.min.js) and minor (ai.2.x.min.js) versions to the requested full version, you can optionally only update the minor version.

> :bulb: **Note**
>
Expand All @@ -117,13 +125,13 @@ __Command line arguments__

| Name | Type | Description
|------|------|----------------
| container | string | __[Required]__ Identifies the target container to update (beta, next, public)
| container | string | __[Required]__ Identifies the target container to update (next, public, dev, nightly).
| activeVersion | string | __[Required]__ Identifies the source full version number to copy and make the active released version fro the specified container. This MUST be the full version number in the form "a.b.c". The new active versions will be created (or overwritten) as the major version (ai.[a].min.js) and minor version (ai.[a].[b].min.js).
| cdnStorePath | string | [Optional] Identifies the target Azure Storage account (by name) where the files will be uploaded to. As you may have access to multiple subscriptions, resource groups, and storage accounts (which can slow the automatic validation / identification process) you can optionally include the a partial subscription id and resource group name with the storage account name. So you can specify the target using any of the following 3 forms :-<br> - &lt;Full storage account name&gt; <br> - &lt;partial or full subscription id&gt;::&lt;Full storage account name&gt; <br> - &lt;partial or full subscription id&gt;::&lt;Full resource group name&gt;::&lt;Full storage account name&gt;<br>The subscription id is used to match against the collection of subscription id's that the user/runner has access to, it uses the PowerShell -like matching by wrapping the value in '*'<br>When a resource group name is supplied it will further limit the collection of storage accounts that are scanned / checked for the storage account name.<br>Example: `"65b2f83e::tstcdnstore"`
| sasToken | string | [Optional] For automated deployments, it is recommended that you pass in a pre-generated Shared Access Signature (SAS) Token to avoid the script attempting to login the user which could cause a blocking UI to be displayed. When supplied the script bypasses the automated scan / checks and will just used the identified storage account name from the `cdnStorePath` argument. If this value is not specified the script will ensure that the user is logged into azure (displaying a login UI), enumerate all of the subscription Id's for the user to find full location of the storage account identified by the `cdnStorePath` argument, once identified it will then Generate a new SAS token for the script (as long as the user has permissions) for the target subscription.
| logPath | string | [Optional] Identifies the location where the automatic log file will be written. Defaults to <systemDrive>:\Logs
| minorOnly | switch | By default the script will update both the major (ai.2.min.js) and minor (ai.2.#.min.js) available versions of the script. If this switch is set it will only update the minor version (ai.2.#.min.js) and the major version (ai.2.min.js) will be unaffected.
| testOnly | switch | [Optional] By default the script will update the production containers (beta, next and scripts), for testing this switch will effectively only update the "tst" container versions with and the normal container names will instead be prepended (simulating folders) to the name. ([tst] scripts/b/ai.2.min.js)
| testOnly | switch | [Optional] By default the script will update the next and scripts containers, for testing this switch will effectively only update the "tst" container versions with and the normal container names will instead be prepended (simulating folders) to the name. ([tst] scripts/b/ai.2.min.js)
| useConnectedAccount | switch | [Optional] By default the script will use the current logged in user to authenticate with Azure using SAS tokens, if you have disabled SAS token support for the storage account then you will need to use this switch and grant the user "Storage Blob Data Contributor" role.

#### Example Usage and output
Expand Down Expand Up @@ -196,12 +204,12 @@ __Command line arguments__

| Name | Type | Description
|------|------|----------------
| container | string | __[Optional]__ Identifies the single target container to list the available versions for (beta, next, public). If not specified all containers will be enumerated.
| container | string | __[Optional]__ Identifies the single target container to list the available versions for (next, public, dev, nightly). If not specified all supported containers will be enumerated.
| cdnStorePath | string | [Optional] Identifies the target Azure Storage account (by name) where the files will be uploaded to. As you may have access to multiple subscriptions, resource groups, and storage accounts (which can slow the automatic validation / identification process) you can optionally include the a partial subscription id and resource group name with the storage account name. So you can specify the target using any of the following 3 forms :-<br> - &lt;Full storage account name&gt; <br> - &lt;partial or full subscription id&gt;::&lt;Full storage account name&gt; <br> - &lt;partial or full subscription id&gt;::&lt;Full resource group name&gt;::&lt;Full storage account name&gt;<br>The subscription id is used to match against the collection of subscription id's that the user/runner has access to, it uses the PowerShell -like matching by wrapping the value in '*'<br>When a resource group name is supplied it will further limit the collection of storage accounts that are scanned / checked for the storage account name.<br>Example: `"65b2f83e::tstcdnstore"`
| sasToken | string | [Optional] For automated deployments, it is recommended that you pass in a pre-generated Shared Access Signature (SAS) Token to avoid the script attempting to login the user which could cause a blocking UI to be displayed. When supplied the script bypasses the automated scan / checks and will just used the identified storage account name from the `cdnStorePath` argument. If this value is not specified the script will ensure that the user is logged into azure (displaying a login UI), enumerate all of the subscription Id's for the user to find full location of the storage account identified by the `cdnStorePath` argument, once identified it will then Generate a new SAS token for the script (as long as the user has permissions) for the target subscription.
| logPath | string | [Optional] Identifies the location where the automatic log file will be written. Defaults to <systemDrive>:\Logs
| showFiles | switch | [Optional] Identifies whether the details of each located blob should be listed, this includes the CacheControl and metadata for each file
| testOnly | switch | [Optional] By default the script will update the production containers (beta, next and scripts), for testing this switch will effectively only update the "tst" container versions with and the normal container names will instead be prepended (simulating folders) to the name. ([tst] scripts/b/ai.2.min.js)
| testOnly | switch | [Optional] Lists the versions in the "tst" container instead of the normal next and scripts containers, using the normal container names as prefixes.
| useConnectedAccount | switch | [Optional] By default the script will use the current logged in user to authenticate with Azure using SAS tokens, if you have disabled SAS token support for the storage account then you will need to use this switch and grant the user "Storage Blob Data Contributor" role.

#### Example Usages and output
Expand Down
7 changes: 3 additions & 4 deletions AISKU/scripts/listAzCdnVersions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Function Write-LogParams
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"
if ([string]::IsNullOrWhiteSpace($container) -ne $true -and "next","public", "dev", "nightly" -NotContains $container) {
Write-LogFailure "[$($container)] is not a valid value, must be next, public, dev or nightly"
}
}

Expand Down Expand Up @@ -98,7 +98,6 @@ $files = New-Object 'system.collections.generic.dictionary[string, system.collec
# 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"
Expand All @@ -107,7 +106,7 @@ if ([string]::IsNullOrWhiteSpace($container) -eq $true) {
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") {
} elseif ($container -eq "next" -or $container -eq "dev" -or $container -eq "nightly") {
Get-AllVersionFiles $files "$container"
} else {
$global:connectDetails.testOnly = $true
Expand Down
14 changes: 8 additions & 6 deletions AISKU/scripts/publishAzReleaseToCdn.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ $contentType = "text/javascript; charset=utf-8";

Write-LogParams

$version = GetPackageVersion $jsSdkDir
if ("release","rc","dev","nightly","alpha" -NotContains $version.type) {
Write-LogFailure "Version type [$($version.type)] is not supported"
exit 2
}

# You will need to at least have the Az modules installed
InstallRequiredModules
$global:connectDetails = ParseCdnStorePath $global:connectDetails
Expand All @@ -113,8 +119,6 @@ if ([string]::IsNullOrWhiteSpace($global:connectDetails.sasToken) -eq $true) {

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"
Expand All @@ -127,19 +131,17 @@ 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") {
elseif ($version.type -eq "dev") {
# Publish to release type folder folder
PublishFiles $releaseFiles "$($version.type)" $cacheControl1Year $contentType $overwrite
}
elseif ($version.type -like "nightly*") {
elseif ($version.type -eq "nightly") {
# Publish to release nightly folder folder
PublishFiles $releaseFiles "nightly" $cacheControl1Year $contentType $overwrite
}
Expand Down
14 changes: 7 additions & 7 deletions AISKU/scripts/setAzActiveCdnVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Function Validate-Params

$version = Get-VersionDetails $activeVersion

if ([string]::IsNullOrWhiteSpace($version.type) -eq $true) {
Write-LogFailure "Unknown release type"
if ("release","rc","dev","nightly","alpha" -NotContains $version.type) {
Write-LogFailure "Version type [$($version.type)] is not supported"
}

$versionParts = $version.ver.Split(".")
Expand All @@ -73,21 +73,21 @@ Function Validate-Params
# Publish the full versioned files to all release folders
if ($version.type -eq "release") {
# Normal publishing deployment
if ("beta","next","public" -NotContains $container) {
if ("next","public" -NotContains $container) {
Write-LogFailure "Container [$container] is not valid for version type [$($version.type)]"
}
}
elseif ($version.type -eq "rc") {
if ("beta","next" -NotContains $container) {
if ($container -ne "next") {
Write-LogFailure "Container [$container] is not valid for version type [$($version.type)]"
}
}
elseif ($version.type -eq "dev" -or $version.type -eq "beta") {
elseif ($version.type -eq "dev") {
if ($version.type -ne $container) {
Write-LogFailure "Container [$container] is not valid for version type [$($version.type)]"
}
}
elseif ($version.type -like "nightly*") {
elseif ($version.type -eq "nightly") {
if ("nightly" -ne $container) {
Write-LogFailure "Container [$container] is not valid for version type [$($version.type)]"
}
Expand Down Expand Up @@ -138,7 +138,7 @@ $files = New-Object 'system.collections.generic.dictionary[string, system.collec
$storePath = "$container"
if ($container -eq "public") {
$storePath = "scripts/b"
} elseif ($container -ne "beta" -and $container -ne "next" -and $container -ne "dev" -and $container -ne "nightly") {
} elseif ($container -ne "next" -and $container -ne "dev" -and $container -ne "nightly") {
$global:connectDetails.testOnly = $true
$global:connectDetails.storeContainer = "tst"
}
Expand Down
Loading
Loading