Skip to content

Issue 2336 - Option to fail deployment - #2385

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

Thomas Rønn (thomasroennTRM) wants to merge 36 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/.Modules/settings.schema.json Resolved

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 Scenarios/settings.md Resolved

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 Scenarios/settings.md Resolved

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)

…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.

🟡 Changes recommended

The downgrade checks can fail CI/CD for environments Deploy would skip, while dependency installation can still modify an environment before a downgraded target app is rejected.

1 open issue

Review effort: Balanced

Comment thread Actions/Deploy/Deploy.ps1 Resolved
@aholstrup1

Copy link
Copy Markdown
Collaborator

Thomas Rønn (@thomasroennTRM) Sorry for the delay in response. I can see there are a couple of PSScriptanalyzer findings we need to address before merging this, as well as one more comment from copilot. I think the new action you made it just missing on the Publish To Environment workflow as well :)

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.

🟡 Changes recommended

The preflight consumes single-use device-login codes before Deploy can authenticate and rejects environments Deploy would skip, while affected tests expect too few validation calls.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread Tests/Deploy.Action.Test.ps1 Resolved

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.

🟡 Changes recommended

The downgrade preflight checks production environments that Deploy intentionally skips, causing workflows to fail for targets that would not receive a deployment.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread RELEASENOTES.md Resolved
Clarified the behavior of the new `CheckDowngrade` action regarding version checks and deployment processes.

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.

🔵 Needs a closer look

The downgrade precheck omits Deploy’s production-environment skip rules, so environments that will not receive a deployment can incorrectly fail the job when an installed app is newer.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

🟡 Changes recommended

Unescaped multiline AuthContext masking can expose credentials in workflow logs, and downgrade validation can fail targets that deployment would skip.

1 open issue

Review effort: Balanced

… the multiline AuthContext before masking it.

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.

🔵 Needs a closer look

The downgrade preflight omits Deploy.ps1’s production eligibility guards, so deployments that should be skipped can instead fail the workflow during version checks.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

🟡 Changes recommended

Missing helper exports break both actions even when downgrade checking is disabled, and the new tests invoke real API-selection code instead of validating the intended behavior.

3 open issues

Review effort: Balanced

Comment on lines +125 to +126
return $false
}
Comment on lines +483 to +485
Mock CheckInstalledApps { $script:checkBeforePublish = -not $script:publishCalled }
Mock Publish-PerTenantExtensionApps { $script:publishCalled = $true }
Mock Publish-BcContainerApp { $script:publishCalled = $true }
Comment on lines +91 to +92
$installedApps = Get-BcInstalledExtensions -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName |
Where-Object { $_.isInstalled }

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.

5 participants