Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/microsoft/AL-Go
Browse files Browse the repository at this point in the history
  • Loading branch information
mazhelez committed Oct 4, 2023
2 parents 5314bfb + 9042092 commit 38c3b97
Show file tree
Hide file tree
Showing 55 changed files with 282 additions and 238 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/Deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
required: false
default: false
defaultBcContainerHelperVersion:
description: 'Which version of BcContainerHelper to use? (latest, preview, private, a specific version number or a direct download URL like https://github.com/freddydk/navcontainerhelper/archive/master.zip - leave empty to use latest)'
description: 'Which version of BcContainerHelper to use? (latest, preview, private, a specific version number or a direct download URL like https://github.com/freddydk/navcontainerhelper/archive/master.zip). Leave empty to use latest (or preview for preview branches)'
required: false
default: ''

Expand All @@ -35,11 +35,13 @@ jobs:
- name: Validate Deployment
if: github.repository_owner == 'microsoft'
env:
GH_TOKEN: ${{ github.token }}
branch: ${{ github.event.inputs.branch }}
repository: ${{ github.repository }}
runId: ${{ github.run_id }}
run: |
if ($env:branch -match 'preview') {
$errorActionPreference = "Stop"
if ($env:branch -eq 'preview') {
Write-Host "Deploying to preview branch. No validation required"
} else {
$approval = gh api /repos/$($env:repository)/actions/runs/$($env:runId)/approvals | ConvertFrom-Json
Expand All @@ -66,6 +68,13 @@ jobs:
throw "In order to run the Deploy workflow, you need a Secret called OrgPAT containing a valid Personal Access Token"
}
$githubOwner = "$ENV:GITHUB_REPOSITORY_OWNER"
if ("$env:defaultBcContainerHelperVersion" -eq "") {
if ($env:branch -eq 'preview') {
$env:defaultBcContainerHelperVersion = 'preview'
} else {
$env:defaultBcContainerHelperVersion = 'latest'
}
}
$config = @{
"githubOwner" = $githubOwner
"actionsRepo" = "AL-Go-Actions"
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/E2E.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ jobs:
Write-Host "::Error::In order to run end to end tests, you need a Secret called licenseFileUrl containing a secure Url to a build license file"
$err = $true
}
if ('${{ Secrets.insiderSasToken }}' -eq '') {
Write-Host "::Error::In order to run end to end tests, you need a Secret called insiderSasToken containing the Insider SAS token from https://aka.ms/collaborate"
$err = $true
}
if ($err) {
exit 1
}
Expand Down Expand Up @@ -196,7 +192,7 @@ jobs:
- name: Run test
run: |
try {
. (Join-Path "." "e2eTests/scenarios/${{ matrix.scenario }}/runtest.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -InsiderSasToken '${{ Secrets.InsiderSasToken }}' -pteTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.appSourceAppRepo }}' -adminCenterApiToken '${{ Secrets.adminCenterApiCredentials }}' -licenseFileUrl '${{ Secrets.licenseFileUrl }}'
. (Join-Path "." "e2eTests/scenarios/${{ matrix.scenario }}/runtest.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -pteTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.appSourceAppRepo }}' -adminCenterApiToken '${{ Secrets.adminCenterApiCredentials }}' -licenseFileUrl '${{ Secrets.licenseFileUrl }}'
}
catch {
Write-Host $_.Exception.Message
Expand Down Expand Up @@ -242,7 +238,7 @@ jobs:
- name: Run tests
run: |
try {
. (Join-Path "." "e2eTests/Test-AL-Go.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -InsiderSasToken '${{ Secrets.InsiderSasToken }}' -template ${{ steps.calculateParams.outputs.template }} -adminCenterApiToken ${{ steps.calculateParams.outputs.adminCenterApiCredentials }} -licenseFileUrl ${{ steps.calculateParams.outputs.licenseFileUrl }} -multiProject:('${{ matrix.style }}' -eq 'multiProject') -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -linux:('${{ matrix.os }}' -eq 'linux') -private:('${{ matrix.visibility }}' -eq 'private') -useCompilerFolder:('${{ matrix.Compiler }}' -eq 'CompilerFolder')
. (Join-Path "." "e2eTests/Test-AL-Go.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -template ${{ steps.calculateParams.outputs.template }} -adminCenterApiToken ${{ steps.calculateParams.outputs.adminCenterApiCredentials }} -licenseFileUrl ${{ steps.calculateParams.outputs.licenseFileUrl }} -multiProject:('${{ matrix.style }}' -eq 'multiProject') -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -linux:('${{ matrix.os }}' -eq 'linux') -private:('${{ matrix.visibility }}' -eq 'private') -useCompilerFolder:('${{ matrix.Compiler }}' -eq 'CompilerFolder')
}
catch {
Write-Host $_.Exception.Message
Expand Down
70 changes: 32 additions & 38 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ $runAlPipelineOverrides = @(
"GetBcContainerAppRuntimePackage"
"RemoveBcContainer"
"InstallMissingDependencies"
"PreCompileApp"
"PostCompileApp"
)

# Well known AppIds
Expand Down Expand Up @@ -337,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 @@ -528,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 @@ -551,7 +556,6 @@ function ReadSettings {
"appRevision" = 0
"keyVaultName" = ""
"licenseFileUrlSecretName" = "licenseFileUrl"
"insiderSasTokenSecretName" = "insiderSasToken"
"ghTokenWorkflowSecretName" = "ghTokenWorkflow"
"adminCenterApiCredentialsSecretName" = "adminCenterApiCredentials"
"applicationInsightsConnectionStringSecretName" = "applicationInsightsConnectionString"
Expand Down Expand Up @@ -585,6 +589,7 @@ function ReadSettings {
"failOn" = "error"
"treatTestFailuresAsWarnings" = $false
"rulesetFile" = ""
"enableExternalRulesets" = $false
"vsixFile" = ""
"assignPremiumPlan" = $false
"enableTaskScheduler" = $false
Expand Down Expand Up @@ -840,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 @@ -990,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 @@ -1298,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 @@ -1504,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 @@ -1593,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 @@ -1638,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 @@ -1747,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 @@ -1839,6 +1842,7 @@ function CreateDevEnv {
}

Run-AlPipeline @runAlPipelineParams `
-accept_insiderEula:$accept_insiderEula `
-vsixFile $settings.vsixFile `
-pipelinename $workflowName `
-imageName "" `
Expand All @@ -1860,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 @@ -2070,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 @@ -2106,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 @@ -2142,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 @@ -2151,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 @@ -2168,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
2 changes: 1 addition & 1 deletion Actions/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
2 changes: 1 addition & 1 deletion Actions/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
Loading

0 comments on commit 38c3b97

Please sign in to comment.