Skip to content

Commit

Permalink
Merge pull request #76 from freddydk/main
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
freddydk authored Mar 30, 2022
2 parents 7c4e6ff + defd4c3 commit df02dd4
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 73 deletions.
50 changes: 46 additions & 4 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ function ReadSettings {
"MicrosoftTelemetryConnectionString" = $MicrosoftTelemetryConnectionString
"PartnerTelemetryConnectionString" = ""
"SendExtendedTelemetryToMicrosoft" = $false
"Environments" = @()
}

$gitHubFolder = ".github"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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()}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions Actions/AddExistingApp/AddExistingApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
22 changes: 20 additions & 2 deletions Actions/CreateApp/AppHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function UpdateManifest
[string] $name,
[string] $publisher,
[string] $version,
[string[]] $idrange
[string[]] $idrange,
[switch] $AddTestDependencies
)
{
#Modify app.json
Expand All @@ -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
}

Expand Down Expand Up @@ -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]
}

Expand Down
20 changes: 11 additions & 9 deletions Actions/CreateApp/CreateApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions Actions/IncrementVersionNumber/IncrementVersionNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand Down
58 changes: 30 additions & 28 deletions Actions/ReadSettings/ReadSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand All @@ -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"
Expand All @@ -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)]"
}
Expand All @@ -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)"
}
Expand Down
18 changes: 13 additions & 5 deletions Actions/RunPipeline/RunPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 += "($_)"
}
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion Internal/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df02dd4

Please sign in to comment.