diff --git a/Actions/AL-Go-Helper.ps1 b/Actions/AL-Go-Helper.ps1 index 07b1d00d4..6b542fe9c 100644 --- a/Actions/AL-Go-Helper.ps1 +++ b/Actions/AL-Go-Helper.ps1 @@ -60,7 +60,8 @@ $runAlPipelineOverrides = @( # $parameters argument. [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'alGoHooks', Justification = 'Used by RunHook action and Invoke-ALGoHook helper.')] $alGoHooks = @( - "BuildInitialize" + "BuildInitialize", + "BuildCleanup" ) <# diff --git a/Actions/RunHook/README.md b/Actions/RunHook/README.md index 526bc0902..8c842cefd 100644 --- a/Actions/RunHook/README.md +++ b/Actions/RunHook/README.md @@ -40,7 +40,8 @@ Write-Host "BuildInitialize hook running for project '$($parameters.project)'" | Hook name | Where it runs | Notes | | :-- | :-- | :-- | -| `BuildInitialize` | Build workflow (`_BuildALGoProject.yaml`), immediately after `Read settings` | AL-Go settings are available as environment variables; secrets are not yet read at this point. | +| `BuildInitialize` | Build workflow (`_BuildALGoProject.yaml`), after `Determine whether to build project` | AL-Go settings are available as environment variables; `buildMode` and `buildIt` can be passed via `parametersJson`. | +| `BuildCleanup` | Build workflow (`_BuildALGoProject.yaml`), as the last step with `if: always()` | Runs regardless of prior step success/failure and can be used for final reporting/cleanup logic. | ## INPUT diff --git a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml index 3b4f502ec..8dd95668f 100644 --- a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml @@ -111,14 +111,6 @@ jobs: buildMode: ${{ inputs.buildMode }} get: useCompilerFolder,workspaceCompilation,keyVaultCodesignCertificateName,doNotSignApps,doNotRunTests,doNotRunBcptTests,doNotRunpageScriptingTests,artifact,generateDependencyArtifact,trustedSigning,useGitSubmodules,trackALAlertsInGitHub,skipUpgrade - - name: Run Build Initialize hook - if: hashFiles(format('{0}/.AL-Go/BuildInitialize.ps1', inputs.project)) != '' - uses: microsoft/AL-Go-Actions/RunHook@main - with: - shell: ${{ inputs.shell }} - project: ${{ inputs.project }} - hookName: BuildInitialize - - name: Determine whether to build project id: DetermineBuildProject uses: microsoft/AL-Go-Actions/DetermineBuildProject@main @@ -128,6 +120,19 @@ jobs: project: ${{ inputs.project }} baselineWorkflowRunId: ${{ inputs.baselineWorkflowRunId }} + - name: Run Build Initialize hook + if: hashFiles(format('{0}/.AL-Go/BuildInitialize.ps1', inputs.project)) != '' + uses: microsoft/AL-Go-Actions/RunHook@main + with: + shell: ${{ inputs.shell }} + project: ${{ inputs.project }} + hookName: BuildInitialize + parametersJson: | + { + "buildMode": "${{ inputs.buildMode }}", + "buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }} + } + - name: Read secrets id: ReadSecrets if: steps.DetermineBuildProject.outputs.BuildIt == 'True' @@ -364,3 +369,16 @@ jobs: with: shell: ${{ inputs.shell }} project: ${{ inputs.project }} + + - name: Run Build Cleanup hook + if: always() && hashFiles(format('{0}/.AL-Go/BuildCleanup.ps1', inputs.project)) != '' && steps.DetermineBuildProject.outcome != 'skipped' + uses: microsoft/AL-Go-Actions/RunHook@main + with: + shell: ${{ inputs.shell }} + project: ${{ inputs.project }} + hookName: BuildCleanup + parametersJson: | + { + "buildMode": "${{ inputs.buildMode }}", + "buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }} + } diff --git a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml index 3b4f502ec..8dd95668f 100644 --- a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml @@ -111,14 +111,6 @@ jobs: buildMode: ${{ inputs.buildMode }} get: useCompilerFolder,workspaceCompilation,keyVaultCodesignCertificateName,doNotSignApps,doNotRunTests,doNotRunBcptTests,doNotRunpageScriptingTests,artifact,generateDependencyArtifact,trustedSigning,useGitSubmodules,trackALAlertsInGitHub,skipUpgrade - - name: Run Build Initialize hook - if: hashFiles(format('{0}/.AL-Go/BuildInitialize.ps1', inputs.project)) != '' - uses: microsoft/AL-Go-Actions/RunHook@main - with: - shell: ${{ inputs.shell }} - project: ${{ inputs.project }} - hookName: BuildInitialize - - name: Determine whether to build project id: DetermineBuildProject uses: microsoft/AL-Go-Actions/DetermineBuildProject@main @@ -128,6 +120,19 @@ jobs: project: ${{ inputs.project }} baselineWorkflowRunId: ${{ inputs.baselineWorkflowRunId }} + - name: Run Build Initialize hook + if: hashFiles(format('{0}/.AL-Go/BuildInitialize.ps1', inputs.project)) != '' + uses: microsoft/AL-Go-Actions/RunHook@main + with: + shell: ${{ inputs.shell }} + project: ${{ inputs.project }} + hookName: BuildInitialize + parametersJson: | + { + "buildMode": "${{ inputs.buildMode }}", + "buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }} + } + - name: Read secrets id: ReadSecrets if: steps.DetermineBuildProject.outputs.BuildIt == 'True' @@ -364,3 +369,16 @@ jobs: with: shell: ${{ inputs.shell }} project: ${{ inputs.project }} + + - name: Run Build Cleanup hook + if: always() && hashFiles(format('{0}/.AL-Go/BuildCleanup.ps1', inputs.project)) != '' && steps.DetermineBuildProject.outcome != 'skipped' + uses: microsoft/AL-Go-Actions/RunHook@main + with: + shell: ${{ inputs.shell }} + project: ${{ inputs.project }} + hookName: BuildCleanup + parametersJson: | + { + "buildMode": "${{ inputs.buildMode }}", + "buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }} + } diff --git a/Tests/RunHook.Test.ps1 b/Tests/RunHook.Test.ps1 index 42e1f520c..bf0aee646 100644 --- a/Tests/RunHook.Test.ps1 +++ b/Tests/RunHook.Test.ps1 @@ -160,6 +160,10 @@ Set-Content -Path '$sentinelPath' -Value `$parameters.value -Encoding UTF8 { Invoke-ALGoHook -Project 'project' -HookName 'BuildInitialize' -Parameters @{} } | Should -Not -Throw } + It 'Accepts BuildCleanup from the allow-list' { + { Invoke-ALGoHook -Project 'project' -HookName 'BuildCleanup' -Parameters @{} } | Should -Not -Throw + } + It 'Runs the hook script with the project folder as the current location' { $sentinelPath = Join-Path $script:workspace2 'cwd.txt' Set-Content -Path (Join-Path $script:projectPath2 '.AL-Go/BuildInitialize.ps1') -Value @"