Skip to content

Commit

Permalink
Deploying AL-Go from main (91a563be484eeff8ccde7f39b3622991cc8931f0) …
Browse files Browse the repository at this point in the history
…to main (#24)

Deploying AL-Go from main (91a563be484eeff8ccde7f39b3622991cc8931f0) to
main

Co-authored-by: microsoft <[email protected]>
  • Loading branch information
bcbuild-github-agent and microsoft authored Oct 17, 2023
1 parent a26f554 commit 01dd9f9
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 112 deletions.
70 changes: 31 additions & 39 deletions AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $defaultCICDPushBranches = @( 'main', 'release/*', 'feature/*' )
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'defaultCICDPullRequestBranches', Justification = 'False positive.')]
$defaultCICDPullRequestBranches = @( 'main' )
$runningLocal = $local.IsPresent
$defaultBcContainerHelperVersion = "preview" # Must be double quotes. Will be replaced by BcContainerHelperVersion if necessary in the deploy step
$defaultBcContainerHelperVersion = "latest" # Must be double quotes. Will be replaced by BcContainerHelperVersion if necessary in the deploy step
$microsoftTelemetryConnectionString = "InstrumentationKey=84bd9223-67d4-4378-8590-9e4a46023be2;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/"

$runAlPipelineOverrides = @(
Expand Down Expand Up @@ -339,7 +339,7 @@ function GetBcContainerHelperPath([string] $bcContainerHelperVersion) {
Remove-Item -Path "$tempName.zip" -ErrorAction SilentlyContinue
if ($bcContainerHelperVersion -notlike "https://*") {
# Check whether the version is already available in the cache
$version = Get-Content -Encoding UTF8 -Path (Join-Path $tempName 'BcContainerHelper/Version.txt')
$version = ([System.IO.File]::ReadAllText((Join-Path $tempName 'BcContainerHelper/Version.txt'), [System.Text.Encoding]::UTF8)).Trim()
$cacheFolder = Join-Path $bcContainerHelperRootFolder $version
# To avoid two agents on the same machine downloading the same version at the same time, use a mutex
$buildMutexName = "DownloadAndImportBcContainerHelper"
Expand Down Expand Up @@ -530,6 +530,9 @@ function ReadSettings {
throw "Error reading $path. Error was $($_.Exception.Message).`n$($_.ScriptStackTrace)"
}
}
else {
Write-Host "No settings found in $path"
}
return $null
}

Expand All @@ -553,7 +556,6 @@ function ReadSettings {
"appRevision" = 0
"keyVaultName" = ""
"licenseFileUrlSecretName" = "licenseFileUrl"
"insiderSasTokenSecretName" = "insiderSasToken"
"ghTokenWorkflowSecretName" = "ghTokenWorkflow"
"adminCenterApiCredentialsSecretName" = "adminCenterApiCredentials"
"applicationInsightsConnectionStringSecretName" = "applicationInsightsConnectionString"
Expand Down Expand Up @@ -587,6 +589,7 @@ function ReadSettings {
"failOn" = "error"
"treatTestFailuresAsWarnings" = $false
"rulesetFile" = ""
"enableExternalRulesets" = $false
"vsixFile" = ""
"assignPremiumPlan" = $false
"enableTaskScheduler" = $false
Expand Down Expand Up @@ -842,7 +845,6 @@ function AnalyzeRepo {
[hashTable] $settings,
[string] $baseFolder = $ENV:GITHUB_WORKSPACE,
[string] $project = '.',
[string] $insiderSasToken,
[switch] $doNotCheckArtifactSetting,
[switch] $doNotIssueWarnings,
[string[]] $includeOnlyAppIds
Expand Down Expand Up @@ -992,7 +994,7 @@ function AnalyzeRepo {
}

if (!$doNotCheckArtifactSetting) {
$artifactUrl = DetermineArtifactUrl -projectSettings $settings -insiderSasToken $insiderSasToken -doNotIssueWarnings:$doNotIssueWarnings
$artifactUrl = DetermineArtifactUrl -projectSettings $settings -doNotIssueWarnings:$doNotIssueWarnings
$version = $artifactUrl.Split('/')[4]
Write-Host "Downloading artifacts from $($artifactUrl.Split('?')[0])"
$folders = Download-Artifacts -artifactUrl $artifactUrl -includePlatform -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -1300,7 +1302,7 @@ function CommitFromNewFolder {
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $ENV:GITHUB_REF_NAME
}
catch {
OutputError("GitHub actions are not allowed to create Pull Requests (see GitHub Organization or Repository Actions Settings). You can create the PR manually by navigating to $($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/$branch.")
OutputError("GitHub actions are not allowed to create Pull Requests (see GitHub Organization or Repository Actions Settings). You can create the PR manually by navigating to $($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/$branch")
}
}
else {
Expand Down Expand Up @@ -1506,8 +1508,8 @@ function CreateDevEnv {
[pscredential] $credential,
[Parameter(ParameterSetName = 'local')]
[string] $containerName = "",
[string] $insiderSasToken = "",
[string] $licenseFileUrl = ""
[string] $licenseFileUrl = "",
[switch] $accept_insiderEula
)

if ($PSCmdlet.ParameterSetName -ne $kind) {
Expand Down Expand Up @@ -1595,9 +1597,6 @@ function CreateDevEnv {
$LicenseFileSecret = Get-AzKeyVaultSecret -VaultName $settings.keyVaultName -Name $settings.licenseFileUrlSecretName
if ($LicenseFileSecret) { $licenseFileUrl = $LicenseFileSecret.SecretValue | Get-PlainText }

$insiderSasTokenSecret = Get-AzKeyVaultSecret -VaultName $settings.keyVaultName -Name $settings.insiderSasTokenSecretName
if ($insiderSasTokenSecret) { $insiderSasToken = $insiderSasTokenSecret.SecretValue | Get-PlainText }

# do not add codesign cert.

if ($settings.applicationInsightsConnectionStringSecretName) {
Expand Down Expand Up @@ -1640,18 +1639,20 @@ function CreateDevEnv {
}

$params = @{}
if ($kind -eq "local") {
$params += @{
"insiderSasToken" = $insiderSasToken
}
}
elseif ($kind -eq "cloud") {
if ($kind -eq "cloud") {
$accept_insiderEula = $true
$params += @{
"doNotCheckArtifactSetting" = $true
}
}
$settings = AnalyzeRepo -settings $settings -baseFolder $baseFolder -project $project @params
$settings = CheckAppDependencyProbingPaths -settings $settings -baseFolder $baseFolder -project $project

if (!$accept_insiderEula -and ($settings.artifact -like 'https://bcinsider.blob.core.windows.net/*' -or $settings.artifact -like 'https://bcinsider.azureedge.net/*')) {
Read-Host 'Press ENTER to accept the Business Central insider EULA (https://go.microsoft.com/fwlink/?linkid=2245051) or break the script to cancel'
$accept_insiderEula = $true
}

if ((-not $settings.appFolders) -and (-not $settings.testFolders)) {
Write-Host "Repository is empty"
}
Expand Down Expand Up @@ -1749,7 +1750,7 @@ function CreateDevEnv {

if ($kind -eq "local") {
$runAlPipelineParams += @{
"artifact" = $settings.artifact.replace('{INSIDERSASTOKEN}', $insiderSasToken)
"artifact" = $settings.artifact.replace('{INSIDERSASTOKEN}', '')
"auth" = $auth
"credential" = $credential
}
Expand Down Expand Up @@ -1841,6 +1842,7 @@ function CreateDevEnv {
}

Run-AlPipeline @runAlPipelineParams `
-accept_insiderEula:$accept_insiderEula `
-vsixFile $settings.vsixFile `
-pipelinename $workflowName `
-imageName "" `
Expand All @@ -1862,6 +1864,7 @@ function CreateDevEnv {
-failOn $settings.failOn `
-treatTestFailuresAsWarnings:$settings.treatTestFailuresAsWarnings `
-rulesetFile $settings.rulesetFile `
-enableExternalRulesets:$settings.enableExternalRulesets `
-AppSourceCopMandatoryAffixes $settings.appSourceCopMandatoryAffixes `
-obsoleteTagMinAllowedMajorMinor $settings.obsoleteTagMinAllowedMajorMinor `
-doNotRunTests `
Expand Down Expand Up @@ -2072,7 +2075,7 @@ function GetBaseFolder {

Push-Location $folder
try {
$baseFolder = invoke-git rev-parse --show-toplevel -returnValue
$baseFolder = invoke-git -silent rev-parse --show-toplevel -returnValue
}
finally {
Pop-Location
Expand Down Expand Up @@ -2108,32 +2111,23 @@ function GetProject {
function DetermineArtifactUrl {
Param(
[hashtable] $projectSettings,
[string] $insiderSasToken = "",
[switch] $doNotIssueWarnings
)

$artifact = $projectSettings.artifact
if ($artifact.Contains('{INSIDERSASTOKEN}')) {
if ($insiderSasToken) {
$artifact = $artifact.replace('{INSIDERSASTOKEN}', $insiderSasToken)
}
else {
throw "Artifact definition $artifact requires you to create a secret called InsiderSasToken, containing the Insider SAS Token from https://aka.ms/collaborate"
}
$artifact = $artifact.replace('{INSIDERSASTOKEN}', '')
Write-Host "::Warning::Please update your artifact setting and remove {INSIDERSASTOKEN} from the setting. This is no longer needed."
}

Write-Host "Checking artifact setting for project"
if ($artifact -eq "" -and $projectSettings.updateDependencies) {
$artifact = Get-BCArtifactUrl -country $projectSettings.country -select all | Where-Object { [Version]$_.Split("/")[4] -ge [Version]$projectSettings.applicationDependency } | Select-Object -First 1
if (-not $artifact) {
if ($insiderSasToken) {
$artifact = Get-BCArtifactUrl -storageAccount bcinsider -country $projectSettings.country -select all -sasToken $insiderSasToken | Where-Object { [Version]$_.Split("/")[4] -ge [Version]$projectSettings.applicationDependency } | Select-Object -First 1
if (-not $artifact) {
throw "No artifacts found for application dependency $($projectSettings.applicationDependency)."
}
}
else {
throw "No artifacts found for application dependency $($projectSettings.applicationDependency). If you are targetting an insider version, you need to create a secret called InsiderSasToken, containing the Insider SAS Token from https://aka.ms/collaborate"
# Check Insider Artifacts
$artifact = Get-BCArtifactUrl -storageAccount bcinsider -accept_insiderEula -country $projectSettings.country -select all | Where-Object { [Version]$_.Split("/")[4] -ge [Version]$projectSettings.applicationDependency } | Select-Object -First 1
if (-not $artifact) {
throw "No artifacts found for application dependency $($projectSettings.applicationDependency)."
}
}
}
Expand All @@ -2144,7 +2138,6 @@ function DetermineArtifactUrl {
$artifactType = ("$artifactUrl////".Split('/')[3])
$version = ("$artifactUrl////".Split('/')[4])
$country = ("$artifactUrl////".Split('?')[0].Split('/')[5])
$sasToken = "$($artifactUrl)?".Split('?')[1]
}
else {
$segments = "$artifact/////".Split('/')
Expand All @@ -2153,8 +2146,7 @@ function DetermineArtifactUrl {
$version = $segments[2]
$country = $segments[3]; if ($country -eq "") { $country = $projectSettings.country }
$select = $segments[4]; if ($select -eq "") { $select = "latest" }
$sasToken = $segments[5]
$artifactUrl = Get-BCArtifactUrl -storageAccount $storageAccount -type $artifactType -version $version -country $country -select $select -sasToken $sasToken | Select-Object -First 1
$artifactUrl = Get-BCArtifactUrl -storageAccount $storageAccount -type $artifactType -version $version -country $country -select $select -accept_insiderEula | Select-Object -First 1
if (-not $artifactUrl) {
throw "No artifacts found for the artifact setting ($artifact) in $ALGoSettingsFile"
}
Expand All @@ -2170,10 +2162,10 @@ function DetermineArtifactUrl {
# AT is the latest published language - use this to determine available country codes (combined with mapping)
$ver = [Version]$version
Write-Host "https://$storageAccount/$artifactType/$version/$country"
$atArtifactUrl = Get-BCArtifactUrl -storageAccount $storageAccount -type $artifactType -country at -version "$($ver.Major).$($ver.Minor)" -select Latest -sasToken $sasToken
$atArtifactUrl = Get-BCArtifactUrl -storageAccount $storageAccount -type $artifactType -country at -version "$($ver.Major).$($ver.Minor)" -select Latest -accept_insiderEula
Write-Host "Latest AT artifacts $atArtifactUrl"
$latestATversion = $atArtifactUrl.Split('/')[4]
$countries = Get-BCArtifactUrl -storageAccount $storageAccount -type $artifactType -version $latestATversion -sasToken $sasToken -select All | ForEach-Object {
$countries = Get-BCArtifactUrl -storageAccount $storageAccount -type $artifactType -version $latestATversion -accept_insiderEula -select All | ForEach-Object {
$countryArtifactUrl = $_.Split('?')[0] # remove sas token
$countryArtifactUrl.Split('/')[5] # get country
}
Expand Down
17 changes: 16 additions & 1 deletion AL-Go-TestRepoHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,22 @@ function Test-JsonFile {
Test-JsonStr -org -jsonStr (Get-Content -Path $jsonFile -Raw -Encoding UTF8) -settingsDescription $settingsFile -type $type
}

function Test-ALGoRepository {
function TestRunnerPrerequisites {
try {
invoke-gh version
}
catch {
Write-Host "::Warning::GitHub CLI is not installed"
}
try {
invoke-git version
}
catch {
Write-Host "::Warning::Git is not installed"
}
}

function TestALGoRepository {
Param(
[string] $baseFolder = $ENV:GITHUB_WORKSPACE
)
Expand Down
2 changes: 1 addition & 1 deletion AnalyzeTests/AnalyzeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ try {
Add-Content -path $ENV:GITHUB_STEP_SUMMARY -value "$($testResultSummary.Replace("\n","`n"))`n"
}
else {
Add-Content -path $ENV:GITHUB_STEP_SUMMARY -value "*Test results not found*`n`n"
Write-Host "Test results not found"
}

$bcptTestResultsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\BCPTTestResults.json"
Expand Down
8 changes: 6 additions & 2 deletions CalculateArtifactNames/CalculateArtifactNames.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Param(
[string] $project,
[Parameter(HelpMessage = "Build mode used when building the artifacts", Mandatory = $true)]
[string] $buildMode,
[Parameter(HelpMessage = "Name of the branch the workflow is running on", Mandatory = $true)]
[string] $branchName,
[Parameter(HelpMessage = "Suffix to add to the artifacts names", Mandatory = $false)]
[string] $suffix
)
Expand All @@ -20,6 +18,12 @@ if ($project -eq ".") {
$project = $settings.repoName
}

$branchName = $ENV:GITHUB_HEAD_REF
# $ENV:GITHUB_HEAD_REF is specified only for pull requests, so if it is not specified, use GITHUB_REF_NAME
if (!$branchName) {
$branchName = $ENV:GITHUB_REF_NAME
}

$branchName = $branchName.Replace('\', '_').Replace('/', '_')
$projectName = $project.Replace('\', '_').Replace('/', '_')

Expand Down
1 change: 0 additions & 1 deletion CalculateArtifactNames/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Calculate Artifact Names for AL-Go workflows
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| project | Yes | Name of the built project or . if the repository is setup for single project | |
| buildMode | Yes |Build mode used when building the artifacts | |
| branchName | Yes | Name of the branch the workflow is running on | |
| suffix | | A suffix to add to artifacts names. **Note:** if a suffix is specified, the current date will be added extra | Build version |

## OUTPUT
Expand Down
6 changes: 1 addition & 5 deletions CalculateArtifactNames/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ inputs:
buildMode:
description: Build mode used when building the artifacts
required: true
branchName:
description: Name of the branch the workflow is running on
required: true
suffix:
description: Suffix to add to the artifacts names
required: false
Expand Down Expand Up @@ -58,12 +55,11 @@ runs:
env:
_project: ${{ inputs.project }}
_buildMode: ${{ inputs.buildMode }}
_branchName: ${{ inputs.branchName }}
_suffix: ${{ inputs.suffix }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
try {
${{ github.action_path }}/CalculateArtifactNames.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -branchName $ENV:_branchName -suffix $ENV:_suffix
${{ github.action_path }}/CalculateArtifactNames.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -suffix $ENV:_suffix
}
catch {
Write-Host "::ERROR::Unexpected error when running action. Error Message: $($_.Exception.Message.Replace("`r",'').Replace("`n",' ')), StackTrace: $($_.ScriptStackTrace.Replace("`r",'').Replace("`n",' <- '))";
Expand Down
2 changes: 1 addition & 1 deletion CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ try {
# DirectALGo is used to determine if the template is a direct link to an AL-Go repository
$directALGo = $templateUrl -like 'https://github.com/*/AL-Go@*'
if ($directALGo) {
if ($templateUrl -like 'https://github.com/microsoft/AL-Go@*') {
if ($templateUrl -like 'https://github.com/microsoft/AL-Go@*' -and -not ($templateUrl -like 'https://github.com/microsoft/AL-Go@*/*')) {
throw "You cannot use microsoft/AL-Go as a template repository. Please use a fork of AL-Go instead."
}
}
Expand Down
16 changes: 15 additions & 1 deletion Deliver/Deliver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function EnsureAzStorageModule() {
Import-Module 'Azure.Storage' -DisableNameChecking -WarningAction SilentlyContinue | Out-Null
Set-Alias -Name New-AzStorageContext -Value New-AzureStorageContext -Scope Script
Set-Alias -Name Get-AzStorageContainer -Value Get-AzureStorageContainer -Scope Script
Set-Alias -Name New-AzStorageContainer -Value New-AzureStorageContainer -Scope Script
Set-Alias -Name Set-AzStorageBlobContent -Value Set-AzureStorageBlobContent -Scope Script
}
else {
Expand Down Expand Up @@ -352,7 +353,20 @@ try {
$storageBlobName = $storageAccount.BlobName.ToLowerInvariant()
Write-Host "Storage Container Name is $storageContainerName"
Write-Host "Storage Blob Name is $storageBlobName"
Get-AzStorageContainer -Context $azStorageContext -name $storageContainerName | Out-Null

$containerExists = $true
try {
Get-AzStorageContainer -Context $azStorageContext -name $storageContainerName | Out-Null
}
catch {
$containerExists = $false
}

if (-not $containerExists -and $settings.Contains('DeliverToStorage') -and $settings."DeliverToStorage".Contains('CreateContainerIfNotExist') -and $settings."DeliverToStorage"."CreateContainerIfNotExist" -eq $true) {
Write-Host "Container $storageContainerName does not exist. Creating..."
New-AzStorageContainer -Context $azStorageContext -Name $storageContainerName | Out-Null
}

Write-Host "Delivering to $storageContainerName in $($storageAccount.StorageAccountName)"
$atypes.Split(',') | ForEach-Object {
$atype = $_
Expand Down
6 changes: 4 additions & 2 deletions Deploy/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ try {
throw "Authentication failed. $([environment]::Newline) $($_.exception.message)"
}

Write-Host "$($bcContainerHelperConfig.baseUrl.TrimEnd('/'))/$($bcAuthContext.tenantId)/$($deploymentSettings.EnvironmentName)/deployment/url"
$response = Invoke-RestMethod -UseBasicParsing -Method Get -Uri "$($bcContainerHelperConfig.baseUrl.TrimEnd('/'))/$($bcAuthContext.tenantId)/$($deploymentSettings.EnvironmentName)/deployment/url"
$environmentUrl = "$($bcContainerHelperConfig.baseUrl.TrimEnd('/'))/$($bcAuthContext.tenantId)/$($deploymentSettings.EnvironmentName)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "environmentUrl=$environmentUrl"
Write-Host "EnvironmentUrl: $environmentUrl"
$response = Invoke-RestMethod -UseBasicParsing -Method Get -Uri "$environmentUrl/deployment/url"
if ($response.Status -eq "DoesNotExist") {
OutputError -message "Environment with name $($deploymentSettings.EnvironmentName) does not exist in the current authorization context."
exit
Expand Down
Loading

0 comments on commit 01dd9f9

Please sign in to comment.