From c147f70566fd5fcc2018608646ab3ee1380d28a3 Mon Sep 17 00:00:00 2001 From: Alexander Holstrup Date: Tue, 20 Oct 2026 16:17:00 +0200 Subject: [PATCH 1/4] Keep Copilot review templates inert until opted in Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- Actions/.Modules/settings.schema.json | 3 +- .../CheckForUpdates.HelperFunctions.ps1 | 26 ++++- Scenarios/Agents/CopilotCodeReview.md | 4 +- .../.github/workflows/CopilotPRReview.yaml | 5 +- .../workflows/CopilotPRReviewRunner.yaml | 6 +- .../.github/workflows/CopilotPRReview.yaml | 5 +- .../workflows/CopilotPRReviewRunner.yaml | 6 +- Tests/CheckForUpdates.Action.Test.ps1 | 102 ++++++++++++++++++ .../WorkflowFileContent.Test.ps1 | 24 +++++ 9 files changed, 162 insertions(+), 19 deletions(-) diff --git a/Actions/.Modules/settings.schema.json b/Actions/.Modules/settings.schema.json index 46a1378d4..498240bda 100644 --- a/Actions/.Modules/settings.schema.json +++ b/Actions/.Modules/settings.schema.json @@ -371,7 +371,8 @@ "properties": { "enabled": { "type": "boolean", - "description": "Enable Copilot code review workflows." + "default": false, + "description": "Enable Copilot code review in PTE and AppSource repositories. Update AL-Go System Files adds the automatic review triggers only when true; otherwise it removes the review workflows. Raw templates are manual-only and skip manual runs." }, "branches": { "type": "array", diff --git a/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 b/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 index cc7dc4b36..915eb1ac4 100644 --- a/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 +++ b/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 @@ -133,6 +133,10 @@ function ModifyPullRequestHandlerWorkflow { $yaml.Replace("on:/$($repoSettings.pullRequestTrigger):/branches:", "branches: [ '$($CICDPullRequestBranches -join "', '")' ]") } +<# +.SYNOPSIS +Adds the pull request trigger and configured target branches to the enabled review intake workflow. +#> function ModifyCopilotPRReviewWorkflow { Param( [Yaml] $yaml, @@ -150,7 +154,10 @@ function ModifyCopilotPRReviewWorkflow { } $branchesJson = ConvertTo-Json -InputObject $codeReviewBranches -Compress - $yaml.Replace("on:/pull_request:/branches:", "branches: $branchesJson") + $yaml.ReplaceOrAdd('on:/', 'pull_request:', @( + "branches: $branchesJson" + 'types: [ opened, reopened, synchronize, ready_for_review ]' + )) } function ModifyRunsOnAndShell { @@ -593,8 +600,21 @@ function GetWorkflowContentWithChangesFromSettings { ModifyPullRequestHandlerWorkflow -yaml $yaml -repoSettings $repoSettings } - if ([System.IO.Path]::GetFileName($srcFile) -eq "CopilotPRReview.yaml") { - ModifyCopilotPRReviewWorkflow -yaml $yaml -repoSettings $repoSettings + if ( + $repoSettings.Keys -contains 'CodeReviewAgent' -and + $repoSettings.CodeReviewAgent -is [System.Collections.IDictionary] -and + $repoSettings.CodeReviewAgent.Keys -contains 'enabled' -and + $repoSettings.CodeReviewAgent.enabled + ) { + if ($baseName -eq 'CopilotPRReview') { + ModifyCopilotPRReviewWorkflow -yaml $yaml -repoSettings $repoSettings + } + elseif ($baseName -eq 'CopilotPRReviewRunner') { + $yaml.ReplaceOrAdd('on:/', 'workflow_run:', @( + 'workflows: [ Copilot PR Review ]' + 'types: [ completed ]' + )) + } } $criticalWorkflows = @('UpdateGitHubGoSystemFiles', 'Troubleshooting', 'CopilotPRReviewRunner') diff --git a/Scenarios/Agents/CopilotCodeReview.md b/Scenarios/Agents/CopilotCodeReview.md index 3d4800faf..cdc6308ae 100644 --- a/Scenarios/Agents/CopilotCodeReview.md +++ b/Scenarios/Agents/CopilotCodeReview.md @@ -31,7 +31,9 @@ Add the following repository-level setting to `.github/AL-Go-Settings.json`: } ``` -Run the **Update AL-Go System Files** workflow to add the review workflows. Subsequent eligible pull requests targeting a branch configured in `CodeReviewAgent.branches` will be reviewed automatically. +Run the **Update AL-Go System Files** workflow to add the review workflows and their automatic triggers. Subsequent eligible pull requests targeting a branch configured in `CodeReviewAgent.branches` will be reviewed automatically. + +Both PTE and AppSource raw templates contain manual-only (`workflow_dispatch`) review workflows. Their entry jobs skip manual runs, so copying the templates directly or through an older updater does not start reviews. The current updater adds the intake `pull_request` and runner `workflow_run` triggers only when `CodeReviewAgent.enabled` is `true`; manual runs remain no-ops. When the setting is missing or disabled, the current updater excludes/removes both review workflows. BCQuality defaults to the trusted `microsoft/BCQuality` marketplace release, retains all content layers, and supplies the internal AL review context. Advanced filtering remains available through `BCQuality.enabledLayers`, `disabledSkills`, and `knowledge`. An empty `enabledLayers` list retains Microsoft, community, and custom content; an explicit list retains only those layers. `CodeReviewAgent.branches` controls the target branches reviewed independently of pull request build branches. Its empty default means `main`; an explicit list replaces that fallback and uses ordered GitHub Actions branch patterns, including `!` exclusions. The trusted runner checks the authoritative pull request base branch against these patterns before review. `model` controls final self-review and consolidation, while `leafModel` controls the isolated review processes. `excludedAuthors` contains GitHub login names whose pull requests should not be reviewed. The author list is empty by default. diff --git a/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml b/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml index 1bb98ac2c..0e097021e 100644 --- a/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml +++ b/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review on: - pull_request: - branches: [ 'main' ] - types: [ opened, reopened, synchronize, ready_for_review ] + workflow_dispatch: concurrency: group: copilot-pr-review-${{ github.event.pull_request.number }} @@ -18,6 +16,7 @@ permissions: jobs: Intake: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Upload pull request metadata diff --git a/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml b/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml index d6cc52407..4e5344c37 100644 --- a/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml +++ b/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review Runner on: - workflow_run: - workflows: [ Copilot PR Review ] - types: [ completed ] + workflow_dispatch: concurrency: group: copilot-pr-review-runner-${{ github.event.workflow_run.id }} @@ -21,7 +19,7 @@ env: jobs: prepare: - if: github.event.workflow_run.conclusion == 'success' + if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' runs-on: [ windows-latest ] permissions: actions: read diff --git a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml index 1bb98ac2c..0e097021e 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review on: - pull_request: - branches: [ 'main' ] - types: [ opened, reopened, synchronize, ready_for_review ] + workflow_dispatch: concurrency: group: copilot-pr-review-${{ github.event.pull_request.number }} @@ -18,6 +16,7 @@ permissions: jobs: Intake: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Upload pull request metadata diff --git a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml index d6cc52407..4e5344c37 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review Runner on: - workflow_run: - workflows: [ Copilot PR Review ] - types: [ completed ] + workflow_dispatch: concurrency: group: copilot-pr-review-runner-${{ github.event.workflow_run.id }} @@ -21,7 +19,7 @@ env: jobs: prepare: - if: github.event.workflow_run.conclusion == 'success' + if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' runs-on: [ windows-latest ] permissions: actions: read diff --git a/Tests/CheckForUpdates.Action.Test.ps1 b/Tests/CheckForUpdates.Action.Test.ps1 index a9a5b88e2..b3394ac43 100644 --- a/Tests/CheckForUpdates.Action.Test.ps1 +++ b/Tests/CheckForUpdates.Action.Test.ps1 @@ -390,6 +390,74 @@ Describe "CheckForUpdates Action: CheckForUpdates.HelperFunctions.ps1" { { ModifyRunsOnAndShell -yaml $yaml -repoSettings $repoSettings } | Should -Throw '*The shell cannot be set to powershell when runs-on is ubuntu-latest*' } + It 'Adds Copilot review triggers only when enabled in