[release/v7.6] Fix buildinfo.json uploading for preview, LTS, and stable releases#26715
Conversation
There was a problem hiding this comment.
Pull request overview
This PR backports a fix from #25571 to the release/v7.6 branch that improves buildinfo.json uploading logic for preview, LTS, and stable releases. The changes refactor variable names for better clarity and add semantic version comparison to ensure build info files are only uploaded when appropriate.
Changes:
- Improved variable naming from generic names (CopyMainBuildInfo, BuildInfoJsonFile) to more specific names (UploadPreview, PreviewBuildInfoFile, UploadLTS, UploadStable)
- Added semantic version comparison to only upload stable.json when the current version is greater than the existing stable version
- Updated the upload task condition to check all three upload flags (preview, LTS, stable) instead of just one
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $metadata = Get-Content -LiteralPath "$toolsDirectory/metadata.json" -ErrorAction Stop | ConvertFrom-Json | ||
| $stableReleaseTag = $metadata.StableReleaseTag -Replace 'v','' | ||
|
|
||
| $currentReleaseTag = $buildInfo.ReleaseTag -Replace 'v','' |
There was a problem hiding this comment.
The variable $buildInfo is used on line 61 before it's defined. The $buildInfo object is not created until line 69 with $buildInfo = $buildInfoJsonContent | ConvertFrom-Json. This will cause a runtime error when the script tries to access $buildInfo.ReleaseTag on a null or undefined variable.
This line should be removed as line 71 correctly sets $currentReleaseTag after $buildInfo is defined.
| $currentReleaseTag = $buildInfo.ReleaseTag -Replace 'v','' |
| Set-BuildVariable -Name BuildInfoJsonFile -Value $targetFile | ||
|
|
||
| ## Create 'lts.json' if it's the latest stable and also a LTS release. | ||
| Set-BuildVariable -Name PreviewBuildInfoFile -Value $targetFile |
There was a problem hiding this comment.
The PreviewBuildInfoFile variable is set to $targetFile for all file types (preview.json, stable.json, etc.), not just for preview.json files. This variable name suggests it should only contain the preview build info file path, but it's being set regardless of the file type.
Consider either:
- Renaming this variable to something more generic like
BuildInfoFilesince it's used for all types, or - Only setting it when
$fileName -eq "preview.json"(move it inside the if block on line 76)
| [System.Management.Automation.SemanticVersion] $stableVersion = $stableReleaseTag | ||
| [System.Management.Automation.SemanticVersion] $currentVersion = $currentReleaseTag |
There was a problem hiding this comment.
The $stableVersion and $currentVersion semantic version variables are only initialized within the if ($fileName -eq "stable.json") block (lines 86-87), but $stableReleaseTag and $currentReleaseTag are extracted earlier at lines 59 and 71.
The semantic version parsing should happen closer to where the variables are first extracted (after line 71), or the string variables should be extracted just before they're parsed into semantic versions (before line 86). The current approach creates two separate locations where similar logic is applied, which could lead to maintenance issues.
Backport of #25571 to release/v7.6
Triggered by @daxian-dbw on behalf of @jshigetomi
Original CL Label: CL-BuildPackaging
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
This fix is required for the release pipeline to correctly upload buildinfo.json files for preview, LTS, and stable releases. It improves the logic for determining which JSON files should be uploaded based on release type and semantic version comparison.
Customer Impact
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
Verified that buildinfo.json is correctly uploaded for preview, LTS, and stable releases. The changes refactor variable names for clarity and improve semantic version handling to ensure JSON files are only uploaded when appropriate.
Risk
REQUIRED: Check exactly one box.
This is a refinement of release pipeline logic with improved variable naming and conditional checks. The changes are isolated to the build info upload template and do not affect runtime PowerShell functionality.