|
| 1 | +Param( |
| 2 | + [Parameter(HelpMessage = "The GitHub token running the action", Mandatory = $false)] |
| 3 | + [string] $token, |
| 4 | + [Parameter(HelpMessage = "ArtifactUrl to use for the build", Mandatory = $false)] |
| 5 | + [string] $artifact = "", |
| 6 | + [Parameter(HelpMessage = "Project folder", Mandatory = $false)] |
| 7 | + [string] $project = "", |
| 8 | + [Parameter(HelpMessage = "Specifies a mode to use for the build steps", Mandatory = $false)] |
| 9 | + [string] $buildMode = 'Default', |
| 10 | + [Parameter(HelpMessage = "A path to a JSON-formatted list of dependency apps", Mandatory = $false)] |
| 11 | + [string] $dependencyAppsJson = '', |
| 12 | + [Parameter(HelpMessage = "A path to a JSON-formatted list of dependency test apps", Mandatory = $false)] |
| 13 | + [string] $dependencyTestAppsJson = '', |
| 14 | + [Parameter(HelpMessage = "RunId of the baseline workflow run", Mandatory = $false)] |
| 15 | + [string] $baselineWorkflowRunId = '0', |
| 16 | + [Parameter(HelpMessage = "SHA of the baseline workflow run", Mandatory = $false)] |
| 17 | + [string] $baselineWorkflowSHA = '' |
| 18 | +) |
| 19 | + |
| 20 | +. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve) |
| 21 | +Import-Module (Join-Path -Path $PSScriptRoot "..\.Modules\CompileFromWorkspace.psm1" -Resolve) |
| 22 | +Import-Module (Join-Path $PSScriptRoot '..\TelemetryHelper.psm1' -Resolve) |
| 23 | +Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\DetermineProjectsToBuild\DetermineProjectsToBuild.psm1" -Resolve) -DisableNameChecking |
| 24 | +DownloadAndImportBcContainerHelper |
| 25 | + |
| 26 | +# ANALYZE - Analyze the repository and determine settings |
| 27 | +$baseFolder = (Get-BasePath) |
| 28 | +$settings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable |
| 29 | +$settings = AnalyzeRepo -settings $settings -baseFolder $baseFolder -project $project -doNotCheckArtifactSetting |
| 30 | +$settings = CheckAppDependencyProbingPaths -settings $settings -token $token -baseFolder $baseFolder -project $project |
| 31 | + |
| 32 | +# Check if there are any app folders or test app folders to compile |
| 33 | +if ($settings.appFolders.Count -eq 0 -and $settings.testFolders.Count -eq 0) { |
| 34 | + Write-Host "No app folders or test app folders specified for compilation. Skipping compilation step." |
| 35 | + return |
| 36 | +} |
| 37 | + |
| 38 | +$projectFolder = Join-Path $baseFolder $project |
| 39 | +Push-Location $projectFolder |
| 40 | +try { |
| 41 | + # Set up output folders |
| 42 | + $buildArtifactFolder = Join-Path $projectFolder ".buildartifacts" |
| 43 | + $appOutputFolder = Join-Path $buildArtifactFolder "Apps" |
| 44 | + $testAppOutputFolder = Join-Path $buildArtifactFolder "TestApps" |
| 45 | + if (-not (Test-Path $buildArtifactFolder)) { |
| 46 | + New-Item $buildArtifactFolder -ItemType Directory -Force | Out-Null |
| 47 | + } |
| 48 | + if (-not (Test-Path $appOutputFolder)) { |
| 49 | + New-Item $appOutputFolder -ItemType Directory -Force | Out-Null |
| 50 | + } |
| 51 | + if (-not (Test-Path $testAppOutputFolder)) { |
| 52 | + New-Item $testAppOutputFolder -ItemType Directory -Force | Out-Null |
| 53 | + } |
| 54 | + |
| 55 | + # Check for precompile and postcompile overrides |
| 56 | + $scriptOverrides = Get-ScriptOverrides -ALGoFolderName (Join-Path $projectFolder ".AL-Go") -OverrideScriptNames @("PreCompileApp", "PostCompileApp") |
| 57 | + |
| 58 | + # Prepare build metadata |
| 59 | + $buildMetadata = Get-BuildMetadata |
| 60 | + |
| 61 | + # Get version number |
| 62 | + $versionNumber = Get-VersionNumber -Settings $settings |
| 63 | + |
| 64 | + # Get ruleset file if specified |
| 65 | + $rulesetPath = $settings.rulesetFile |
| 66 | + if ($settings.rulesetFile) { |
| 67 | + $rulesetPath = Join-Path $projectFolder $settings.rulesetFile -Resolve |
| 68 | + if (-not (Test-Path $rulesetPath)) { |
| 69 | + throw "Ruleset file specified in settings.rulesetFile not found at path '$rulesetPath'." |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + # Read existing install apps and test apps from JSON files |
| 74 | + $dependencyApps = @() |
| 75 | + $dependencyTestApps = @() |
| 76 | + |
| 77 | + if ($dependencyAppsJson -and (Test-Path $dependencyAppsJson)) { |
| 78 | + try { |
| 79 | + $dependencyApps += Get-Content -Path $dependencyAppsJson | ConvertFrom-Json |
| 80 | + } |
| 81 | + catch { |
| 82 | + throw "Failed to parse JSON file at path '$dependencyAppsJson'. Error: $($_.Exception.Message)" |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + if ($dependencyTestAppsJson -and (Test-Path $dependencyTestAppsJson)) { |
| 87 | + try { |
| 88 | + $dependencyTestApps += Get-Content -Path $dependencyTestAppsJson | ConvertFrom-Json |
| 89 | + } |
| 90 | + catch { |
| 91 | + throw "Failed to parse JSON file at path '$dependencyTestAppsJson'. Error: $($_.Exception.Message)" |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + # Set up a compiler folder |
| 96 | + $containerName = GetContainerName($project) |
| 97 | + $cacheFolder = "" |
| 98 | + if ($settings.gitHubRunner -like "windows-*" -or $settings.gitHubRunner -like "ubuntu-*") { |
| 99 | + # On GitHub-hosted runners, use a folder in the runner temp directory for caching to speed up subsequent builds |
| 100 | + $cacheFolder = Join-Path $ENV:RUNNER_TEMP ".artifactcache" |
| 101 | + } |
| 102 | + $compilerFolder = New-BcCompilerFolder -artifactUrl $artifact -containerName "$($containerName)compiler" -cacheFolder $cacheFolder |
| 103 | + $packageCachePath = Join-Path $compilerFolder "symbols" |
| 104 | + |
| 105 | + # Copy dependency apps to the package cache so the compiler can resolve them |
| 106 | + foreach ($appFile in $dependencyApps) { |
| 107 | + $appFile = $appFile.Trim('()') |
| 108 | + if ($appFile -and (Test-Path $appFile)) { |
| 109 | + Copy-Item -Path $appFile -Destination $packageCachePath -Force |
| 110 | + OutputDebug "Copied dependency app to package cache: $(Split-Path $appFile -Leaf)" |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + # Incremental Builds - Determine unmodified apps from baseline workflow run if applicable |
| 115 | + if ($baselineWorkflowSHA -and $baselineWorkflowRunId -ne '0' -and $settings.incrementalBuilds.mode -eq 'modifiedApps') { |
| 116 | + #TODO: Implement support for incremental builds (AB#620492) |
| 117 | + Write-Host "Incremental builds based on modified apps is not yet implemented." |
| 118 | + } |
| 119 | + |
| 120 | + if ((-not $settings.skipUpgrade) -and $settings.enableAppSourceCop) { |
| 121 | + # TODO: Missing implementation of around using latest release as a baseline (skipUpgrade) / Appsourcecop.json baseline implementation (AB#620310) |
| 122 | + Write-Host "Checking for required upgrades using AppSourceCop..." |
| 123 | + } |
| 124 | + |
| 125 | + # Update the app jsons with version number (and other properties) from the app manifest files |
| 126 | + Update-AppJsonProperties -Folders ($settings.appFolders + $settings.testFolders) ` |
| 127 | + -MajorMinorVersion $versionNumber.MajorMinorVersion -BuildNumber $versionNumber.BuildNumber -RevisionNumber $versionNumber.RevisionNumber ` |
| 128 | + -BuildBy $buildMetadata.BuildBy -BuildUrl $buildMetadata.BuildUrl |
| 129 | + |
| 130 | + # Collect common parameters for Build-AppsInWorkspace |
| 131 | + $buildParams = @{ |
| 132 | + CompilerFolder = $compilerFolder |
| 133 | + PackageCachePath = $packageCachePath |
| 134 | + LogDirectory = $buildArtifactFolder |
| 135 | + Ruleset = $rulesetPath |
| 136 | + AssemblyProbingPaths = (Get-AssemblyProbingPaths -CompilerFolder $compilerFolder) |
| 137 | + PreprocessorSymbols = $settings.preprocessorSymbols |
| 138 | + Features = $settings.features |
| 139 | + MajorMinorVersion = $versionNumber.MajorMinorVersion |
| 140 | + BuildNumber = $versionNumber.BuildNumber |
| 141 | + RevisionNumber = $versionNumber.RevisionNumber |
| 142 | + MaxCpuCount = $settings.workspaceCompilation.parallelism |
| 143 | + SourceRepositoryUrl = $buildMetadata.SourceRepositoryUrl |
| 144 | + SourceCommit = $buildMetadata.SourceCommit |
| 145 | + ReportSuppressedDiagnostics = $settings.reportSuppressedDiagnostics |
| 146 | + EnableExternalRulesets = $settings.enableExternalRulesets |
| 147 | + PreCompileApp = $scriptOverrides['PreCompileApp'] |
| 148 | + PostCompileApp = $scriptOverrides['PostCompileApp'] |
| 149 | + Analyzers = (Get-CodeAnalyzers -Settings $settings) |
| 150 | + CustomAnalyzers = (Get-CustomAnalyzers -Settings $settings -CompilerFolder $compilerFolder) |
| 151 | + } |
| 152 | + |
| 153 | + # Start compilation |
| 154 | + $appFiles = @() |
| 155 | + $testAppFiles = @() |
| 156 | + try { |
| 157 | + if ($settings.appFolders.Count -gt 0) { |
| 158 | + # Compile Apps |
| 159 | + $appFiles = Build-AppsInWorkspace @buildParams ` |
| 160 | + -Folders $settings.appFolders ` |
| 161 | + -OutFolder $appOutputFolder ` |
| 162 | + -AppType 'app' |
| 163 | + } |
| 164 | + |
| 165 | + if ($settings.testFolders.Count -gt 0) { |
| 166 | + if (-not ($settings.enableCodeAnalyzersOnTestApps)) { |
| 167 | + $buildParams.Analyzers = @() |
| 168 | + } |
| 169 | + |
| 170 | + # Compile Test Apps |
| 171 | + $testAppFiles = Build-AppsInWorkspace @buildParams ` |
| 172 | + -Folders $settings.testFolders ` |
| 173 | + -OutFolder $testAppOutputFolder ` |
| 174 | + -AppType 'testApp' |
| 175 | + } |
| 176 | + |
| 177 | + } finally { |
| 178 | + New-BuildOutputFile -BuildArtifactFolder $buildArtifactFolder -BuildOutputPath (Join-Path $projectFolder "BuildOutput.txt") -DisplayInConsole -FailOn $settings.failOn |
| 179 | + } |
| 180 | + |
| 181 | + # OUTPUT - Output the updated list of dependency apps and test apps to JSON files for downstream steps |
| 182 | + $dependencyApps += $appFiles |
| 183 | + $dependencyTestApps += $testAppFiles |
| 184 | + Trace-Information -message "Compilation completed. Compiled $(@($appFiles).Count) apps and $(@($testAppFiles).Count) test apps." |
| 185 | + |
| 186 | + ConvertTo-Json $dependencyApps -Depth 99 -Compress | Out-File -Encoding UTF8 -FilePath $dependencyAppsJson |
| 187 | + ConvertTo-Json $dependencyTestApps -Depth 99 -Compress | Out-File -Encoding UTF8 -FilePath $dependencyTestAppsJson |
| 188 | +} finally { |
| 189 | + Pop-Location |
| 190 | +} |
0 commit comments