Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run "Update AL-Go System Files" on multiple branches #1037

Merged
merged 102 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
de2ddd1
Run "Update AL-Go System Files" on multiple branches
mazhelez Apr 15, 2024
6daba1a
Run GetBranches on windows-latest by default
mazhelez Apr 15, 2024
06589ab
Convert to JSON array
mazhelez Apr 15, 2024
b0b3020
JSON stuff
mazhelez Apr 15, 2024
fc39d35
Always use array
mazhelez Apr 15, 2024
5abda87
🤦‍♀️
mazhelez Apr 15, 2024
c8399f3
🤦‍♀️
mazhelez Apr 15, 2024
9b29103
🤦‍♀️
mazhelez Apr 15, 2024
25640df
Add name property to GetBranches
mazhelez Apr 15, 2024
e760d59
Convert arrays to JSON
mazhelez Apr 15, 2024
c4ea9e0
Fix typo
mazhelez Apr 15, 2024
f441952
Default to main in AL-Go settings
mazhelez Apr 15, 2024
40eb235
Use invoke-git
mazhelez Apr 15, 2024
57b08f8
Fix README
mazhelez Apr 15, 2024
e60b51e
Minor fixes
mazhelez Apr 15, 2024
b3ed51c
Import GitHub helper
mazhelez Apr 15, 2024
2c29e00
Import GitHub module better
mazhelez Apr 15, 2024
72a40df
Add logs
mazhelez Apr 15, 2024
bc88077
Debugging
mazhelez Apr 15, 2024
7dab72d
Fix issue with types
mazhelez Apr 15, 2024
77e72f8
Fix param name
mazhelez Apr 15, 2024
14be591
Add -returnValue param to invoke-git
mazhelez Apr 15, 2024
1b8dbc8
Use matrix branch for CheckForUpdates
mazhelez Apr 15, 2024
1198bad
Fix outputs
mazhelez Apr 19, 2024
ba160a3
Add parenthesis
mazhelez Apr 19, 2024
1578131
Fix mistake when assigning output
mazhelez Apr 19, 2024
b80bbec
Merge branch 'main' into update-al-go-multiple-branches
mazhelez May 14, 2024
3c3a6e9
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Jun 25, 2024
9c3e8cb
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Jun 25, 2024
eb8ce45
Minor improvements
mazhelez Jun 25, 2024
8bada67
Propagate changes to the App Source template
mazhelez Jun 25, 2024
b5fffcd
Add action tests
mazhelez Jun 25, 2024
e209f53
Do not set default value for updateALGoBranches
mazhelez Jun 25, 2024
3f84587
Add release notes
mazhelez Jun 25, 2024
2ec56a4
Merge branch 'update-al-go-multiple-branches' of https://github.com/m…
mazhelez Jun 25, 2024
a853021
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Aug 7, 2024
3c603e2
Use GitHub variable instead of an AL-Go setting
mazhelez Aug 7, 2024
c30e162
Remove updateALGoBranches setting
mazhelez Aug 7, 2024
a1ca3da
Sync templates files
mazhelez Aug 7, 2024
f53c605
Fix doc and test file name
mazhelez Aug 7, 2024
0ae7c48
Improve release notes
mazhelez Aug 7, 2024
29e3dde
Fix branch name in YAML file
mazhelez Aug 7, 2024
a9874f1
Remove description from YAML to fix tests
mazhelez Aug 7, 2024
a31a479
Uptake action wrapper
mazhelez Aug 7, 2024
1e7f290
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Sep 27, 2024
25bd499
Use settings for when updating AL-Go on a schedule
mazhelez Sep 27, 2024
d68b12f
Fix README
mazhelez Sep 27, 2024
59b8496
Propagate changes to the PTE template
mazhelez Sep 27, 2024
7694e52
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Oct 30, 2024
58e2a70
Fix release notes
mazhelez Oct 30, 2024
1c96a5f
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Nov 11, 2024
69aca8b
Merge branch 'main' of https://github.com/mazhelez/AL-Go into update-…
mazhelez Dec 12, 2024
39e79b6
Fixes
mazhelez Dec 12, 2024
cd920cd
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Dec 12, 2024
2fc7ca5
Remove updateALGoSystemFilesSettings setting. Add scheduleSettings
mazhelez Dec 12, 2024
5db6867
Use ghTokenWorkflow instead of TokenForPush.
mazhelez Dec 12, 2024
748b633
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Dec 13, 2024
8c1fdaa
Add checkbox to update multiple branches
mazhelez Dec 19, 2024
5795eff
Sync workflows
mazhelez Dec 19, 2024
b025bc1
Fix action refs
mazhelez Dec 19, 2024
d5d078b
Minor fixes
mazhelez Dec 30, 2024
85eae0a
Use ubuntu-latest and pwsh
mazhelez Dec 30, 2024
baf2189
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Jan 7, 2025
ecdfd5a
Use activeBranch as base branch when creating a PR
mazhelez Jan 7, 2025
5b7c333
Debug PR creation
mazhelez Jan 8, 2025
488b62b
Propagate the branch to update
mazhelez Jan 8, 2025
075386d
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Jan 28, 2025
3f4ea62
Fix JSON-related issue with arrays
mazhelez Jan 28, 2025
f3fb6da
Propagate changes
mazhelez Jan 28, 2025
5f73ca0
Output ResultJSON in GetGitBranches
mazhelez Jan 28, 2025
6eedf0f
Silent git fetch
mazhelez Jan 28, 2025
4ce5d21
Fix action output name
mazhelez Jan 28, 2025
bb63c6c
Fix variable name
mazhelez Jan 28, 2025
d7987ae
Use windows-latest and powershell
mazhelez Jan 28, 2025
8da9f6d
Fix failing test
mazhelez Jan 29, 2025
e8d3bc4
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Feb 5, 2025
c70aa36
Rename action + remove extra logic from YAML into PS
mazhelez Feb 5, 2025
c53e1bf
Fix release notes
mazhelez Feb 5, 2025
dd7d595
Fix settings doc
mazhelez Feb 5, 2025
8dabfbd
Fix failing tests
mazhelez Feb 5, 2025
793b017
Add more tests
mazhelez Feb 5, 2025
410c8fe
Apply suggestions from code review
mazhelez Feb 10, 2025
ada64c4
Fix typo in RELEASENOTES.md
mazhelez Feb 10, 2025
41ae291
Apply suggestions from code review
mazhelez Feb 11, 2025
281f151
Merge branch 'main' of https://github.com/microsoft/AL-Go into update…
mazhelez Feb 20, 2025
190490d
Merge branch 'update-al-go-multiple-branches' of https://github.com/m…
mazhelez Feb 20, 2025
ee6bc17
Merge branch 'main' into update-al-go-multiple-branches
mazhelez Feb 25, 2025
86b6125
Remove workflowSchedule from default settings
mazhelez Feb 26, 2025
869088d
Add defensive check for when workflowSchedule.includeBranches is not …
mazhelez Feb 26, 2025
1104a71
Remove unneeded condition
mazhelez Feb 26, 2025
abae2ad
Fix parameter description
mazhelez Feb 26, 2025
ddb30fb
Merge branch 'main' into update-al-go-multiple-branches
mazhelez Feb 26, 2025
f60fd82
Apply suggestions from code review
mazhelez Feb 26, 2025
ed48f7d
Merge branch 'main' into update-al-go-multiple-branches
mazhelez Feb 27, 2025
5f0c6b0
Merge branch 'main' into update-al-go-multiple-branches
freddydk Feb 28, 2025
e3ba454
Apply suggestions from code review
mazhelez Feb 28, 2025
e5ce3ea
Fix typo
mazhelez Feb 28, 2025
af70949
Remove reading of unused templateUrl setting
mazhelez Feb 28, 2025
baebcd4
Improve release notes
mazhelez Feb 28, 2025
a68b6c1
Update Scenarios/settings.md
mazhelez Feb 28, 2025
db6f3e2
Enforce array on single values + fix tests
mazhelez Feb 28, 2025
e5028b7
Merge branch 'update-al-go-multiple-branches' of https://github.com/m…
mazhelez Feb 28, 2025
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
8 changes: 5 additions & 3 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ function ReadSettings {
"messageSuffix" = ""
"pullRequestAutoMerge" = $false
"pullRequestLabels" = @()
"createPullRequest" = $true
}
"trustedSigning" = [ordered]@{
"Endpoint" = ""
Expand Down Expand Up @@ -1374,7 +1375,8 @@ function CommitFromNewFolder {
[string] $serverUrl,
[string] $commitMessage,
[string] $body = $commitMessage,
[string] $branch
[string] $branch,
[string] $headBranch = $ENV:GITHUB_REF_NAME
)

invoke-git add *
Expand Down Expand Up @@ -1419,9 +1421,9 @@ function CommitFromNewFolder {
if ($settings.commitOptions.pullRequestLabels) {
$labels = "$($settings.commitOptions.pullRequestLabels -join ",")"
Write-Host "Adding labels: $labels"
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $ENV:GITHUB_REF_NAME --body "$body" --label $labels
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $headBranch --body "$body" --label $labels
} else {
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $ENV:GITHUB_REF_NAME --body "$body"
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $headBranch --body "$body"
}

if ($settings.commitOptions.pullRequestAutoMerge) {
Expand Down
2 changes: 1 addition & 1 deletion Actions/CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ else {
Write-Host "ReleaseNotes:"
Write-Host $releaseNotes

if (!(CommitFromNewFolder -serverUrl $serverUrl -commitMessage $commitMessage -branch $branch -body $releaseNotes)) {
if (!(CommitFromNewFolder -serverUrl $serverUrl -commitMessage $commitMessage -branch $branch -body $releaseNotes -headBranch $updateBranch)) {
OutputNotice -message "No updates available for AL-Go for GitHub."
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
param(
[Parameter(Mandatory = $false, HelpMessage = "Comma-separated value of branch name patterns to include if they exist. If not specified, only the current branch is returned. Wildcards are supported.")]
[string] $includeBranches
)

$gitHubHelperPath = Join-Path $PSScriptRoot '../Github-Helper.psm1' -Resolve
Import-Module $gitHubHelperPath -DisableNameChecking

switch ($env:GITHUB_EVENT_NAME) {
'schedule' {
Write-Host "Event is schedule: getting branches from settings"
$settings = ConvertFrom-Json $env:settings

# Add defensive check to handle if wporkflowSchedule.includeBranches is not defined in settings
if (-not $($settings.workflowSchedule.includeBranches)) {
Write-Host "No branch patterns defined in settings"
$branchPatterns = @()
} else {
$branchPatterns = @($($settings.workflowSchedule.includeBranches))
}
}
'workflow_dispatch' {
Write-Host "Event is workflow_dispatch: getting branches from input"
$branchPatterns = @($includeBranches.Split(',') | ForEach-Object { $_.Trim() })
}
}

# Default to the current branch if no branch patterns are specified
if (-not $branchPatterns) {
$branchPatterns = @($env:GITHUB_REF_NAME)
}

Write-Host "Filtering branches by: $($branchPatterns -join ', ')"

invoke-git fetch --quiet
$allBranches = @(invoke-git -returnValue for-each-ref --format="%(refname:short)" refs/remotes/origin | ForEach-Object { $_ -replace 'origin/', '' })
$branches = @()

foreach ($branchPattern in $branchPatterns) {
$branches += $allBranches | Where-Object { $_ -like $branchPattern }
}

$branches = $branches | Select-Object -Unique
Write-Host "Found git branches: $($branches -join ', ')"

# Add the branches to the output
$ResultJSON = $(ConvertTo-Json @{ branches = $branches } -Depth 99 -Compress)
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "Result=$ResultJSON"
32 changes: 32 additions & 0 deletions Actions/GetWorkflowMultiRunBranches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Get Workflow Multi-Run Branches

Gets the branches for a multi-branch workflow run.
If the worflow is dispatched, the branches are determined based on the input `includeBranches`.
If the workflow is run on a schedule, the branches are determined based on the `workflowSchedule.includeBranches` setting.

## INPUT

### ENV variables

| Name | Description |
| :-- | :-- |
| Settings | env.Settings must be set by a prior call to the ReadSettings Action |

### Parameters

| Name | Required | Description | Default value |
| :-- | :-: | :-- | :-- |
| shell | false | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| includeBranches | false | Comma-separated value of branch name patterns to include if they exist. If not specified, only the current branch is returned. Wildcards are supported. |''|

## OUTPUT

### ENV variables

none

### OUTPUT variables

| Name | Description |
| :-- | :-- |
| Result | JSON-formatted object with `branches` property, an array of branch names |
30 changes: 30 additions & 0 deletions Actions/GetWorkflowMultiRunBranches/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Get Workflow Multi-Run Branches
author: Microsoft Corporation
inputs:
shell:
description: Shell in which you want to run the action (powershell or pwsh)
required: false
default: powershell
includeBranches:
description: Comma-separated value of branch name patterns to include if they exist. If not specified, only the current branch is returned. Wildcards are supported.
required: false
default: ''
outputs:
Result:
description: JSON-formatted object with branches property, an array of branch names
value: ${{ steps.GetWorkflowMultiRunBranches.outputs.Result }}
runs:
using: composite
steps:
- name: run
shell: ${{ inputs.shell }}
id: GetWorkflowMultiRunBranches
env:
_includeBranches: ${{ inputs.includeBranches }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "GetWorkflowMultiRunBranches" -Action {
${{ github.action_path }}/GetWorkflowMultiRunBranches.ps1 -includeBranches $env:_includeBranches
}
branding:
icon: terminal
color: blue
6 changes: 6 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
> [!NOTE]
> The projects mentioned here are AL-Go projects in a multi-project repository. A repository can contain multiple projects and a project can contain multiple apps.

### Run "Update AL-Go System Files" on a schedule on multiple branches

When run on a schedule, _Update AL-Go System Files_ only runs on the _main_ branch. By setting `includeBranches` in `workflowSchedule` setting, you can now run the workflow on a schedule on multiple branches. Read more at https://aka.ms/algosettings#workflowSchedule.

Dispatching the workflow manually still runs the workflow only on the branch it was dispatched on.

### Support for incremental builds

AL-Go for GitHub now supports incremental builds, which means that unchanged projects or apps will be reused from the previous good build. Read [this](https://aka.ms/algosettings#incrementalBuilds) to learn more.
Expand Down
4 changes: 2 additions & 2 deletions Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The repository settings are only read from the repository settings file (.github
| <a id="pullRequestTrigger"></a>pullRequestTrigger | Setting for specifying the trigger AL-Go should use to trigger Pull Request Builds. You need to run the Update AL-Go System Files workflow for the change to take effect.<BR />Default is [pull_request_target](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) |
| <a id="buildModes"></a>buildModes | A list of build modes to use when building the AL-Go projects. Every AL-Go project will be built using each build mode. The following build modes have special meaning in AL-Go:<br /> **Default**: Apps are compiled as they are in the source code.<br />**Clean**: Should be used for Clean Mode. Use [Conditional Settings](https://aka.ms/algosettings#conditional-settings) with buildMode set the 'Clean' to specify preprocessorSymbols for clean mode.<br />**Translated**: `TranslationFile` compiler feature is enabled when compiling the apps.<br /><br />It is also possible to specify custom build modes by adding a build mode that is different than 'Default', 'Clean' or 'Translated' and use [conditional settings](https://aka.ms/algosettings#conditional-settings) to specify preprocessor symbols and other build settings for the build mode. |
| <a id="useGitSubmodules"></a>useGitSubmodules | If your repository is using Git Submodules, you can set the `useGitSubmodules` setting to `"true"` or `"recursive"` in order to use these submodules during build workflows. If `useGitSubmodules` is not set, git submodules are not initialized. If the submodules reside in private repositories, you need to define a `gitSubmodulesToken` secret. Read [this](https://aka.ms/algosecrets#gitSubmodulesToken) for more information. |
| <a id="commitOptions"></a>commitOptions | If you want more control over how AL-Go creates pull requests or commits changes to the repository you can define `commitOptions`. It is a structure defining how you want AL-Go to handle automated commits or pull requests coming from AL-Go (e.g. for Update AL-Go System Files). The structure contains the following properties:<br />**messageSuffix** = A string you want to append to the end of commits/pull requests created by AL-Go. This can be useful if you are using the Azure Boards integration (or similar integration) to link commits to work items. <br />**pullRequestAutoMerge** = A boolean defining whether you want AL-Go pull requests to be set to auto-complete. This will auto-complete the pull requests once all checks are green and all required reviewers have approved.<br />**pullRequestLabels** = A list of labels to add to the pull request. The labels need to be created in the repository before they can be applied.<br />If you want different behavior in different AL-Go workflows you can add the `commitOptions` setting to your [workflow-specific settings files](https://github.com/microsoft/AL-Go/blob/main/Scenarios/settings.md#where-are-the-settings-located). |
| <a id="commitOptions"></a>commitOptions | If you want more control over how AL-Go creates pull requests or commits changes to the repository you can define `commitOptions`. It is a structure defining how you want AL-Go to handle automated commits or pull requests coming from AL-Go (e.g. for Update AL-Go System Files). The structure contains the following properties:<br />**messageSuffix** = A string you want to append to the end of commits/pull requests created by AL-Go. This can be useful if you are using the Azure Boards integration (or similar integration) to link commits to work items. <br />`createPullRequest` : A boolean defining whether AL-Go should create a pull request or attempt to push directly in the branch.<br />**pullRequestAutoMerge** = A boolean defining whether you want AL-Go pull requests to be set to auto-complete. This will auto-complete the pull requests once all checks are green and all required reviewers have approved.<br />**pullRequestLabels** = A list of labels to add to the pull request. The labels need to be created in the repository before they can be applied.<br />If you want different behavior in different AL-Go workflows you can add the `commitOptions` setting to your [workflow-specific settings files](https://github.com/microsoft/AL-Go/blob/main/Scenarios/settings.md#where-are-the-settings-located). |
| <a id="incrementalBuilds"></a>incrementalBuilds | A structure defining how you want AL-Go to handle incremental builds. When using incremental builds for a build, AL-Go will look for the latest successful CI/CD build, newer than the defined `retentionDays` and only rebuild projects or apps (based on `mode`) which needs to be rebuilt. The structure supports the following properties:<br />**onPush** = Determines whether incremental builds is enabled in CI/CD triggered by a merge/push event. Default is **false**.<br />**onPull_Request** = Determines whether incremental builds is enabled in Pull Requests. Default is **true**.<br />**onSchedule** = Determines whether incremental builds is enabled in CI/CD when running on a schedule. Default is **false**.<br />**retentionDays** = Number of days a successful build is good (and can be used for incremental builds). Default is **30**.<br />**mode** = Specifies the mode for incremental builds. Currently, two values are supported. Use **modifiedProjects** when you want to rebuild all apps in all modified projects and depending projects or **modifiedApps** if you want to rebuild modified apps and all apps with dependencies to this app.<br />**NOTE:** when running incremental builds, it is recommended to also set `workflowConcurrency` for the CI/CD workflow, as defined [here](https://aka.ms/algosettings#workflowConcurrency). |

## Advanced settings
Expand Down Expand Up @@ -128,7 +128,7 @@ The following settings are only allowed in workflow specific settings files or i

| Name | Description |
| :-- | :-- |
| <a id="workflowSchedule"></a>workflowSchedule | The value should be a structure with a property named `cron`, containing a valid crontab, which is the CRON schedule for when the specified workflow should run. Default is no scheduled runs, only manual triggers. Build your crontab string here: [https://crontab.guru](https://crontab.guru). You need to run the Update AL-Go System Files workflow for the schedule to take effect.<br/>**Note:** If you configure a WorkflowSchedule for the CI/CD workflow, AL-Go will stop triggering CICDs on push unless you have also added CICDPushBranches to your settings.<br/>**Note also:** If you define a schedule for Update AL-Go System Files, it uses direct Commit instead of creating a PR. |
| <a id="workflowSchedule"></a>workflowSchedule | The value should be a structure with a property named `cron`, containing a valid crontab, which is the CRON schedule for when the specified workflow should run. Default is no scheduled runs, only manual triggers. Build your crontab string here: [https://crontab.guru](https://crontab.guru). You need to run the Update AL-Go System Files workflow for the schedule to take effect.<br/> The structure can also contain `includeBranches`, an array of branches to support when running the workflow on multiple branches. Currently, only "Update AL-Go System Files" is suppoeted to run on multiple branches. **Note:** If you configure a WorkflowSchedule for the CI/CD workflow, AL-Go will stop triggering CICDs on push unless you have also added CICDPushBranches to your settings.<br/>**Note also:** If you define a schedule for Update AL-Go System Files, it uses direct Commit instead of creating a PR. |
| <a id="workflowConcurrency"></a>workflowConcurrency | A setting to control concurrency of workflows. Like with the `WorkflowSchedule` setting, this setting should be applied in workflow specific settings files or conditional settings. By default, all workflows allows for concurrency, except for the Create Release workflow. If you are using incremental builds in CI/CD it is also recommented to set WorkflowConcurrency to:<br/>`[ "group: ${{ github.workflow }}-${{ github.ref }}", "cancel-in-progress: true" ]`<br />in order to cancel prior incremental builds on the same branch.<br />Read more about workflow concurrency [here](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/control-the-concurrency-of-workflows-and-jobs).

## AppSource specific advanced settings
Expand Down
Loading
Loading