Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Actions/.Modules/ReadSettings.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ function GetDefaultSettings
}
"pullRequestTrigger" = "pull_request"
"skipDraftPullRequests" = $false
"optionalPatternsForPrValidation" = @()
"bcptThresholds" = [ordered]@{
"DurationWarning" = 10
"DurationError" = 25
Expand Down
8 changes: 8 additions & 0 deletions Actions/.Modules/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"description": "Schema for AL-Go settings",
"type": "object",
"properties": {
"optionalPatternsForPrValidation": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Optional case-insensitive PowerShell wildcard patterns matching full job names. Only names matching 'Build * (*) / *' qualify, including custom jobs following this convention. Matching failures do not block the aggregate Pull Request Status Check; jobs outside this convention remain required. Applies to PTE and AppSource Pull Request Build workflows, including merge groups. See https://aka.ms/ALGoSettings#optionalPatternsForPrValidation"
},
"type": {
"type": "string",
"minLength": 1,
Expand Down
63 changes: 52 additions & 11 deletions Actions/PullRequestStatusCheck/PullRequestStatusCheck.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
$gitHubHelperPath = Join-Path $PSScriptRoot '..\Github-Helper.psm1' -Resolve
Import-Module $gitHubHelperPath -DisableNameChecking
. (Join-Path $PSScriptRoot '..\AL-Go-Helper.ps1' -Resolve)

<#
.SYNOPSIS
Checks the status of all jobs in a Pull Request build run and fails if any job failed.
Checks a Pull Request build run and fails if any required job failed.
.DESCRIPTION
Queries the GitHub Actions jobs API for the given run and throws if any job concluded with "failure".
Queries the GitHub Actions jobs API and throws for required jobs concluded with "failure".
Jobs named "Build * (*) / *" matching optional wildcard patterns emit warnings instead.
Other jobs remain required. Other conclusions retain their existing behavior.
Writes failedOptionalJobs as a JSON array of failed optional job names before reporting required failures.
The jobs endpoint is paginated and can return a large response for builds with many jobs (for example
a build that spans many countries). Three robustness measures are applied:
- The request is retried, because the (large) jobs endpoint intermittently returns HTTP 502.
Expand All @@ -18,36 +20,75 @@ Import-Module $gitHubHelperPath -DisableNameChecking
The repository (owner/name) that owns the run.
.PARAMETER RunId
The id of the workflow run to check.
.PARAMETER OptionalPatterns
Case-insensitive PowerShell wildcard patterns matching full build job names.
.EXAMPLE
PullRequestStatusCheck -Repository "owner/repo" -RunId "123456"
#>
function PullRequestStatusCheck()
{
function PullRequestStatusCheck() {
param(
[Parameter(HelpMessage = "Repository name", Mandatory = $true)]
[string] $Repository,
[Parameter(HelpMessage = "Run Id", Mandatory = $true)]
[string] $RunId
[string] $RunId,
[string[]] $OptionalPatterns = @()
)
Write-Host "Checking PR Build status for run $RunId in repository $Repository"

foreach ($pattern in $OptionalPatterns) {
# Fail-Fast for invalid wildcard patterns. Force wildcard parsing even when the run contains no failed jobs.
$null = '' -like $pattern
}
$env:GH_HOST = ([Uri]$env:GITHUB_SERVER_URL).Host
$workflowJobs = Invoke-CommandWithRetry -RetryCount 5 -FirstDelay 5 -MaxWaitBetweenRetries 60 -ScriptBlock {
$jobsJson = gh api "/repos/$Repository/actions/runs/$RunId/jobs?per_page=50" --paginate --slurp -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
if ($LASTEXITCODE) {
throw "Failed to get jobs for run $RunId in repository $Repository (gh exit code $LASTEXITCODE)."
}
$jobsJson | ConvertFrom-Json
$jobsJson | ConvertFrom-Json | ForEach-Object {
foreach ($page in $_) {
$page | ConvertTo-HashTable -recurse
}
}
}

# --slurp yields an array with one entry per page; member enumeration flattens jobs across all pages.
# When a single (non-slurped) object is returned, .jobs resolves to that object's jobs.
$failedJobs = @($workflowJobs.jobs | Where-Object { $_.conclusion -eq "failure" })

if ($failedJobs) {
throw "PR Build failed. Failing jobs: $($failedJobs.name -join ', ')"
$failedOptionalJobs = @()
$badFailures = @(
foreach ($job in $failedJobs) {
$matchesOptionalPattern = @($OptionalPatterns | Where-Object { $job.name -like $_ }).Count -gt 0
if ($job.name -like 'Build * (*) / *' -and $matchesOptionalPattern) {
$failedOptionalJobs += $job.name
OutputWarning -message "Optional PR build job failed (non-blocking): $($job.name)"
continue
}
$job
}
)
$failedOptionalJobsJson = ConvertTo-Json -InputObject $failedOptionalJobs -Compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "failedOptionalJobs=$failedOptionalJobsJson"
if ($badFailures) {
throw "PR Build failed. Failing jobs: $($badFailures.name -join ', ')"
}
}

PullRequestStatusCheck -Repository $env:GITHUB_REPOSITORY -RunId $env:GITHUB_RUN_ID
if (!$env:Settings) {
throw "Settings environment variable is required."
}
$settingsJson = $env:Settings | ConvertFrom-Json
$rawOptionalPatterns = $settingsJson.optionalPatternsForPrValidation
if ($rawOptionalPatterns -isnot [System.Array]) {
throw "Settings.optionalPatternsForPrValidation must be an array."
}
foreach ($pattern in $rawOptionalPatterns) {
if ($pattern -isnot [string]) {
throw "Settings.optionalPatternsForPrValidation must contain only strings."
}
}
$settings = $settingsJson | ConvertTo-HashTable -recurse
$optionalPatterns = @($settings.optionalPatternsForPrValidation)
PullRequestStatusCheck -Repository $env:GITHUB_REPOSITORY -RunId $env:GITHUB_RUN_ID -OptionalPatterns $optionalPatterns
Write-Host "PR Build succeeded"
23 changes: 21 additions & 2 deletions Actions/PullRequestStatusCheck/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pull Request Status Check

Check the status of a pull request build and fail the build if any jobs have failed.
Check the status of a pull request build and fail if any required jobs have failed. Matching optional build-matrix failures emit warnings instead. Other job conclusions retain their existing behavior.

## INPUT

Expand All @@ -16,6 +16,25 @@ Check the status of a pull request build and fail the build if any jobs have fai
| :-- | :-: | :-- | :-- |
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |

Optional build job patterns are read from `Settings.optionalPatternsForPrValidation`, which is populated by the preceding ReadSettings action. The setting is an array of case-insensitive PowerShell wildcard patterns matching full build job names.

The PTE and AppSource Pull Request Build workflows read settings in the StatusCheck job after checking out the build ref. The patterns are passed as JSON from the ReadSettings action's standard `Settings` environment variable. Only jobs whose API names match `Build * (*) / *` can be optional, and they must also match a configured pattern. Custom jobs using this naming convention also qualify. Jobs outside this convention remain required even with a broad wildcard. Invalid JSON or input shapes fail explicitly.

Optional jobs and the workflow run may remain failed while this aggregate status check succeeds. See [optional PR builds](../../Scenarios/settings.md#optional-pr-builds).

## OUTPUT

none
| Name | Description |
| :-- | :-- |
| failedOptionalJobs | JSON array of full names of failed optional build jobs, or `[]` when none qualify. Successful, skipped, cancelled, and required jobs are excluded. |

After job classification, the output is written even if a required job failure causes the action to fail. API or input validation errors do not produce this output.

Give the action step an `id` (for example, `statusCheck`) and read `${{ steps.statusCheck.outputs.failedOptionalJobs }}`. Use `fromJSON(steps.statusCheck.outputs.failedOptionalJobs)` to consume it as an array. To expose it to other jobs, map it to a job output and read `${{ needs.StatusCheck.outputs.failedOptionalJobs }}`:

```yaml
outputs:
failedOptionalJobs: ${{ steps.statusCheck.outputs.failedOptionalJobs }}
```

Consumers that must run after a required failure need an appropriate condition such as `if: always()`.
5 changes: 5 additions & 0 deletions Actions/PullRequestStatusCheck/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ inputs:
description: Shell in which you want to run the action (powershell or pwsh)
required: false
default: powershell
outputs:
failedOptionalJobs:
description: JSON array of failed optional build job names
value: ${{ steps.pullrequeststatuscheck.outputs.failedOptionalJobs }}
runs:
using: composite
steps:
- name: run
shell: ${{ inputs.shell }}
id: pullrequeststatuscheck
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "PullRequestStatusCheck" -Action {
${{ github.action_path }}/PullRequestStatusCheck.ps1
Expand Down
6 changes: 6 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Optional builds for PR validation
Comment thread
ChrisBlankDe marked this conversation as resolved.
Resolved

The new `optionalPatternsForPrValidation` setting (default `[]`) lets PTE and AppSource repositories make selected build-matrix failures non-blocking for the aggregate **Pull Request Status Check**, including merge-group runs. Case-insensitive PowerShell wildcard patterns match full GitHub job names. Eligible names must also match `Build * (*) / *`; custom jobs following this convention also qualify. Optional failures emit warnings; jobs outside this convention remain required. Individual optional jobs and the workflow run can still be red, so rulesets should require the aggregate check. Update AL-Go system files for the new input wiring. See [optionalPatternsForPrValidation](Scenarios/settings.md#optionalPatternsForPrValidation).

The PullRequestStatusCheck action exposes `failedOptionalJobs`, a JSON array of failed optional build job names (`[]` when none qualify), for consumption by later steps or via job outputs. The output is also written when required job failures cause the check to fail.

## v10.1

### Optional draft PR build skipping
Expand Down
22 changes: 22 additions & 0 deletions Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ The following settings are only allowed in workflow specific settings files or i
| <a id=""></a>appSourceContextSecretName | This setting specifies the name (**NOT the secret**) of a secret containing a json string with ClientID, TenantID and ClientSecret or RefreshToken. If this secret exists, AL-Go will can upload builds to AppSource validation. | AppSourceContext |
| <a id=""></a>keyVaultCertificateUrlSecretName<br />keyVaultCertificatePasswordSecretName<br />keyVaultClientIdSecretName | If you want to enable KeyVault access for your AppSource App, you need to provide 3 secrets as GitHub Secrets or in the Azure KeyVault. The names of those secrets (**NOT the secrets**) should be specified in the settings file with these 3 settings. Default is to not have KeyVault access from your AppSource App. Read [this](EnableKeyVaultForAppSourceApp.md) for more information. | |

## Optional PR builds

| Name | Description | Default value |
| :-- | :-- | :-- |
| <a id="optionalPatternsForPrValidation"></a>optionalPatternsForPrValidation | Optional array of strings containing case-insensitive PowerShell wildcard patterns (`*`, `?`, and character sets) matching full GitHub build-matrix job names. Matching failed builds emit warnings instead of blocking **Pull Request Status Check**. Non-build jobs always remain required. Honored by the **Pull Request Build** workflows, including merge-group runs; not by CI/CD or the Current, NextMinor, and NextMajor workflows. Read in the StatusCheck job from organization, repository, workflow, and root project settings, without aggregating settings from individual matrix projects. | `[]` |

For example, when a build mode is named `NextMinor`, configure:

```json
{
"optionalPatternsForPrValidation": ["Build * (NextMinor) / *"]
}
```

Patterns match the full job name returned by GitHub, such as `Build MyProject (NextMinor) / MyProject (NextMinor)`, not artifact URLs or build-mode settings directly. Matching uses PowerShell `-like`, just as conditional settings do, not regular expressions. Arrays follow the existing settings merge and `overwriteSettings` rules. An empty array keeps all failures blocking.

Only jobs whose full API names match `Build * (*) / *` can be optional, and they must also match a configured pattern. Custom jobs following this naming convention also qualify. Initialization, fork validation, code analysis, and other jobs outside this convention remain required even with `["*"]`. Jobs sharing the same name follow the same pattern-matching rules. A failure in any step of an eligible build job can be optional, including container setup or checkout failures. Additional-country execution inside that same job cannot be made optional separately.

Individual optional jobs and the workflow run can still appear failed while the aggregate **Pull Request Status Check** succeeds. Configure branch protection/rulesets to require the aggregate check rather than the optional jobs. Optional failures are reported as workflow warnings.

Only jobs with conclusion `failure` are affected. Existing cancellation/skipping behavior and dependency scheduling are unchanged: an optional failure does not rerun downstream builds that were skipped because of it. The same policy applies to merge-queue validation. Update AL-Go system files to obtain the new workflow input wiring.

<a id="conditional"></a>

## Conditional Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ jobs:
runs-on: [ windows-latest ]
name: Pull Request Status Check
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
lfs: true
ref: ${{ github.event_name == 'pull_request' && github.sha || github.event_name == 'merge_group' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}

- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell

- name: Pull Request Status Check
id: PullRequestStatusCheck
uses: microsoft/AL-Go-Actions/PullRequestStatusCheck@main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ jobs:
runs-on: [ windows-latest ]
name: Pull Request Status Check
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
lfs: true
ref: ${{ github.event_name == 'pull_request' && github.sha || github.event_name == 'merge_group' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}

- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell

- name: Pull Request Status Check
id: PullRequestStatusCheck
uses: microsoft/AL-Go-Actions/PullRequestStatusCheck@main
Expand Down
Loading