Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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/.Modules/ReadSettings.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function GetDefaultSettings
"gitSubmodulesTokenSecretName" = "gitSubmodulesToken"
"shortLivedArtifactsRetentionDays" = 1 # 0 means use GitHub default
"reportSuppressedDiagnostics" = $false
"workflowDefaultInputs" = @()
}
}

Expand Down Expand Up @@ -608,5 +609,5 @@ function SanitizeWorkflowName {
return $workflowName.Trim().Split([System.IO.Path]::getInvalidFileNameChars()) -join ""
}

Export-ModuleMember -Function ReadSettings
Export-ModuleMember -Function ReadSettings, SanitizeWorkflowName
Export-ModuleMember -Variable ALGoFolderName, ALGoSettingsFile, RepoSettingsFile, CustomTemplateRepoSettingsFile, CustomTemplateProjectSettingsFile
30 changes: 30 additions & 0 deletions Actions/.Modules/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,36 @@
"reportSuppressedDiagnostics": {
"type": "boolean",
"description": "Report suppressed diagnostics. See https://aka.ms/ALGoSettings#reportsuppresseddiagnostics"
},
"workflowDefaultInputs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"workflow": {
"type": "string",
"description": "The workflow name to apply default values to (must match exactly)"
},
"defaults": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the workflow input"
},
"value": {
"description": "The default value for the workflow input (can be string, boolean, or number)"
}
},
"required": ["name", "value"]
}
}
},
"required": ["workflow", "defaults"]
},
"description": "An array of workflow input default values. See https://aka.ms/ALGoSettings#workflowDefaultInputs"
}
}
}
186 changes: 186 additions & 0 deletions Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,187 @@ function ModifyUpdateALGoSystemFiles {
$yaml.Replace('jobs:/UpdateALGoSystemFiles:/', $updateALGoSystemFilesJob.content)
}

function ApplyWorkflowDefaultInputs {
Param(
[Yaml] $yaml,
[hashtable] $repoSettings,
[string] $workflowName
)

# Check if workflow_dispatch inputs exist
$workflowDispatch = $yaml.Get('on:/workflow_dispatch:/')
if (-not $workflowDispatch) {
# No workflow_dispatch section, nothing to do
return
}

$inputs = $workflowDispatch.Get('inputs:/')
if (-not $inputs) {
# No inputs section, nothing to do
return
}

# Sanitize the workflow name for matching
$sanitizedWorkflowName = SanitizeWorkflowName -workflowName $workflowName

# Find matching workflow input defaults
$matchingDefaults = @()
foreach ($workflowInputDefault in $repoSettings.workflowDefaultInputs) {
if ($workflowInputDefault.workflow) {
# Sanitize the workflow name in the setting for comparison
$settingWorkflowName = SanitizeWorkflowName -workflowName $workflowInputDefault.workflow
if ($sanitizedWorkflowName -eq $settingWorkflowName) {
$matchingDefaults += $workflowInputDefault
}
}
}

if ($matchingDefaults.Count -eq 0) {
# No matching defaults for this workflow
return
}

# Apply defaults to matching inputs
foreach ($workflowInputDefault in $matchingDefaults) {
foreach ($default in $workflowInputDefault.defaults) {
$inputName = $default.name
$defaultValue = $default.value

# Check if this input exists in the workflow
$inputSection = $inputs.Get("$($inputName):/")
if ($inputSection) {
# Get the input type from the YAML if specified
$inputType = $null
$typeStart = 0
$typeCount = 0
if ($inputSection.Find('type:', [ref] $typeStart, [ref] $typeCount)) {
$typeLine = $inputSection.content[$typeStart].Trim()
if ($typeLine -match 'type:\s*(.+)') {
$inputType = $matches[1].Trim()
}
}

# Validate that the value type matches the input type
$validationError = $null
if ($inputType) {
switch ($inputType) {
'boolean' {
if ($defaultValue -isnot [bool]) {
$validationError = "Workflow '$workflowName', input '$inputName': Expected boolean value, but got $($defaultValue.GetType().Name). Please use `$true or `$false."
}
}
'number' {
if ($defaultValue -isnot [int] -and $defaultValue -isnot [long] -and $defaultValue -isnot [double]) {
$validationError = "Workflow '$workflowName', input '$inputName': Expected number value, but got $($defaultValue.GetType().Name)."
}
}
'string' {
if ($defaultValue -isnot [string]) {
$validationError = "Workflow '$workflowName', input '$inputName': Expected string value, but got $($defaultValue.GetType().Name)."
}
}
'choice' {
# Choice inputs accept strings and must match one of the available options (case-sensitive)
if ($defaultValue -isnot [string]) {
$validationError = "Workflow '$workflowName', input '$inputName': Expected string value for choice input, but got $($defaultValue.GetType().Name)."
}
else {
# Validate that the value is one of the available options
$optionsStart = 0
$optionsCount = 0
if ($inputSection.Find('options:', [ref] $optionsStart, [ref] $optionsCount)) {
$availableOptions = @()
# Parse the options from the YAML (they are indented list items starting with "- ")
for ($i = $optionsStart + 1; $i -lt ($optionsStart + $optionsCount); $i++) {
$optionLine = $inputSection.content[$i].Trim()
if ($optionLine -match '^-\s*(.+)$') {
$availableOptions += $matches[1].Trim()
}
}

if ($availableOptions.Count -gt 0 -and $availableOptions -cnotcontains $defaultValue) {
$validationError = "Workflow '$workflowName', input '$inputName': Value '$defaultValue' is not a valid choice (case-sensitive match required). Available options: $($availableOptions -join ', ')."
}
}
}
}
}
}
else {
# If no type is specified in the workflow, it defaults to string
if ($defaultValue -isnot [string]) {
OutputWarning "Workflow '$workflowName', input '$inputName': No type specified in workflow (defaults to string), but configured value is $($defaultValue.GetType().Name). This may cause issues."
}
}

if ($validationError) {
throw $validationError
}

# Convert the default value to the appropriate YAML format
$yamlValue = $defaultValue
if ($defaultValue -is [bool]) {
$yamlValue = $defaultValue.ToString().ToLower()
}
elseif ($defaultValue -is [string]) {
# Quote strings and escape single quotes per YAML spec
$escapedValue = $defaultValue.Replace("'", "''")
$yamlValue = "'$escapedValue'"
}

# Find and replace the default: line in the input section
$start = 0
$count = 0
if ($inputSection.Find('default:', [ref] $start, [ref] $count)) {
# Replace existing default value
$inputSection.Replace('default:', "default: $yamlValue")
}
else {
# Add default value - find the best place to insert it
# Insert after type, required, or description (whichever comes last)
$insertAfter = -1
$typeLine = 0
$typeCount = 0
$requiredLine = 0
$requiredCount = 0
$descLine = 0
$descCount = 0

if ($inputSection.Find('type:', [ref] $typeLine, [ref] $typeCount)) {
$insertAfter = $typeLine + $typeCount
}
if ($inputSection.Find('required:', [ref] $requiredLine, [ref] $requiredCount)) {
if (($requiredLine + $requiredCount) -gt $insertAfter) {
$insertAfter = $requiredLine + $requiredCount
}
}
if ($inputSection.Find('description:', [ref] $descLine, [ref] $descCount)) {
if (($descLine + $descCount) -gt $insertAfter) {
$insertAfter = $descLine + $descCount
}
}

if ($insertAfter -eq -1) {
# No other properties, insert at position 1 (after the input name)
$insertAfter = 1
}

$inputSection.Insert($insertAfter, "default: $yamlValue")
}

# Update the inputs section with the modified input
$inputs.Replace("$($inputName):/", $inputSection.content)
}
}
}

# Update the workflow_dispatch section with modified inputs
$workflowDispatch.Replace('inputs:/', $inputs.content)

# Update the on: section with modified workflow_dispatch
$yaml.Replace('on:/workflow_dispatch:/', $workflowDispatch.content)
}

function GetWorkflowContentWithChangesFromSettings {
Param(
[string] $srcFile,
Expand Down Expand Up @@ -394,6 +575,11 @@ function GetWorkflowContentWithChangesFromSettings {
ModifyUpdateALGoSystemFiles -yaml $yaml -repoSettings $repoSettings
}

# Apply workflow input defaults from settings
if ($repoSettings.Keys -contains 'workflowDefaultInputs') {
ApplyWorkflowDefaultInputs -yaml $yaml -repoSettings $repoSettings -workflowName $workflowName
}

# combine all the yaml file lines into a single string with LF line endings
$yaml.content -join "`n"
}
Expand Down
33 changes: 33 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
### Set default values for workflow inputs

A new setting `workflowDefaultInputs` allows you to configure default values for workflow_dispatch inputs. This makes it easier to run workflows manually with consistent settings across your team.

When you add this setting to your AL-Go settings file and run the "Update AL-Go System Files" workflow, the default values will be automatically applied to the workflow YAML files in your repository.
The default values must match the input types (boolean, number, string, or choice) defined in the workflow YAML files.

Example configuration:

```json
{
"workflowDefaultInputs": [
{
"workflow": "Create Release",
"defaults": [
{ "name": "directCommit", "value": true },
{ "name": "useGhTokenWorkflow", "value": true },
{ "name": "updateVersionNumber", "value": "+0.1" }
]
},
{
"workflow": "Update AL-Go System Files",
"defaults": [
{ "name": "directCommit", "value": true }
]
}
]
}
```

Read more at [workflowDefaultInputs](https://aka.ms/algosettings#workflowDefaultInputs).

### Issues

- Issue 1961 KeyVault access in PR pipeline
- Discussion 1911 Add support for reportSuppressedDiagnostics
- Discussion 1968 Parameter for settings passed to CreateDevEnv
- Issue 1945 Deploy Reference Documentation fails for CI/CD
- Issue 2016 Running Update AL-Go system files with branches wildcard `*` tries to update _origin_
- Discussion 1952 Set default values on workflow_dispatch input

## v8.0

Expand Down
7 changes: 7 additions & 0 deletions Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The repository settings are only read from the repository settings file (.github
| <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 />`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 />**pullRequestMergeMethod** = A string defining which merge method to use when auto-merging pull requests. Valid values are "merge" and "squash". Default is "squash".<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). |
| <a id="workflowDefaultInputs"></a>workflowDefaultInputs | An array of workflow input default values. This setting allows you to configure default values for workflow_dispatch inputs, making it easier to run workflows manually with consistent settings. Each entry should contain:<br />**workflow** = The name of the workflow (e.g., "Create Release"). Workflow names are matched using [sanitized names](#workflow-name-sanitization).<br />**defaults** = An array of default values, where each entry has:<br />**name** = The name of the workflow input<br />  **value** = The default value (can be string, boolean, or number)<br />**Important validation rules:**<br />  • The value type must match the input type defined in the workflow YAML file (boolean, number, string, or choice)<br />  • For choice inputs, the value must be one of the options declared in the workflow<br />Type and choice validation is performed when running the "Update AL-Go System Files" workflow to prevent configuration errors.<br />When you run the "Update AL-Go System Files" workflow, these default values will be applied to the workflow YAML files.<br />Example:<br />`"workflowDefaultInputs": [`<br />` {`<br />` "workflow": "Create Release",`<br />` "defaults": [`<br />` { "name": "directCommit", "value": true },`<br />` { "name": "useGhTokenWorkflow", "value": true },`<br />` { "name": "updateVersionNumber", "value": "+0.1" }`<br />` ]`<br />` }`<br />`]` |

<a id="advanced"></a>

Expand Down Expand Up @@ -181,6 +182,12 @@ to your [project settings file](#where-are-the-settings-located) will ensure tha
- **workflows** settings will be applied to workflows matching the patterns
- **users** settings will be applied for users matching the patterns

<a id="workflow-name-sanitization"></a>

### Workflow Name Sanitization

When matching workflow names (for conditional settings and workflowDefaultInputs), AL-Go sanitizes the actual workflow name before comparison. Sanitization removes invalid filename characters such as leading spaces, quotes, colons, slashes, and other special characters. For example, a workflow named `" CI/CD"` would be sanitized to `"CICD"` for matching purposes.

You could imagine that you could have and organizational settings variable containing:

```json
Expand Down
Loading
Loading