Skip to content

Add VersionChecker to detect and warn about newer Bicep CLI installations#18375

Open
polatengin wants to merge 9 commits intomainfrom
polatengin/5070-try-to-identify-when-two-versions-of-bicep-are-installed-on-the-system
Open

Add VersionChecker to detect and warn about newer Bicep CLI installations#18375
polatengin wants to merge 9 commits intomainfrom
polatengin/5070-try-to-identify-when-two-versions-of-bicep-are-installed-on-the-system

Conversation

@polatengin
Copy link
Copy Markdown
Member

@polatengin polatengin commented Oct 30, 2025

VersionChecker helper scans well-known install locations, runs bicep --version to parse versions, and reports any installations newer than the running CLI.

Fixes #5070

Description

Well-known installation locations checked:

~/.bicep/bin (default location)
~/.azure/bin (Azure CLI installation location)

Windows-specific:

  • C:\Program Files\Bicep CLI
  • C:\Program Files (x86)\Bicep CLI
  • All directories in the PATH environment variable

Linux-specific:

  • /usr/local/bin
  • /usr/bin/
  • All directories in the PATH environment variable

Example Usage

Run any bicep command. You may see this warning in the terminal;

Warning: You are running Bicep CLI version 0.38.1, but newer version(s) are installed on this system:
  - Version 0.40.23 at /usr/local/bin/bicep
  - Version 0.39.47 at ~/.azure/bin/bicep

Checklist

Microsoft Reviewers: Open in CodeFlow

…ions

VersionChecker helper scans well-known install locations, runs `bicep --version` to parse versions, and reports any installations newer than the running CLI.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 30, 2025

Test this change out locally with the following install scripts (Action run 25401026575)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 25401026575
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 25401026575"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 25401026575
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 25401026575"

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 30, 2025

Dotnet Test Results

   102 files   -     42     102 suites   - 42   41m 1s ⏱️ - 35m 23s
12 554 tests +    16  12 554 ✅ +    16  0 💤 ±0  0 ❌ ±0 
28 853 runs   - 14 333  28 853 ✅  - 14 333  0 💤 ±0  0 ❌ ±0 

Results for commit f8c3d61. ± Comparison against base commit 8ea021c.

This pull request removes 1954 and adds 690 tests. Note that renamed tests count towards both.

		nestedProp1: 1
		nestedProp2: 2
		prop1: true
		prop2: false
	1
	2
	\$'")
	prop1: true
	prop2: false
…
Bicep.Cli.IntegrationTests.BuildParamsCommandTests ‑ BuildParams_ResourceInputType_ArrayOfResources_Succeeds
Bicep.Cli.IntegrationTests.BuildParamsCommandTests ‑ BuildParams_ResourceInputType_ComplexNestedObject_Succeeds
Bicep.Cli.IntegrationTests.BuildParamsCommandTests ‑ BuildParams_ResourceInputType_NestedProperty_Succeeds
Bicep.Cli.IntegrationTests.BuildParamsCommandTests ‑ BuildParams_ResourceInputType_WithValidObject_Succeeds
Bicep.Cli.UnitTests.Helpers.VersionCheckerTests ‑ CheckForNewerVersionsAsync_ShouldCheckWindowsLocations_OnWindows
Bicep.Cli.UnitTests.Helpers.VersionCheckerTests ‑ CheckForNewerVersionsAsync_ShouldHandleInvalidVersions
Bicep.Cli.UnitTests.Helpers.VersionCheckerTests ‑ CheckForNewerVersionsAsync_ShouldHandleNonExistentDirectories
Bicep.Cli.UnitTests.Helpers.VersionCheckerTests ‑ CheckForNewerVersionsAsync_ShouldNotRun_WhenShouldCheckIsFalse
Bicep.Cli.UnitTests.Helpers.VersionCheckerTests ‑ CheckForNewerVersionsAsync_ShouldNotWarn_WhenNoNewerVersionsFound
Bicep.Cli.UnitTests.Helpers.VersionCheckerTests ‑ CheckForNewerVersionsAsync_ShouldNotWarn_WhenOlderVersionFound
…

♻️ This comment has been updated with latest results.

Comment thread src/Bicep.Cli/Helpers/VersionChecker.cs
Copy link
Copy Markdown
Member

@anthony-c-martin anthony-c-martin left a comment

Choose a reason for hiding this comment

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

This is a pretty major behavioral change, and could have serious performance implications that we need to think through, as well as product design implications. At minimum, I think we need to cover this as a topic in Bicep Discussions before continuing on with the change.

Generally, I think my feeling with doing this work is that the cons outweigh the pros. Issue #5070 was created a long time ago, and since then, I don't think it's been as much of a problem as we imagined it being.

Comment thread src/Bicep.Cli/Helpers/VersionChecker.cs Outdated
…ing process

Avoid spawning a bicep process and parsing its stdout. Check file existence earlier and read FileVersionInfo.FileVersion, parsing it with Version.TryParse and returning null for missing/invalid versions.
Make VersionChecker.CheckForNewerVersions non-blocking by introducing
CheckForNewerVersionsAsync that runs the scan in a background task with a
100ms timeout and cancellation token. Add a shouldCheck parameter so
callers can skip the scan for lightweight commands or when output is
redirected. Make scanning cancellation-aware and restrict file searches
to the top directory only. Remove scanning of PATH entries from
well-known locations.

Update Program to compute whether the check should run (ShouldCheckForNewerVersions)
and invoke the new async method.
- Add VersionCheckerTests with coverage for:
  - asynchronous check behavior (shouldCheck flag)
  - no/newer/older/multiple versions detection
  - platform-specific install locations (Linux/Windows)
  - non-existent directories, invalid versions, and cancellation handling
- Add TestableVersionChecker to mock Bicep file versions and normalize paths for reliable tests
- Make FindNewerVersions and GetWellKnownInstallLocations public, and make GetBicepVersion protected virtual to allow overriding in tests
- Added a new method to VersionChecker to find newer Bicep CLI installations and return their versions along with Git commit SHAs.
- Updated the RootCommand to print the current Bicep CLI version, OS details, and any newer installations found.
- Refactored version parsing logic to handle Git commit SHAs and normalize version formats.
- Improved test coverage for version checking, including scenarios for newer versions and OS-specific paths.
- Enhanced the IEnvironment interface to expose operating system version and architecture information.
…o-identify-when-two-versions-of-bicep-are-installed-on-the-system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Try to identify when two versions of bicep are installed on the system

3 participants