diff --git a/Actions/AL-Go-Helper.ps1 b/Actions/AL-Go-Helper.ps1 index c87d68703..77ce7cc2f 100644 --- a/Actions/AL-Go-Helper.ps1 +++ b/Actions/AL-Go-Helper.ps1 @@ -401,6 +401,7 @@ function ReadSettings { "MicrosoftTelemetryConnectionString" = $MicrosoftTelemetryConnectionString "PartnerTelemetryConnectionString" = "" "SendExtendedTelemetryToMicrosoft" = $false + "Environments" = @() } $gitHubFolder = ".github" @@ -543,6 +544,32 @@ function AnalyzeRepo { } } + if (-not (@($settings.appFolders)+@($settings.testFolders))) { + Get-ChildItem -Path $baseFolder -Directory | Where-Object { Test-Path -Path (Join-Path $_.FullName "app.json") } | ForEach-Object { + $folder = $_ + $appJson = Get-Content (Join-Path $folder.FullName "app.json") -Encoding UTF8 | ConvertFrom-Json + $isTestApp = $false + if ($appJson.PSObject.Properties.Name -eq "dependencies") { + $appJson.dependencies | ForEach-Object { + if ($_.PSObject.Properties.Name -eq "AppId") { + $id = $_.AppId + } + else { + $id = $_.Id + } + if ($testRunnerApps.Contains($id)) { + $isTestApp = $true + } + } + } + if ($isTestApp) { + $settings.testFolders += @($_.Name) + } + else { + $settings.appFolders += @($_.Name) + } + } + } Write-Host "Checking appFolders and testFolders" $dependencies = [ordered]@{} $true, $false | ForEach-Object { @@ -576,7 +603,7 @@ function AnalyzeRepo { $settings.appFolders = @($settings.appFolders | Where-Object { $_ -ne $folderName }) } else { - $settings.appFolders = @($settings.appFolders | Where-Object { $_ -ne $folderName }) + $settings.testFolders = @($settings.testFolders | Where-Object { $_ -ne $folderName }) } } else { @@ -1035,7 +1062,7 @@ function CreateDevEnv { exit } - if ($kind -eq "local" -and $settings.type -eq "AppSource App" ) { + if ($kind -eq "local" -and $repo.type -eq "AppSource App" ) { if ($licenseFileUrl -eq "") { OutputError -message "When building an AppSource App, you need to create a secret called LicenseFileUrl, containing a secure URL to your license file with permission to the objects used in the app." exit @@ -1044,7 +1071,22 @@ function CreateDevEnv { $installApps = $repo.installApps $installTestApps = $repo.installTestApps - + + if ($repo.versioningStrategy -eq -1) { + if ($kind -eq "cloud") { throw "Versioningstrategy -1 cannot be used on cloud" } + $artifactVersion = [Version]$repo.artifact.Split('/')[4] + $runAlPipelineParams += @{ + "appVersion" = "$($artifactVersion.Major).$($artifactVersion.Minor)" + "appBuild" = "$($artifactVersion.Build)" + "appRevision" = "$($artifactVersion.Revision)" + } + } + elseif (($repo.versioningStrategy -band 16) -eq 16) { + $runAlPipelineParams += @{ + "appVersion" = $repo.repoVersion + } + } + $buildArtifactFolder = Join-Path $baseFolder "output" if (Test-Path $buildArtifactFolder) { Get-ChildItem -Path $buildArtifactFolder -Include * -File | ForEach-Object { $_.Delete()} @@ -1117,7 +1159,7 @@ function CreateDevEnv { $baseApp = Get-BcPublishedApps -bcAuthContext $authContext -environment $environmentName | Where-Object { $_.Name -eq "Base Application" } } else { - $countryCode = $settings.country + $countryCode = $repo.country New-BcEnvironment -bcAuthContext $authContext -environment $environmentName -countryCode $countryCode -environmentType "Sandbox" | Out-Null do { Start-Sleep -Seconds 10 diff --git a/Actions/AddExistingApp/AddExistingApp.ps1 b/Actions/AddExistingApp/AddExistingApp.ps1 index 921364bed..85ac92525 100644 --- a/Actions/AddExistingApp/AddExistingApp.ps1 +++ b/Actions/AddExistingApp/AddExistingApp.ps1 @@ -187,18 +187,19 @@ try { try { $settingsJsonFile = Join-Path $baseFolder $ALGoSettingsFile $SettingsJson = Get-Content $settingsJsonFile -Encoding UTF8 | ConvertFrom-Json - if ($ttype -eq "Test App") { - if ($SettingsJson.testFolders -notcontains $foldername) { - $SettingsJson.testFolders += @($folderName) + if (@($settingsJson.appFolders)+@($settingsJson.testFolders)) { + if ($ttype -eq "Test App") { + if ($SettingsJson.testFolders -notcontains $foldername) { + $SettingsJson.testFolders += @($folderName) + } } - } - else { - if ($SettingsJson.appFolders -notcontains $foldername) { - $SettingsJson.appFolders += @($folderName) + else { + if ($SettingsJson.appFolders -notcontains $foldername) { + $SettingsJson.appFolders += @($folderName) + } } + $SettingsJson | ConvertTo-Json -Depth 99 | Set-Content -Path $settingsJsonFile -Encoding UTF8 } - - $SettingsJson | ConvertTo-Json -Depth 99 | Set-Content -Path $settingsJsonFile -Encoding UTF8 } catch { throw "$ALGoSettingsFile is malformed. Error: $($_.Exception.Message)" diff --git a/Actions/CreateApp/AppHelper.psm1 b/Actions/CreateApp/AppHelper.psm1 index 1d19412df..3df6b7756 100644 --- a/Actions/CreateApp/AppHelper.psm1 +++ b/Actions/CreateApp/AppHelper.psm1 @@ -35,7 +35,8 @@ function UpdateManifest [string] $name, [string] $publisher, [string] $version, - [string[]] $idrange + [string[]] $idrange, + [switch] $AddTestDependencies ) { #Modify app.json @@ -47,6 +48,23 @@ function UpdateManifest $appJson.Version = $version $appJson.idRanges[0].from = [int]$idrange[0] $appJson.idRanges[0].to = [int]$idrange[1] + if ($AddTestDependencies) { + $appJson.dependencies += @( + @{ + "id" = "dd0be2ea-f733-4d65-bb34-a28f4624fb14" + "publisher" = "Microsoft" + "name" = "Library Assert" + "version" = $appJson.Application + }, + @{ + "id" = "e7320ebb-08b3-4406-b1ec-b4927d3e280b" + "publisher" = "Microsoft" + "name" = "Any" + "version" = $appJson.Application + } + ) + + } $appJson | ConvertTo-Json -depth 99 | Set-Content $appJsonFile -Encoding UTF8 } @@ -103,7 +121,7 @@ function New-SampleTestApp New-Item -Path "$($destinationPath)\.vscode" -ItemType Directory -Force | Out-Null Copy-Item -path "$($alTemplatePath)\.vscode\launch.json" -Destination "$($destinationPath)\.vscode\launch.json" - UpdateManifest -appJsonFile "$($destinationPath)\app.json" -name $name -publisher $publisher -idrange $idrange -version $version + UpdateManifest -appJsonFile "$($destinationPath)\app.json" -name $name -publisher $publisher -idrange $idrange -version $version -AddTestDependencies UpdateALFile -destinationFolder $destinationPath -alFileName "HelloWorld.Test.al" -startId $idrange[0] } diff --git a/Actions/CreateApp/CreateApp.ps1 b/Actions/CreateApp/CreateApp.ps1 index feaf095de..1ffbfd09b 100644 --- a/Actions/CreateApp/CreateApp.ps1 +++ b/Actions/CreateApp/CreateApp.ps1 @@ -63,17 +63,19 @@ try { try { $settingsJsonFile = Join-Path $baseFolder $ALGoSettingsFile $SettingsJson = Get-Content $settingsJsonFile -Encoding UTF8 | ConvertFrom-Json - if ($type -eq "Test App") { - if ($SettingsJson.testFolders -notcontains $foldername) { - $SettingsJson.testFolders += @($folderName) + if (@($settingsJson.appFolders)+@($settingsJson.testFolders)) { + if ($type -eq "Test App") { + if ($SettingsJson.testFolders -notcontains $foldername) { + $SettingsJson.testFolders += @($folderName) + } } - } - else { - if ($SettingsJson.appFolders -notcontains $foldername) { - $SettingsJson.appFolders += @($folderName) + else { + if ($SettingsJson.appFolders -notcontains $foldername) { + $SettingsJson.appFolders += @($folderName) + } } + $SettingsJson | ConvertTo-Json -Depth 99 | Set-Content -Path $settingsJsonFile -Encoding UTF8 } - $SettingsJson | ConvertTo-Json -Depth 99 | Set-Content -Path $settingsJsonFile -Encoding UTF8 } catch { throw "A malformed $ALGoSettingsFile is encountered.$([environment]::Newline) $($_.Exception.Message)" @@ -85,7 +87,7 @@ try { } if ($type -eq "Test App") { - New-SampleTestApp -destinationPath (Join-Path $baseFolder $folderName) -name $name -publisher $publisher -version $appVersion -idrange $ids + New-SampleTestApp -destinationPath (Join-Path $baseFolder $folderName) -name $name -publisher $publisher -version $appVersion -idrange $ids } else { New-SampleApp -destinationPath (Join-Path $baseFolder $folderName) -name $name -publisher $publisher -version $appVersion -idrange $ids diff --git a/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 b/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 index f8b59af90..78280e830 100644 --- a/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 +++ b/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 @@ -73,21 +73,21 @@ try { if ($modifyApps) { Write-Host "Versioning strategy $($settingsJson.VersioningStrategy) is set. The version number in the apps will be changed." - 'appFolders', 'testFolders' | ForEach-Object { - if ($SettingsJson.PSObject.Properties.Name -eq $_) { - $settingsJson."$_" | ForEach-Object { - Write-Host "Modifying app.json in folder $project\$_" - $appJsonFile = Join-Path "$project\$_" "app.json" - if (Test-Path $appJsonFile) { - try { - $appJson = Get-Content $appJsonFile -Encoding UTF8 | ConvertFrom-Json - $appJson.Version = "$($newVersion.Major).$($newVersion.Minor).0.0" - $appJson | ConvertTo-Json -Depth 99 | Set-Content $appJsonFile -Encoding UTF8 - } - catch { - throw "Application manifest file($appJsonFile) is malformed." - } - } + $folders = @('appFolders', 'testFolders' | ForEach-Object { if ($SettingsJson.PSObject.Properties.Name -eq $_) { $settingsJson."$_" } }) + if (-not ($folders)) { + $folders = Get-ChildItem -Path $project -Directory | Where-Object { Test-Path (Join-Path $_.FullName 'app.json') } | ForEach-Object { $_.Name } + } + $folders | ForEach-Object { + Write-Host "Modifying app.json in folder $project\$_" + $appJsonFile = Join-Path "$project\$_" "app.json" + if (Test-Path $appJsonFile) { + try { + $appJson = Get-Content $appJsonFile -Encoding UTF8 | ConvertFrom-Json + $appJson.Version = "$($newVersion.Major).$($newVersion.Minor).0.0" + $appJson | ConvertTo-Json -Depth 99 | Set-Content $appJsonFile -Encoding UTF8 + } + catch { + throw "Application manifest file($appJsonFile) is malformed." } } } diff --git a/Actions/ReadSettings/ReadSettings.ps1 b/Actions/ReadSettings/ReadSettings.ps1 index d6446ae6e..c8a2074dd 100644 --- a/Actions/ReadSettings/ReadSettings.ps1 +++ b/Actions/ReadSettings/ReadSettings.ps1 @@ -48,27 +48,29 @@ try { $settings.versioningStrategy = 15 } - if ($getSettings -contains 'appBuild' -or $getSettings -contains 'appRevision') { - switch ($settings.versioningStrategy -band 15) { - 0 { # Use RUN_NUMBER and RUN_ATTEMPT - $settings.appBuild = $settings.runNumberOffset + [Int32]($ENV:GITHUB_RUN_NUMBER) - $settings.appRevision = [Int32]($ENV:GITHUB_RUN_ATTEMPT) - 1 - } - 1 { # Use RUN_ID and RUN_ATTEMPT - $settings.appBuild = [Int32]($ENV:GITHUB_RUN_ID) - $settings.appRevision = [Int32]($ENV:GITHUB_RUN_ATTEMPT) - 1 - } - 2 { # USE DATETIME - $settings.appBuild = [Int32]([DateTime]::UtcNow.ToString('yyyyMMdd')) - $settings.appRevision = [Int32]([DateTime]::UtcNow.ToString('hhmmss')) - } - 15 { # Use maxValue - $settings.appBuild = [Int32]::MaxValue - $settings.appRevision = [Int32]::MaxValue - } - default { - OutputError -message "Unknown version strategy $versionStrategy" - exit + if ($settings.versioningstrategy -ne -1) { + if ($getSettings -contains 'appBuild' -or $getSettings -contains 'appRevision') { + switch ($settings.versioningStrategy -band 15) { + 0 { # Use RUN_NUMBER and RUN_ATTEMPT + $settings.appBuild = $settings.runNumberOffset + [Int32]($ENV:GITHUB_RUN_NUMBER) + $settings.appRevision = [Int32]($ENV:GITHUB_RUN_ATTEMPT) - 1 + } + 1 { # Use RUN_ID and RUN_ATTEMPT + $settings.appBuild = [Int32]($ENV:GITHUB_RUN_ID) + $settings.appRevision = [Int32]($ENV:GITHUB_RUN_ATTEMPT) - 1 + } + 2 { # USE DATETIME + $settings.appBuild = [Int32]([DateTime]::UtcNow.ToString('yyyyMMdd')) + $settings.appRevision = [Int32]([DateTime]::UtcNow.ToString('hhmmss')) + } + 15 { # Use maxValue + $settings.appBuild = [Int32]::MaxValue + $settings.appRevision = [Int32]::MaxValue + } + default { + OutputError -message "Unknown version strategy $versionStrategy" + exit + } } } } @@ -90,12 +92,8 @@ try { Write-Host "set-output name=GitHubRunnerJson::$githubRunner" if ($getprojects) { - if (Test-Path ".AL-Go" -PathType Container) { - $projects = @(".") - } - else { - $projects = @(Get-ChildItem -Path $ENV:GITHUB_WORKSPACE -Directory | Where-Object { Test-Path (Join-Path $_.FullName ".AL-Go") -PathType Container } | ForEach-Object { $_.Name }) - Write-Host "All Projects: $($projects -join ', ')" + $projects = @(Get-ChildItem -Path $ENV:GITHUB_WORKSPACE -Directory | Where-Object { Test-Path (Join-Path $_.FullName ".AL-Go") -PathType Container } | ForEach-Object { $_.Name }) + if ($projects) { if (($ENV:GITHUB_EVENT_NAME -eq "pull_request" -or $ENV:GITHUB_EVENT_NAME -eq "push") -and !$settings.alwaysBuildAllProjects) { $headers = @{ "Authorization" = "token $token" @@ -117,6 +115,10 @@ try { } } } + if (Test-Path ".AL-Go" -PathType Container) { + $projects += @(".") + } + Write-Host "All Projects: $($projects -join ', ')" if ($projects.Count -eq 1) { $projectsJSon = "[$($projects | ConvertTo-Json -compress)]" } @@ -137,7 +139,7 @@ try { } $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments" try { - $environments = @((Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $url | ConvertFrom-Json).environments | Where-Object { + $environments = @($settings.Environments)+@((Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $url | ConvertFrom-Json).environments | Where-Object { if ($includeProduction) { $_.Name -like $getEnvironments -or $_.Name -like "$getEnvironments (Production)" } diff --git a/Actions/RunPipeline/RunPipeline.ps1 b/Actions/RunPipeline/RunPipeline.ps1 index c4ead81b4..350e9f0c2 100644 --- a/Actions/RunPipeline/RunPipeline.ps1 +++ b/Actions/RunPipeline/RunPipeline.ps1 @@ -64,7 +64,7 @@ try { exit } - if ($settings.type -eq "AppSource App" ) { + if ($repo.type -eq "AppSource App" ) { if ($licenseFileUrl -eq "") { OutputError -message "When building an AppSource App, you need to create a secret called LicenseFileUrl, containing a secure URL to your license file with permission to the objects used in the app." exit @@ -119,10 +119,10 @@ try { $doNotBuildTests = $repo.doNotBuildTests $doNotRunTests = $repo.doNotRunTests - if ($settings.appDependencyProbingPaths) { + if ($repo.appDependencyProbingPaths) { Write-Host "Downloading dependencies ..." - $installApps += Get-dependencies -probingPathsJson $settings.appDependencyProbingPaths -token $token -mask "-Apps-" - Get-dependencies -probingPathsJson $settings.appDependencyProbingPaths -token $token -mask "-TestApps-" | ForEach-Object { + $installApps += Get-dependencies -probingPathsJson $repo.appDependencyProbingPaths -token $token -mask "-Apps-" + Get-dependencies -probingPathsJson $repo.appDependencyProbingPaths -token $token -mask "-TestApps-" | ForEach-Object { $installTestApps += "($_)" } } @@ -183,7 +183,15 @@ try { $environmentName = "" $CreateRuntimePackages = $false - if (($repo.versioningStrategy -band 16) -eq 16) { + if ($repo.versioningStrategy -eq -1) { + $artifactVersion = [Version]$repo.artifact.Split('/')[4] + $runAlPipelineParams += @{ + "appVersion" = "$($artifactVersion.Major).$($artifactVersion.Minor)" + } + $appBuild = $artifactVersion.Build + $appRevision = $artifactVersion.Revision + } + elseif (($repo.versioningStrategy -band 16) -eq 16) { $runAlPipelineParams += @{ "appVersion" = $repo.repoVersion } diff --git a/Internal/Deploy.ps1 b/Internal/Deploy.ps1 index e066836e8..e8ce6d434 100644 --- a/Internal/Deploy.ps1 +++ b/Internal/Deploy.ps1 @@ -331,10 +331,14 @@ try { if (!(Test-Path $dstFilePath -PathType Container)) { New-Item $dstFilePath -ItemType Directory | Out-Null } + $useBranch = $config.branch + if ($_.Name -eq "AL-Go-Settings.json") { + $useBranch = $branch + } $lines = ([string](Get-Content -Raw -path $srcFile)).Split("`n") "actionsRepo","perTenantExtensionRepo","appSourceAppRepo" | ForEach-Object { $regex = "^(.*)$($originalOwnerAndRepo."$_")(.*)$originalBranch(.*)$" - $replace = "`$1$($config.githubOwner)/$($config."$_")`$2$($config.branch)`$3" + $replace = "`$1$($config.githubOwner)/$($config."$_")`$2$($useBranch)`$3" $lines = $lines | ForEach-Object { $_ -replace $regex, $replace } } $lines -join "`n" | Set-Content $dstFile -Force -NoNewline