Add VersionChecker to detect and warn about newer Bicep CLI installations#18375
Conversation
…ions VersionChecker helper scans well-known install locations, runs `bicep --version` to parse versions, and reports any installations newer than the running CLI.
|
Test this change out locally with the following install scripts (Action run 25401026575) VSCode
Azure CLI
|
Dotnet Test Results 102 files - 42 102 suites - 42 41m 1s ⏱️ - 35m 23s 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.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
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.
…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
VersionCheckerhelper scans well-known install locations, runsbicep --versionto 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 CLIC:\Program Files (x86)\Bicep CLILinux-specific:
/usr/local/bin/usr/bin/Example Usage
Run any bicep command. You may see this warning in the terminal;
Checklist
Microsoft Reviewers: Open in CodeFlow