Skip to content

Commit

Permalink
Merge pull request #84 from freddydk/main
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
freddydk authored Apr 14, 2022
2 parents 118318c + edf8bbf commit 7dc1ee1
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 116 deletions.
142 changes: 80 additions & 62 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ function ReadSettings {
"installApps" = @()
"installTestApps" = @()
"installOnlyReferencedApps" = $true
"generateDependencyArtifact" = $false
"skipUpgrade" = $false
"applicationDependency" = "18.0.0.0"
"updateDependencies" = $false
"installTestRunner" = $false
"installTestFramework" = $false
"installTestLibraries" = $false
Expand Down Expand Up @@ -482,68 +484,6 @@ function AnalyzeRepo {
}
}

if (!$doNotCheckArtifactSetting) {
Write-Host "Checking artifact setting"
if ($artifact -like "https://*") {
$artifactUrl = $artifact
$storageAccount = ("$artifactUrl////".Split('/')[2]).Split('.')[0]
$artifactType = ("$artifactUrl////".Split('/')[3])
$version = ("$artifactUrl////".Split('/')[4])
$country = ("$artifactUrl////".Split('/')[5])
$sasToken = "$($artifactUrl)?".Split('?')[1]
}
else {
$segments = "$artifact/////".Split('/')
$storageAccount = $segments[0];
$artifactType = $segments[1]; if ($artifactType -eq "") { $artifactType = 'Sandbox' }
$version = $segments[2]
$country = $segments[3]; if ($country -eq "") { $country = $settings.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
if (-not $artifactUrl) {
throw "No artifacts found for the artifact setting ($artifact) in $ALGoSettingsFile"
}
$version = $artifactUrl.Split('/')[4]
$storageAccount = $artifactUrl.Split('/')[2]
}

if ($settings.additionalCountries -or $country -ne $settings.country) {
if ($country -ne $settings.country) {
OutputWarning -message "artifact definition in $ALGoSettingsFile uses a different country ($country) than the country definition ($($settings.country))"
}
Write-Host "Checking Country and additionalCountries"
# 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
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 {
$countryArtifactUrl = $_.Split('?')[0] # remove sas token
$countryArtifactUrl.Split('/')[5] # get country
}
Write-Host "Countries with artifacts $($countries -join ',')"
$allowedCountries = $bcContainerHelperConfig.mapCountryCode.PSObject.Properties.Name + $countries | Select-Object -Unique
Write-Host "Allowed Country codes $($allowedCountries -join ',')"
if ($allowedCountries -notcontains $settings.country) {
throw "Country ($($settings.country)), specified in $ALGoSettingsFile is not a valid country code."
}
$illegalCountries = $settings.additionalCountries | Where-Object { $allowedCountries -notcontains $_ }
if ($illegalCountries) {
throw "additionalCountries contains one or more invalid country codes ($($illegalCountries -join ",")) in $ALGoSettingsFile."
}
}
else {
Write-Host "Downloading artifacts from $($artifactUrl.Split('?')[0])"
$folders = Download-Artifacts -artifactUrl $artifactUrl -includePlatform -ErrorAction SilentlyContinue
if (-not ($folders)) {
throw "Unable to download artifacts from $($artifactUrl.Split('?')[0]), please check $ALGoSettingsFile."
}
$settings.artifact = $artifactUrl
}
}

if (-not (@($settings.appFolders)+@($settings.testFolders))) {
Get-ChildItem -Path $baseFolder -Directory | Where-Object { Test-Path -Path (Join-Path $_.FullName "app.json") } | ForEach-Object {
$folder = $_
Expand All @@ -570,6 +510,7 @@ function AnalyzeRepo {
}
}
}

Write-Host "Checking appFolders and testFolders"
$dependencies = [ordered]@{}
$true, $false | ForEach-Object {
Expand Down Expand Up @@ -641,8 +582,85 @@ function AnalyzeRepo {
}
}
}
Write-Host "Application Dependency $($settings.applicationDependency)"

if (!$doNotCheckArtifactSetting) {
Write-Host "Checking artifact setting"
if ($artifact -eq "" -and $settings.updateDependencies) {
$artifact = Get-BCArtifactUrl -country $settings.country -select all | Where-Object { [Version]$_.Split("/")[4] -ge [Version]$settings.applicationDependency } | Select-Object -First 1
if (-not $artifact) {
if ($insiderSasToken) {
$artifact = Get-BCArtifactUrl -storageAccount bcinsider -country $settings.country -select all -sasToken $insiderSasToken | Where-Object { [Version]$_.Split("/")[4] -ge [Version]$settings.applicationDependency } | Select-Object -First 1
if (-not $artifact) {
throw "No artifacts found for application dependency $($settings.applicationDependency)."
}
}
else {
throw "No artifacts found for application dependency $($settings.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"
}
}
}

if ($artifact -like "https://*") {
$artifactUrl = $artifact
$storageAccount = ("$artifactUrl////".Split('/')[2]).Split('.')[0]
$artifactType = ("$artifactUrl////".Split('/')[3])
$version = ("$artifactUrl////".Split('/')[4])
$country = ("$artifactUrl////".Split('/')[5])
$sasToken = "$($artifactUrl)?".Split('?')[1]
}
else {
$segments = "$artifact/////".Split('/')
$storageAccount = $segments[0];
$artifactType = $segments[1]; if ($artifactType -eq "") { $artifactType = 'Sandbox' }
$version = $segments[2]
$country = $segments[3]; if ($country -eq "") { $country = $settings.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
if (-not $artifactUrl) {
throw "No artifacts found for the artifact setting ($artifact) in $ALGoSettingsFile"
}
$version = $artifactUrl.Split('/')[4]
$storageAccount = $artifactUrl.Split('/')[2]
}

if ($settings.additionalCountries -or $country -ne $settings.country) {
if ($country -ne $settings.country) {
OutputWarning -message "artifact definition in $ALGoSettingsFile uses a different country ($country) than the country definition ($($settings.country))"
}
Write-Host "Checking Country and additionalCountries"
# 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
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 {
$countryArtifactUrl = $_.Split('?')[0] # remove sas token
$countryArtifactUrl.Split('/')[5] # get country
}
Write-Host "Countries with artifacts $($countries -join ',')"
$allowedCountries = $bcContainerHelperConfig.mapCountryCode.PSObject.Properties.Name + $countries | Select-Object -Unique
Write-Host "Allowed Country codes $($allowedCountries -join ',')"
if ($allowedCountries -notcontains $settings.country) {
throw "Country ($($settings.country)), specified in $ALGoSettingsFile is not a valid country code."
}
$illegalCountries = $settings.additionalCountries | Where-Object { $allowedCountries -notcontains $_ }
if ($illegalCountries) {
throw "additionalCountries contains one or more invalid country codes ($($illegalCountries -join ",")) in $ALGoSettingsFile."
}
$artifactUrl = $artifactUrl.Replace($artifactUrl.Split('/')[4],$atArtifactUrl.Split('/')[4])
}
else {
Write-Host "Downloading artifacts from $($artifactUrl.Split('?')[0])"
$folders = Download-Artifacts -artifactUrl $artifactUrl -includePlatform -ErrorAction SilentlyContinue
if (-not ($folders)) {
throw "Unable to download artifacts from $($artifactUrl.Split('?')[0]), please check $ALGoSettingsFile."
}
}
$settings.artifact = $artifactUrl

if ([Version]$settings.applicationDependency -gt [Version]$version) {
throw "Application dependency is set to $($settings.applicationDependency), which isn't compatible with the artifact version $version"
}
Expand Down
16 changes: 11 additions & 5 deletions Actions/CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,20 @@ try {

invoke-git status

$templateUrl = "$templateUrl@$templateBranch"
$RepoSettingsFile = ".github\AL-Go-Settings.json"
if (Test-Path $RepoSettingsFile) {
$repoSettings = Get-Content $repoSettingsFile -Encoding UTF8 | ConvertFrom-Json | ConvertTo-HashTable
$repoSettings = Get-Content $repoSettingsFile -Encoding UTF8 | ConvertFrom-Json
}
else {
$repoSettings = @{}
$repoSettings = [PSCustomObject]@{}
}
if ($repoSettings.PSObject.Properties.Name -eq "templateUrl") {
$repoSettings.templateUrl = $templateUrl
}
else {
$repoSettings | Add-Member -MemberType NoteProperty -Name "templateUrl" -Value $templateUrl
}
$repoSettings.templateUrl = "$templateUrl@$templateBranch"
$repoSettings | ConvertTo-Json -Depth 99 | Set-Content $repoSettingsFile -Encoding UTF8

$updateFiles | ForEach-Object {
Expand Down Expand Up @@ -240,10 +246,10 @@ try {
}
catch {
if ($directCommit) {
throw "Failed to update AL-Go System Files. Make sure that the personal access token, defined in the secret called GhTokenWorkflow, is not expired and it has permission to update workflows."
throw "Failed to update AL-Go System Files. Make sure that the personal access token, defined in the secret called GhTokenWorkflow, is not expired and it has permission to update workflows. (Error was $($_.Exception.Message))"
}
else {
throw "Failed to create a pull-request to AL-Go System Files. Make sure that the personal access token, defined in the secret called GhTokenWorkflow, is not expired and it has permission to update workflows."
throw "Failed to create a pull-request to AL-Go System Files. Make sure that the personal access token, defined in the secret called GhTokenWorkflow, is not expired and it has permission to update workflows. (Error was $($_.Exception.Message))"
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ function Get-dependencies {
$dependency | Add-Member -name "Projects" -MemberType NoteProperty -Value "*"
}
if (-not ($dependency.PsObject.Properties.name -eq "release_status")) {
$dependency | Add-Member -name "release_status" -MemberType NoteProperty -Value "latestBuild"
$dependency | Add-Member -name "release_status" -MemberType NoteProperty -Value "release"
}

Write-Host "Getting releases from $($dependency.repo)"
# TODO better error messages

$repository = ([uri]$dependency.repo).AbsolutePath.Replace(".git", "").TrimStart("/")
if ($dependency.release_status -eq "latestBuild") {

# TODO it should check the branch and limit to a certain branch

Write-Host "Getting artifacts from $($dependency.repo)"
$artifacts = GetArtifacts -token $dependency.authTokenSecret -api_url $api_url -repository $repository -mask $mask
if ($dependency.version -ne "latest") {
$artifacts = $artifacts | Where-Object { ($_.tag_name -eq $dependency.version) }
Expand All @@ -50,6 +53,7 @@ function Get-dependencies {
}
else {

Write-Host "Getting releases from $($dependency.repo)"
$releases = GetReleases -api_url $api_url -token $dependency.authTokenSecret -repository $repository
if ($dependency.version -ne "latest") {
$releases = $releases | Where-Object { ($_.tag_name -eq $dependency.version) }
Expand Down
4 changes: 2 additions & 2 deletions Actions/ReadSettings/ReadSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ try {
$getSettings = @($settings.Keys)
}

if ($settings.appBuild -eq [int32]::MaxValue -and $settings.appRevision -eq [int32]::MaxValue) {
if ($settings.appBuild -eq [int32]::MaxValue) {
$settings.versioningStrategy = 15
}

Expand All @@ -65,7 +65,7 @@ try {
}
15 { # Use maxValue
$settings.appBuild = [Int32]::MaxValue
$settings.appRevision = [Int32]::MaxValue
$settings.appRevision = 0
}
default {
OutputError -message "Unknown version strategy $versionStrategy"
Expand Down
7 changes: 6 additions & 1 deletion Actions/RunPipeline/RunPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ try {
if (Test-Path $testResultsFiles) {
Remove-Item $testResultsFiles -Force
}


$buildOutputFile = Join-Path $baseFolder "BuildOutput.txt"

"containerName=$containerName" | Add-Content $ENV:GITHUB_ENV

Set-Location $baseFolder
Expand Down Expand Up @@ -237,11 +239,14 @@ try {
-installApps $installApps `
-installTestApps $installTestApps `
-installOnlyReferencedApps:$repo.installOnlyReferencedApps `
-generateDependencyArtifact:$repo.generateDependencyArtifact `
-updateDependencies:$repo.updateDependencies `
-previousApps $previousApps `
-appFolders $repo.appFolders `
-testFolders $repo.testFolders `
-doNotBuildTests:$doNotBuildTests `
-doNotRunTests:$doNotRunTests `
-buildOutputFile $buildOutputFile `
-testResultsFile $testResultsFile `
-testResultsFormat 'JUnit' `
-installTestRunner:$repo.installTestRunner `
Expand Down
1 change: 1 addition & 0 deletions Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The repository settings are only read from the repository settings file (.github
| Name | Description | Default value |
| :-- | :-- | :-- |
| artifact | Determines the artifacts used for building and testing the app.<br />This setting can either be an absolute pointer to Business Central artifacts (https://... - rarely used) or it can be a search specification for artifacts (\<storageaccount\>/\<type\>/\<version\>/\<country\>/\<select\>/\<sastoken\>).<br />If not specified, the artifacts used will be the latest sandbox artifacts from the country specified in the country setting. | |
| updateDependencies | Setting updateDependencies to true causes AL-Go to build your app against the first compatible Business Central build and set the dependency version numbers in the app.json accordingly during build. All version numbers in the built app will be set to the version number used during compilation. | false |
| companyName | Company name selected in the database, used for running the CI/CD workflow. Default is to use the default company in the selected Business Central localization. | |
| versioningStrategy | The versioning strategy determines how versioning is performed in this project. The version number of an app consists of 4 tuples: **Major**.**Minor**.**Build**.**Revision**. **Major** and **Minor** are read from the app.json file for each app. **Build** and **Revision** are calculated. Currently 3 versioning strategies are supported:<br />**0** = **Build** is the **github [run_number](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)** for the CI/CD workflow, increased by the **runNumberOffset** setting value (if specified). **Revision** is the **github [run_attempt](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)** subtracted 1.<br />**1** = **Build** is the **github [run_id](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)** for the repository. **Revision** is the **github [run_attempt](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)** subtracted 1.<br />**2** = **Build** is the current date as **yyyyMMdd**. **Revision** is the current time as **hhmmss**. Date and time are always **UTC** timezone to avoid problems during daylight savings time change. Note that if two CI/CD workflows are started within the same second, this could yield to identical version numbers from two differentruns.<br />**+16** use **repoVersion** setting as **appVersion** (**Major** and **Minor**) for all apps | 0 |
| additionalCountries | This property can be set to an additional number of countries to compile, publish and test your app against during workflows. Note that this setting can be different in NextMajor and NextMinor workflows compared to the CI/CD workflow, by specifying a different value in a workflow settings file. | [ ] |
Expand Down
8 changes: 4 additions & 4 deletions Templates/AppSource App/.AL-Go/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"country": "us",
"AppSourceCopMandatoryAffixes": [
"country": "us",
"AppSourceCopMandatoryAffixes": [
"<affix>"
],
"appFolders": [
"appFolders": [
],
"testFolders": [
"testFolders": [
]
}
4 changes: 2 additions & 2 deletions Templates/AppSource App/.github/AL-Go-Settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "AppSource App",
"templateUrl": "https://github.com/microsoft/AL-Go-AppSource@main"
"type": "AppSource App",
"templateUrl": "https://github.com/microsoft/AL-Go-AppSource@main"
}
Loading

0 comments on commit 7dc1ee1

Please sign in to comment.