diff --git a/BuildPipeline.ps1 b/BuildPipeline.ps1 new file mode 100644 index 000000000..e69de29bb diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..6f401c616 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,36 @@ +# Python package +# Create and test a Python package on multiple Python versions. +# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/python + +trigger: +- master + +pool: + vmImage: ubuntu-latest +strategy: + matrix: + Python27: + python.version: '2.7' + Python35: + python.version: '3.5' + Python36: + python.version: '3.6' + Python37: + python.version: '3.7' + +steps: +- task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + displayName: 'Use Python $(python.version)' + +- script: | + python -m pip install --upgrade pip + pip install -r requirements.txt + displayName: 'Install dependencies' + +- script: | + pip install pytest pytest-azurepipelines + pytest + displayName: 'pytest' diff --git a/scripts/Cleanup.ps1 b/scripts/Cleanup.ps1 new file mode 100644 index 000000000..eb55ddcff --- /dev/null +++ b/scripts/Cleanup.ps1 @@ -0,0 +1,47 @@ +Param( + [Parameter(Mandatory=$false)] + [ValidateSet('Local', 'AzureDevOps', 'GithubActions', 'GitLab')] + [string] $environment = 'Local' +) + +. (Join-Path $PSScriptRoot "Read-Settings.ps1") -environment $environment +. (Join-Path $PSScriptRoot "Install-BcContainerHelper.ps1") -bcContainerHelperVersion $bcContainerHelperVersion + +$refreshToken = "$($ENV:BcSaasRefreshToken)" +$environmentName = "$($ENV:EnvironmentName)" + +if ($refreshToken -and $environmentName) { + $authContext = New-BcAuthContext -refreshToken $refreshToken + if (Get-BcEnvironments -bcAuthContext $authContext | Where-Object { $_.Name -eq $environmentName -and $_.type -eq "Sandbox" }) { + Remove-BcEnvironment -bcAuthContext $authContext -environment $environmentName + } +} + +if ("$AgentName" -ne "Hosted Agent" -and "$AgentName" -notlike "Azure Pipelines*") { + $cleanupMutexName = "Cleanup" + $cleanupMutex = New-Object System.Threading.Mutex($false, $cleanupMutexName) + try { + try { + if (!$cleanupMutex.WaitOne(1000)) { + Write-Host "Waiting for other process to finish cleanup" + $cleanupMutex.WaitOne() | Out-Null + Write-Host "Other process completed" + } + } + catch [System.Threading.AbandonedMutexException] { + Write-Host "Other process terminated abnormally" + } + + Remove-BcContainer -containerName $containerName + Flush-ContainerHelperCache -KeepDays 2 + + Remove-Module BcContainerHelper + $path = Join-Path $ENV:Temp $containerName + if (Test-Path $path) { + Remove-Item $path -Recurse -Force + } + } + finally { + $cleanupMutex.ReleaseMutex() + } +} diff --git a/scripts/Cloud-DevEnv.ps1 b/scripts/Cloud-DevEnv.ps1 new file mode 100644 index 000000000..336ca3fda --- /dev/null +++ b/scripts/Cloud-DevEnv.ps1 @@ -0,0 +1,95 @@ +Param( + [Parameter(Mandatory=$false)] + [string] $version = "cloud", + [Parameter(Mandatory=$true)] + [string] $environmentName, + [switch] $reuseEnvironment +) + +$baseFolder = (Get-Item (Join-Path $PSScriptRoot "..")).FullName +. (Join-Path $PSScriptRoot "Read-Settings.ps1") -environment 'Local' -version $version +. (Join-Path $PSScriptRoot "Install-BcContainerHelper.ps1") -bcContainerHelperVersion $bcContainerHelperVersion -genericImageName $genericImageName + +if (("$vaultNameForLocal" -eq "") -or !(Get-AzKeyVault -VaultName $vaultNameForLocal)) { + throw "You need to setup a Key Vault for use with local pipelines" +} +Get-AzKeyVaultSecret -VaultName $vaultNameForLocal | ForEach-Object { + Write-Host "Get Secret $($_.Name)Secret" + Set-Variable -Name "$($_.Name)Secret" -Value (Get-AzKeyVaultSecret -VaultName $vaultNameForLocal -Name $_.Name -WarningAction SilentlyContinue) +} +$licenseFile = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($licenseFileSecret.SecretValue)) +$insiderSasToken = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($insiderSasTokenSecret.SecretValue)) +$credential = New-Object pscredential 'admin', $passwordSecret.SecretValue +$refreshToken = $BcSaasRefreshTokenSecret.SecretValue | Get-PlainText +$authContext = $null + +if ($refreshToken -and $environmentName) { + $authContext = New-BcAuthContext -refreshToken $refreshToken + $existingEnvironment = Get-BcEnvironments -bcAuthContext $authContext | Where-Object { $_.Name -eq $environmentName } + if ($existingEnvironment) { + if ($existingEnvironment.type -ne "Sandbox") { + throw "Environment $environmentName already exists and it is not a sandbox environment" + } + if (!$reuseEnvironment) { + Remove-BcEnvironment -bcAuthContext $authContext -environment $environmentName + $existingEnvironment = $null + } + } + if ($existingEnvironment) { + $countryCode = $existingEnvironment.CountryCode.ToLowerInvariant() + $baseApp = Get-BcPublishedApps -bcAuthContext $authContext -environment $environmentName | Where-Object { $_.Name -eq "Base Application" } + } + else { + $countryCode = $artifact.Split('/')[3] + New-BcEnvironment -bcAuthContext $authContext -environment $environmentName -countryCode $countrycode -environmentType "Sandbox" | Out-Null + do { + Start-Sleep -Seconds 10 + $baseApp = Get-BcPublishedApps -bcAuthContext $authContext -environment $environmentName | Where-Object { $_.Name -eq "Base Application" } + } while (!($baseApp)) + $baseapp | Out-Host + } + + $artifact = Get-BCArtifactUrl ` + -country $countryCode ` + -version $baseApp.Version ` + -select Closest + + if ($artifact) { + Write-Host "Using Artifacts: $artifact" + } + else { + throw "No artifacts available" + } +} + +$allTestResults = "testresults*.xml" +$testResultsFile = Join-Path $baseFolder "TestResults.xml" +$testResultsFiles = Join-Path $baseFolder $allTestResults +if (Test-Path $testResultsFiles) { + Remove-Item $testResultsFiles -Force +} + +Run-AlPipeline ` + -pipelineName $pipelineName ` + -containerName $containerName ` + -imageName $imageName ` + -bcAuthContext $authContext ` + -environment $environmentName ` + -artifact $artifact.replace('{INSIDERSASTOKEN}',$insiderSasToken) ` + -memoryLimit $memoryLimit ` + -baseFolder $baseFolder ` + -licenseFile $licenseFile ` + -installApps $installApps ` + -installTestApps $installTestApps ` + -appFolders $appFolders ` + -testFolders $testFolders ` + -testResultsFile $testResultsFile ` + -testResultsFormat 'JUnit' ` + -installTestRunner:$installTestRunner ` + -installTestFramework:$installTestFramework ` + -installTestLibraries:$installTestLibraries ` + -installPerformanceToolkit:$installPerformanceToolkit ` + -credential $credential ` + -doNotRunTests ` + -useDevEndpoint ` + -updateLaunchJson "Cloud Sandbox" ` diff --git a/scripts/DevOps-Pipeline.ps1 b/scripts/DevOps-Pipeline.ps1 new file mode 100644 index 000000000..17afeacd8 --- /dev/null +++ b/scripts/DevOps-Pipeline.ps1 @@ -0,0 +1,118 @@ +Param( + [Parameter(Mandatory=$false)] + [ValidateSet('AzureDevOps','GithubActions','GitLab')] + [string] $environment = 'AzureDevOps', + [Parameter(Mandatory=$true)] + [string] $version, + [Parameter(Mandatory=$false)] + [int] $appBuild = 0, + [Parameter(Mandatory=$false)] + [int] $appRevision = 0 +) + +if ($environment -eq "AzureDevOps") { + $buildArtifactFolder = $ENV:BUILD_ARTIFACTSTAGINGDIRECTORY +} +elseif ($environment -eq "GitHubActions") { + $buildArtifactFolder = Join-Path $ENV:GITHUB_WORKSPACE "output" + New-Item $buildArtifactFolder -ItemType Directory | Out-Null +} + +$baseFolder = (Get-Item (Join-Path $PSScriptRoot "..")).FullName +. (Join-Path $PSScriptRoot "Read-Settings.ps1") -environment $environment -version $version +. (Join-Path $PSScriptRoot "Install-BcContainerHelper.ps1") -bcContainerHelperVersion $bcContainerHelperVersion -genericImageName $genericImageName + +$authContext = $null +$refreshToken = "$($ENV:BcSaasRefreshToken)" +$environmentName = "$($ENV:EnvironmentName)" +if ($refreshToken -and $environmentName) { + $authContext = New-BcAuthContext -refreshToken $refreshToken + if (Get-BcEnvironments -bcAuthContext $authContext | Where-Object { $_.Name -eq $environmentName -and $_.type -eq "Sandbox" }) { + Remove-BcEnvironment -bcAuthContext $authContext -environment $environmentName + } + $countryCode = $artifact.Split('/')[3] + New-BcEnvironment -bcAuthContext $authContext -environment $environmentName -countryCode $countrycode -environmentType "Sandbox" | Out-Null + do { + Start-Sleep -Seconds 10 + $baseApp = Get-BcPublishedApps -bcAuthContext $authContext -environment $environmentName | Where-Object { $_.Name -eq "Base Application" } + } while (!($baseApp)) + $baseapp | Out-Host + + $artifact = Get-BCArtifactUrl ` + -country $countryCode ` + -version $baseApp.Version ` + -select Closest + + if ($artifact) { + Write-Host "Using Artifacts: $artifact" + } + else { + throw "No artifacts available" + } +} + +$params = @{} +$insiderSasToken = "$ENV:insiderSasToken" +$licenseFile = "$ENV:licenseFile" +$codeSigncertPfxFile = "$ENV:CodeSignCertPfxFile" +if (!$doNotSignApps -and $codeSigncertPfxFile) { + if ("$ENV:CodeSignCertPfxPassword" -ne "") { + $codeSignCertPfxPassword = try { "$ENV:CodeSignCertPfxPassword" | ConvertTo-SecureString } catch { ConvertTo-SecureString -String "$ENV:CodeSignCertPfxPassword" -AsPlainText -Force } + $params = @{ + "codeSignCertPfxFile" = $codeSignCertPfxFile + "codeSignCertPfxPassword" = $codeSignCertPfxPassword + } + } + else { + $codeSignCertPfxPassword = $null + } +} + +$allTestResults = "testresults*.xml" +$testResultsFile = Join-Path $baseFolder "TestResults.xml" +$testResultsFiles = Join-Path $baseFolder $allTestResults +if (Test-Path $testResultsFiles) { + Remove-Item $testResultsFiles -Force +} + +Run-AlPipeline @params ` + -pipelinename $pipelineName ` + -containerName $containerName ` + -imageName $imageName ` + -bcAuthContext $authContext ` + -environment $environmentName ` + -artifact $artifact.replace('{INSIDERSASTOKEN}',$insiderSasToken) ` + -memoryLimit $memoryLimit ` + -baseFolder $baseFolder ` + -licenseFile $LicenseFile ` + -installApps $installApps ` + -installTestApps $installTestApps ` + -previousApps $previousApps ` + -appFolders $appFolders ` + -testFolders $testFolders ` + -doNotRunTests:$doNotRunTests ` + -testResultsFile $testResultsFile ` + -testResultsFormat 'JUnit' ` + -installTestRunner:$installTestRunner ` + -installTestFramework:$installTestFramework ` + -installTestLibraries:$installTestLibraries ` + -installPerformanceToolkit:$installPerformanceToolkit ` + -enableCodeCop:$enableCodeCop ` + -enableAppSourceCop:$enableAppSourceCop ` + -enablePerTenantExtensionCop:$enablePerTenantExtensionCop ` + -enableUICop:$enableUICop ` + -azureDevOps:($environment -eq 'AzureDevOps') ` + -gitLab:($environment -eq 'GitLab') ` + -gitHubActions:($environment -eq 'GitHubActions') ` + -failOn 'error' ` + -AppSourceCopMandatoryAffixes $appSourceCopMandatoryAffixes ` + -AppSourceCopSupportedCountries $appSourceCopSupportedCountries ` + -additionalCountries $additionalCountries ` + -buildArtifactFolder $buildArtifactFolder ` + -CreateRuntimePackages:$CreateRuntimePackages ` + -appBuild $appBuild -appRevision $appRevision + +if ($environment -eq 'AzureDevOps') { + Write-Host "##vso[task.setvariable variable=TestResults]$allTestResults" +} + diff --git a/scripts/Install-BcContainerHelper.ps1 b/scripts/Install-BcContainerHelper.ps1 new file mode 100644 index 000000000..8fb5d3eff --- /dev/null +++ b/scripts/Install-BcContainerHelper.ps1 @@ -0,0 +1,57 @@ +Param( + [string] $bcContainerHelperVersion = "", + [string] $genericImageName = "" +) + +if ($bcContainerHelperVersion -eq "") { $bcContainerHelperVersion = "latest" } +if ($bccontainerHelperVersion -eq "dev") { $bccontainerHelperVersion = "https://github.com/microsoft/navcontainerhelper/archive/dev.zip" } + +if ((Test-Path $bcContainerHelperVersion) -and (Test-Path (Join-Path $bcContainerHelperVersion "bcContainerHelper.ps1"))) { + $path = $bcContainerHelperVersion +} +elseif ($bccontainerHelperVersion -like "https://*") { + $path = Join-Path $env:TEMP ([Guid]::NewGuid().ToString()) +} +else { + $bcbaseurl = "https://bccontainerhelper.azureedge.net/public" + $versionsxml = [xml](New-Object System.Net.WebClient).DownloadString("$($bcbaseurl)?comp=list&restype=container") + + $latestVersion = $versionsxml.EnumerationResults.Blobs.Blob.Name | Where-Object { $_ -ne "latest.zip" -and $_ -notlike "*preview*" } | ForEach-Object { $_.replace('.zip','') } | Sort-Object { [Version]$_ } | Select-Object -Last 1 + $previewVersion = $versionsxml.EnumerationResults.Blobs.Blob.Name | Where-Object { $_ -like "*-preview*" } | ForEach-Object { $_.replace('.zip','') } | Sort-Object { [Version]($_.replace('-preview','.')) } | Select-Object -Last 1 + if ([version]$latestVersion -ge [version]($previewVersion.split('-')[0])) { + $previewVersion = $latestVersion + } + + if ($bccontainerHelperVersion -eq "latest") { + $bccontainerHelperVersion = $latestVersion + } + elseif ($bccontainerHelperVersion -eq "preview") { + $bccontainerHelperVersion = $previewVersion + } + $basePath = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules\BcContainerHelper" + if (!(Test-Path $basePath)) { New-Item $basePath -ItemType Directory | Out-Null } + $path = Join-Path $basePath $bccontainerHelperVersion + $bccontainerHelperVersion = "$bcbaseurl/$bccontainerHelperVersion.zip" +} + +$bchMutexName = "bcContainerHelper" +$bchMutex = New-Object System.Threading.Mutex($false, $bchMutexName) +try { + try { $bchMutex.WaitOne() | Out-Null } catch {} + if (!(Test-Path $path)) { + $tempName = Join-Path $env:TEMP ([Guid]::NewGuid().ToString()) + Write-Host "Downloading $bccontainerHelperVersion" + (New-Object System.Net.WebClient).DownloadFile($bccontainerHelperVersion, "$tempName.zip") + Expand-Archive -Path "$tempName.zip" -DestinationPath $tempName + $folder = (Get-Item -Path (Join-Path $tempName '*')).FullName + [System.IO.Directory]::Move($folder,$path) + } +} +finally { + $bchMutex.ReleaseMutex() +} +. (Join-Path $path "BcContainerHelper.ps1") + +if ($genericImageName) { + $bcContainerHelperConfig.genericImageName = $genericImageName +} diff --git a/scripts/Local-DevEnv.ps1 b/scripts/Local-DevEnv.ps1 new file mode 100644 index 000000000..2f897ea3d --- /dev/null +++ b/scripts/Local-DevEnv.ps1 @@ -0,0 +1,57 @@ +Param( + [Parameter(Mandatory=$false)] + [string] $version = "ci", + [string] $containerName = "", + [switch] $reUseContainer, + [string] $sharedFolder = "" +) + +$containerNameParam = $containerName +$baseFolder = (Get-Item (Join-Path $PSScriptRoot "..")).FullName +. (Join-Path $PSScriptRoot "Read-Settings.ps1") -environment 'Local' -version $version +. (Join-Path $PSScriptRoot "Install-BcContainerHelper.ps1") -bcContainerHelperVersion $bcContainerHelperVersion -genericImageName $genericImageName +if ($containerNameParam) { $containerName = $containerNameParam } + +if (("$vaultNameForLocal" -eq "") -or !(Get-AzKeyVault -VaultName $vaultNameForLocal)) { + throw "You need to setup a Key Vault for use with local pipelines" +} +Get-AzKeyVaultSecret -VaultName $vaultNameForLocal | ForEach-Object { + Write-Host "Get Secret $($_.Name)Secret" + Set-Variable -Name "$($_.Name)Secret" -Value (Get-AzKeyVaultSecret -VaultName $vaultNameForLocal -Name $_.Name -WarningAction SilentlyContinue) +} +$licenseFile = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($licenseFileSecret.SecretValue)) +$insiderSasToken = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($insiderSasTokenSecret.SecretValue)) +$credential = New-Object pscredential 'admin', $passwordSecret.SecretValue + +$allTestResults = "testresults*.xml" +$testResultsFile = Join-Path $baseFolder "TestResults.xml" +$testResultsFiles = Join-Path $baseFolder $allTestResults +if (Test-Path $testResultsFiles) { + Remove-Item $testResultsFiles -Force +} + +Run-AlPipeline ` + -pipelineName $pipelineName ` + -containerName $containerName ` + -imageName $imageName ` + -artifact $artifact.replace('{INSIDERSASTOKEN}',$insiderSasToken) ` + -memoryLimit $memoryLimit ` + -baseFolder $baseFolder ` + -sharedFolder $sharedFolder ` + -licenseFile $licenseFile ` + -installApps $installApps ` + -installTestApps $installTestApps ` + -appFolders $appFolders ` + -testFolders $testFolders ` + -testResultsFile $testResultsFile ` + -testResultsFormat 'JUnit' ` + -installTestRunner:$installTestRunner ` + -installTestFramework:$installTestFramework ` + -installTestLibraries:$installTestLibraries ` + -installPerformanceToolkit:$installPerformanceToolkit ` + -credential $credential ` + -doNotRunTests ` + -useDevEndpoint ` + -updateLaunchJson "Local Sandbox" ` + -keepContainer ` + -reUseContainer:$reUseContainer diff --git a/scripts/Local-Pipeline.ps1 b/scripts/Local-Pipeline.ps1 new file mode 100644 index 000000000..9d06005b2 --- /dev/null +++ b/scripts/Local-Pipeline.ps1 @@ -0,0 +1,60 @@ +Param( + [Parameter(Mandatory=$false)] + [string] $version = "ci", + [Parameter(Mandatory=$false)] + [int] $appBuild = ([int32]::MaxValue), + [Parameter(Mandatory=$false)] + [int] $appRevision = 0 +) + +$baseFolder = (Get-Item (Join-Path $PSScriptRoot "..")).FullName +. (Join-Path $PSScriptRoot "Read-Settings.ps1") -environment 'Local' -version $version +. (Join-Path $PSScriptRoot "Install-BcContainerHelper.ps1") -bcContainerHelperVersion $bcContainerHelperVersion -genericImageName $genericImageName + +if (("$vaultNameForLocal" -eq "") -or !(Get-AzKeyVault -VaultName $vaultNameForLocal)) { + throw "You need to setup a Key Vault for use with local pipelines" +} +Get-AzKeyVaultSecret -VaultName $vaultNameForLocal | ForEach-Object { + Write-Host "Get Secret $($_.Name)Secret" + Set-Variable -Name "$($_.Name)Secret" -Value (Get-AzKeyVaultSecret -VaultName $vaultNameForLocal -Name $_.Name -WarningAction SilentlyContinue) +} +$licenseFile = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($licenseFileSecret.SecretValue)) +$insiderSasToken = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($insiderSasTokenSecret.SecretValue)) +$credential = New-Object pscredential 'admin', $passwordSecret.SecretValue + +$allTestResults = "testresults*.xml" +$testResultsFile = Join-Path $baseFolder "TestResults.xml" +$testResultsFiles = Join-Path $baseFolder $allTestResults +if (Test-Path $testResultsFiles) { + Remove-Item $testResultsFiles -Force +} + +Run-AlPipeline ` + -pipelineName $pipelineName ` + -containerName $containerName ` + -imageName $imageName ` + -artifact $artifact.replace('{INSIDERSASTOKEN}',$insiderSasToken) ` + -memoryLimit $memoryLimit ` + -baseFolder $baseFolder ` + -licenseFile $licenseFile ` + -installApps $installApps ` + -installTestApps $installTestApps ` + -previousApps $previousApps ` + -appFolders $appFolders ` + -testFolders $testFolders ` + -doNotRunTests:$doNotRunTests ` + -testResultsFile $testResultsFile ` + -testResultsFormat 'JUnit' ` + -installTestRunner:$installTestRunner ` + -installTestFramework:$installTestFramework ` + -installTestLibraries:$installTestLibraries ` + -installPerformanceToolkit:$installPerformanceToolkit ` + -enableCodeCop:$enableCodeCop ` + -enableAppSourceCop:$enableAppSourceCop ` + -enablePerTenantExtensionCop:$enablePerTenantExtensionCop ` + -enableUICop:$enableUICop ` + -AppSourceCopMandatoryAffixes $appSourceCopMandatoryAffixes ` + -AppSourceCopSupportedCountries $appSourceCopSupportedCountries ` + -additionalCountries $additionalCountries ` + -credential $credential ` + -appBuild $appBuild -appRevision $appRevision diff --git a/scripts/MySolution.ps1 b/scripts/MySolution.ps1 new file mode 100644 index 000000000..704b46b51 --- /dev/null +++ b/scripts/MySolution.ps1 @@ -0,0 +1,64 @@ +$path = Join-Path $PSScriptRoot ".." + +$replaceObjectIds = @{ + "50130" = 80130 + "50133" = 80133 + "50101" = 80101 + "50100" = 80100 + "50149" = 80149 +} +$replaceValues = @{ + "00000000-0000-0000-0000-000000000001" = [Guid]::NewGuid().ToString() + "00000000-0000-0000-0000-000000000002" = [Guid]::NewGuid().ToString() + "00000000-0000-0000-0000-000000000003" = [Guid]::NewGuid().ToString() + "HelloWorld" = "MyApp" + "Default Publisher" = "My Name" + "Default App Name" = "My App" + "Default Base App Name" = "My Base App" + "Default Test App Name" = "My Test App" + "2.0.0.0" = "1.0.0.0" + "https://businesscentralapps.azureedge.net/helloworld/latest/apps.zip" = "" +} + $replaceObjectIds + +function ReplaceProperty { Param ($object, $property) + if ($object.PSObject.Properties.name -eq $property) { + $str = "$($object."$property")" + if ($replaceValues.ContainsKey($str)) { + Write-Host "- change $property from $str to $($replaceValues[$str]) " + $object."$property" = $replaceValues[$str] + } + } +} + +function ReplaceObject { Param($object) + "id", "appId", "name", "publisher", "version", "previousApps", "appSourceCopMandatoryAffixes", "appSourceCopSupportedCountries","from","to" | ForEach-Object { + ReplaceProperty -object $object -property $_ + } +} + +Get-ChildItem -Path $path | Where-Object { $_.psIsContainer -and $_.Name -notlike ".*" } | Get-ChildItem -Recurse -filter "app.json" | ForEach-Object { + $appJsonFile = $_.FullName + $appJson = Get-Content $appJsonFile | ConvertFrom-Json + Write-Host -ForegroundColor Yellow $appJsonFile + ReplaceObject -object $appJson + Write-Host "Check idRanges" + $appJson.idRanges | ForEach-Object { ReplaceObject($_) } + Write-Host "Check Dependencies" + $appJson.dependencies | ForEach-Object { ReplaceObject($_) } + $appJson | ConvertTo-Json -Depth 10 | Set-Content $appJsonFile +} + +Get-ChildItem -Path $path | Where-Object { $_.psIsContainer -and $_.Name -notlike ".*" } | Get-ChildItem -Recurse -filter "*.al" | ForEach-Object { + $source = Get-Content $_.FullName + $replaceObjectIds.Keys | % { + $source = $source.Replace("$_", $replaceObjectIds."$_") + } + Set-Content -Path $_.FullName -Value $source +} + + +$settingsFile = Join-Path $PSScriptRoot "settings.json" +$settings = Get-Content $settingsFile | ConvertFrom-Json +Write-Host -ForegroundColor Yellow $settingsFile +ReplaceObject -object $settings +$settings | ConvertTo-Json -Depth 10 | Set-Content $settingsFile diff --git a/scripts/Read-Settings.ps1 b/scripts/Read-Settings.ps1 new file mode 100644 index 000000000..8fad70919 --- /dev/null +++ b/scripts/Read-Settings.ps1 @@ -0,0 +1,72 @@ +Param( + [Parameter(Mandatory=$false)] + [ValidateSet('Local', 'AzureDevOps', 'GithubActions', 'GitLab')] + [string] $environment = 'Local', + [string] $version = "" +) + +$ErrorActionPreference = "Stop" +$WarningPreference = "Continue" + +$agentName = "" +if ($environment -ne 'Local') { + $agentName = $ENV:AGENT_NAME +} + +$settings = (Get-Content (Join-Path $PSScriptRoot "settings.json") | ConvertFrom-Json) +if ("$version" -eq "") { + $version = $settings.versions[0].version + Write-Host "Version not defined, using $version" +} + +$buildversion = $settings.versions | Where-Object { $_.version -eq $version } +if ($buildversion) { + Write-Host "Set artifact = $($buildVersion.artifact)" + Set-Variable -Name "artifact" -Value $buildVersion.artifact +} +else { + throw "Unknown version: $version" +} + +$pipelineName = "$($settings.Name)-$version" +Write-Host "Set pipelineName = $pipelineName" + +if ($agentName) { + $containerName = "$($agentName -replace '[^a-zA-Z0-9---]', '')-$($pipelineName -replace '[^a-zA-Z0-9---]', '')".ToLowerInvariant() +} +else { + $containerName = "$($pipelineName.Replace('.','-') -replace '[^a-zA-Z0-9---]', '')".ToLowerInvariant() +} +Write-Host "Set containerName = $containerName" +if ($environment -eq 'AzureDevOps') { + Write-Host "##vso[task.setvariable variable=containerName]$containerName" +} + +"installApps", "installTestApps", "previousApps", "appSourceCopMandatoryAffixes", "appSourceCopSupportedCountries", "appFolders", "testFolders", "memoryLimit", "additionalCountries", "genericImageName", "vaultNameForLocal", "bcContainerHelperVersion" | ForEach-Object { + $str = "" + if ($buildversion.PSObject.Properties.Name -eq $_) { + $str = $buildversion."$_" + } + elseif ($settings.PSObject.Properties.Name -eq $_) { + $str = $settings."$_" + } + Write-Host "Set $_ = '$str'" + Set-Variable -Name $_ -Value "$str" +} + +"installTestRunner", "installTestFramework", "installTestLibraries", "installPerformanceToolkit", "enableCodeCop", "enableAppSourceCop", "enablePerTenantExtensionCop", "enableUICop", "doNotSignApps", "doNotRunTests", "cacheImage", "CreateRuntimePackages" | ForEach-Object { + $str = "False" + if ($buildversion.PSObject.Properties.Name -eq $_) { + $str = $buildversion."$_" + } + elseif ($settings.PSObject.Properties.Name -eq $_) { + $str = $settings."$_" + } + Write-Host "Set $_ = $str" + Set-Variable -Name $_ -Value ($str -eq "True") +} + +$imageName = "" +if ($cacheImage -and ("$AgentName" -ne "Hosted Agent" -and "$AgentName" -notlike "Azure Pipelines*")) { + $imageName = "bcimage" +}