Skip to content

Issue 2336 - Option to fail deployment - #2385

Open
Thomas Rønn (thomasroennTRM) wants to merge 18 commits into
microsoft:mainfrom
thomasroennTRM:main
Open

Thomas Rønn (thomasroennTRM) wants to merge 18 commits into
microsoft:mainfrom
thomasroennTRM:main

Conversation

@thomasroennTRM

Copy link
Copy Markdown

❔What, Why & How

What

Adds an opt-in setting, failOnAppVersionDowngrade (default false). When it's enabled, the CI/CD deployment fails if an app in the build artifact has a lower version than the app already installed in the environment.

You can set it globally or per environment in DeployTo. The environment value takes precedence.
A new CheckDowngrade action runs before Deploy to Business Central in the PTE and AppSource App CI/CD workflows.
Why

Today, a deployment where the artifact version is lower than the installed version only produces a warning. The workflow still succeeds, so it's easy to miss that the apps were never updated. This setting lets you make that case fail the workflow.

How

The CI/CD workflow works out the effective setting for the environment.
If the setting is true, CheckDowngrade compares each app in the artifact with the installed version in the environment.
If any app would be downgraded, it writes one error per app and fails the deploy job.

Related to issue: #2336
#2336

✅ Checklist

  • Add tests (E2E, unit tests) - did have som issues with getting the e2e to function, so not tested. Looks like this was optional.
  • Update RELEASENOTES.md
  • Update documentation (e.g. for new settings or scenarios)
  • [-] Add telemetry

Copilot AI balanced review requested due to automatic review settings September 28, 2026 08:59
@thomasroennTRM

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Settings resolution, environment targeting, and artifact selection can diverge from the actual deployment and cause false passes or failures.

Review effort: Balanced
Findings: 4 Medium severity · 2 Low severity

Open (6)
What changed in this PR

Adds an opt-in safeguard that blocks CI/CD deployments when artifact app versions are lower than installed versions.

Changes:

  • Adds the CheckDowngrade action and unit tests.
  • Integrates downgrade validation into PTE and AppSource workflows.
  • Documents and registers the new setting.
File Description
Actions/​CheckDowngrade/​CheckDowngrade.ps1 Implements downgrade detection.
Actions/​CheckDowngrade/​action.yaml Defines the composite action.
Actions/​CheckDowngrade/​README.md Documents action usage.
Tests/​CheckDowngrade.Action.Test.ps1 Tests core action behavior.
Templates/​Per Tenant Extension/​.github/​workflows/​CICD.yaml Adds PTE pre-deployment validation.
Templates/​AppSource App/​.github/​workflows/​CICD.yaml Adds AppSource pre-deployment validation.
Actions/​.Modules/​ReadSettings.psm1 Adds the default setting.
Actions/​.Modules/​settings.schema.json Defines global schema metadata.
Scenarios/​settings.md Documents global and environment settings.
RELEASENOTES.md Announces the new action.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Actions/CheckDowngrade/CheckDowngrade.ps1 Outdated
Comment thread Actions/CheckDowngrade/CheckDowngrade.ps1 Outdated
Comment thread Templates/AppSource App/.github/workflows/CICD.yaml Outdated
Comment thread Templates/Per Tenant Extension/.github/workflows/CICD.yaml Outdated
Comment thread Actions/.Modules/settings.schema.json
Comment thread Actions/CheckDowngrade/CheckDowngrade.ps1

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The checker can break custom deployments, and its test-app behavior conflicts with the documentation.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
Resolved since last review (6)

Comment thread Actions/CheckDowngrade/CheckDowngrade.ps1
Comment thread Scenarios/settings.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The check can fail environments that the existing deployment action intentionally skips, and the documented settings sources are inaccurate.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
Resolved since last review (2)

Comment thread Actions/CheckDowngrade/CheckDowngrade.ps1 Outdated
Comment thread Scenarios/settings.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The action declares Publish support but does not handle the standard device-code authentication flow.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread Actions/CheckDowngrade/CheckDowngrade.ps1 Outdated
…support device code and improve error messaging

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The pre-check excludes test apps that the deployment can publish, leaving a documented partial-deployment scenario unprotected.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate test apps using the resolved deployment setting

Actions/​CheckDowngrade/​CheckDowngrade.ps1:83

This forces test apps out of the pre-check even when the resolved deployment setting enables them. Deploy.ps1 uses the original setting and publishes those test apps, so a downgraded test app can still be attempted after the check passes, allowing the partial-deployment scenario this pre-check is meant to prevent. Preserve includeTestAppsInSandboxEnvironment so every app selected for publishing is validated, and update the test/documentation that currently codifies the exclusion.

…p the Deploy action publishes, including test apps when includeTestAppsInSandboxEnvironment is on.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The opt-in behavior is implemented consistently and adequately tested, with only a non-blocking release-note clarification identified.

Review effort: Balanced
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Low severity Reference repository/environment setting instead of action input

RELEASENOTES.md:3

This release note points users to the action input, but the generated CI/CD workflows hard-code that input to true; users opt in through the repository/environment setting instead. Please name the setting here so the configuration guidance matches the workflow and Scenarios/settings.md.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The release note incorrectly states that project-subfolder settings can enable the feature.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

Comment thread RELEASENOTES.md Outdated
Added details about the new `CheckDowngrade` action and its opt-in configuration for CI/CD workflows. Updated the section on allowing pre-release packages as NuGet dependencies.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation, workflow integration, tests, schema, and documentation consistently support the opt-in downgrade policy.

Review effort: Balanced
Findings: None

Resolved since last review (1)


function DownloadAndImportBcContainerHelper {}
function New-BcAuthContext {}
function Get-BcInstalledExtensions { Param($bcAuthContext, $environment) }

function DownloadAndImportBcContainerHelper {}
function New-BcAuthContext {}
function Get-BcInstalledExtensions { Param($bcAuthContext, $environment) }

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The separate precheck has a deployment race and can fail environments that the Deploy action would intentionally skip.

Review effort: Balanced
Findings: 2 High severity · 1 Medium severity

Open (3)


- name: Validate App Versions Before Deploy
if: steps.DowngradePolicy.outputs.failOnAppVersionDowngrade == 'true'
uses: microsoft/AL-Go-Actions/CheckDowngrade@main

- name: Validate App Versions Before Deploy
if: steps.DowngradePolicy.outputs.failOnAppVersionDowngrade == 'true'
uses: microsoft/AL-Go-Actions/CheckDowngrade@main
Comment on lines +91 to +92
$installedApps = Get-BcInstalledExtensions -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName |
Where-Object { $_.isInstalled }

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.

A few smaller comments but otherwise looks good to me. Thanks for contributing! 🚀


- name: Validate App Versions Before Deploy
if: steps.DowngradePolicy.outputs.failOnAppVersionDowngrade == 'true'
uses: microsoft/AL-Go-Actions/CheckDowngrade@main

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.

We also have a deploy step in PublishToEnvironment.yaml. We might need to do something similar there

- name: Deploy to Business Central
id: Deploy
uses: microsoft/AL-Go-Actions/Deploy@main
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifactsFolder: '.artifacts'
type: 'Publish'
deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }}
artifactsVersion: ${{ github.event.inputs.appVersion }}

- name: Determine Downgrade Policy
id: DowngradePolicy
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0

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.

Personally, I'm not a huge fan on PowerShell embedded in the yaml files like this. I'm wondering if we could just check if failOnAppVersionDowngrade is true as the first thing inside the CheckDowngrade action. If it is false, then we just exit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants