From ec5e18214e098ee0a53a996426174f7dfae6d0db Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Wed, 27 May 2026 09:42:15 +0200 Subject: [PATCH 1/3] move the BuildInitialize hook to after determine build project --- .../.github/workflows/_BuildALGoProject.yaml | 21 ++++++++++++------- .../.github/workflows/_BuildALGoProject.yaml | 21 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml index 3b4f502ec..8b6e9e4c5 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 }}" + } + - name: Read secrets id: ReadSecrets if: 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..8b6e9e4c5 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 }}" + } + - name: Read secrets id: ReadSecrets if: steps.DetermineBuildProject.outputs.BuildIt == 'True' From d816c80b45de2daadd3c19ab5b990b02ee3798dc Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Wed, 27 May 2026 10:42:48 +0200 Subject: [PATCH 2/3] use boolean instead of string --- .../AppSource App/.github/workflows/_BuildALGoProject.yaml | 2 +- .../.github/workflows/_BuildALGoProject.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml index 8b6e9e4c5..9ee153efb 100644 --- a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml @@ -130,7 +130,7 @@ jobs: parametersJson: | { "buildMode": "${{ inputs.buildMode }}", - "buildIt": "${{ steps.DetermineBuildProject.outputs.BuildIt }}" + "buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }} } - name: Read secrets diff --git a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml index 8b6e9e4c5..9ee153efb 100644 --- a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml @@ -130,7 +130,7 @@ jobs: parametersJson: | { "buildMode": "${{ inputs.buildMode }}", - "buildIt": "${{ steps.DetermineBuildProject.outputs.BuildIt }}" + "buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }} } - name: Read secrets From 0a243a379b367e93b1d14ba80e8448acd9650552 Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Wed, 27 May 2026 11:16:51 +0200 Subject: [PATCH 3/3] Add BuildCleanup hook --- Actions/AL-Go-Helper.ps1 | 3 ++- Actions/RunHook/README.md | 3 ++- .../.github/workflows/_BuildALGoProject.yaml | 13 +++++++++++++ .../.github/workflows/_BuildALGoProject.yaml | 13 +++++++++++++ Tests/RunHook.Test.ps1 | 4 ++++ 5 files changed, 34 insertions(+), 2 deletions(-) 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 9ee153efb..8dd95668f 100644 --- a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml @@ -369,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 9ee153efb..8dd95668f 100644 --- a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml @@ -369,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 @"