Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

<#
Expand Down
3 changes: 2 additions & 1 deletion Actions/RunHook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) != ''
Comment thread
freddydk marked this conversation as resolved.
uses: microsoft/AL-Go-Actions/RunHook@main
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
hookName: BuildInitialize
parametersJson: |
{
"buildMode": "${{ inputs.buildMode }}",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if buildmode should just be a standard parameter like project is

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on whether hooks will be available in non-build workflows as well, but then project maybe shouldn't be a standard parameter?
Let me know what you conclude?

"buildIt": ${{ steps.DetermineBuildProject.outputs.BuildIt == 'True' }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than passing BuildIt as a parameter, wouldn't it make more sense to just skip the hook altogether if BuildIt is false? Not sure what a hook would do in a job that doesnt build anyway.

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it actually will invoke the _BuildALGoProject (to copy the files), but it would be OK for my scenario.
I also added a Cleanup hook - with these two hooks, I can integrate Fkh to AL-Go and not need anything but that.
Obviously, I would copy some overrides to the .AL-Go folder during build, but I could modify those when you guys modify the build process and keep all changes centralized.

This is how my BuildInitialize and BuildCleanup looks:

Param(
    [Hashtable] $parameters
)

# AL-Go Hook

$buildIt = $parameters.buildIt

if (-not $buildIt) {
    Write-Host "BuildIt is false, no need to copy fkh scripts"
    return
}

$ENV:FKH_BACKEND_URL = "https://fkh-freddydk-backend.azurewebsites.net/api"
$ENV:FKH_TIMEZONE = "Europe/Copenhagen"

Write-Host "Install Freddy's Kubernetes Helper & Business Central Development Tools"
dotnet tool install -g fkh --prerelease
dotnet tool install -g Microsoft.Dynamics.BusinessCentral.Development.Tools

fkh applyALGoOverrides --output $PSScriptRoot

and Cleanup:

Param(
    [Hashtable] $parameters
)

# AL-Go Hook

$project = $parameters.project
$buildMode = $parameters.buildMode
$buildIt = $parameters.buildIt

if (-not $buildIt) {
    Write-Host "BuildIt is false, no need to remove container"
    return
}

$ENV:FKH_BACKEND_URL = "https://fkh-freddydk-backend.azurewebsites.net/api"
$ENV:FKH_TIMEZONE = "Europe/Copenhagen"

$parts = "$ENV:GITHUB_REPOSITORY". Split('/')
$containerName = "$($parts[0])-$($parts[1])-$($project)-$($buildMode)-$($ENV:GITHUB_RUN_ID)".ToLower() -replace "[^a-z0-9\-]"

fkh RemoveContainer --name $containerName --useOIDC

I can easily modify the PR to skip the hooks if buildIt is false - I am not going to use that.

}

- name: Read secrets
id: ReadSecrets
if: steps.DetermineBuildProject.outputs.BuildIt == 'True'
Expand Down Expand Up @@ -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' }}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) != ''
Comment thread
freddydk marked this conversation as resolved.
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'
Expand Down Expand Up @@ -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' }}
}
4 changes: 4 additions & 0 deletions Tests/RunHook.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 @"
Expand Down