fix(pipeline): use git show to read ado-cargo-config.toml (bypass partial clone) - #52
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the OneBranch/ADO sign-and-release pipeline to reliably materialize ado-cargo-config.toml under partial clone (--filter=blob:none) by reading the file via git show instead of copying from the working tree.
Changes:
- Replace
Copy-Itemof.github/workflows/ado-cargo-config.tomlwithgit show HEAD:<path>piped toOut-File. - Remove a leftover
Get-Contentin the arm64 job step.
Show a summary per file
| File | Description |
|---|---|
| .github/workflows/sign-and-release.yml | Switches the ADO cargo config materialization to git show to bypass partial-clone missing blobs; cleans up arm64 step output. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
.github/workflows/sign-and-release.yml:272
- Same issue here:
Out-File -Encoding utf8NoBOMis not available in Windows PowerShell 5.1 used by Azure Pipelinespowershell:steps, so this may break the arm64 job. Use a PowerShell 5.1-compatible BOM-less write approach (or run the step underpwsh:), and explicitly fail whengit showcannot retrieve the blob (non-zero exit code) to avoid silently continuing with an invalid.cargo/config.toml.
$dstDir = "$(Build.SourcesDirectory)\.cargo"
New-Item -ItemType Directory -Force -Path $dstDir | Out-Null
git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml | Out-File -FilePath "$dstDir\config.toml" -Encoding utf8NoBOM
Write-Host "Written: $dstDir\config.toml"
- Files reviewed: 1/1 changed files
- Comments generated: 1
| $dstDir = "$(Build.SourcesDirectory)\.cargo" | ||
| New-Item -ItemType Directory -Force -Path $dstDir | Out-Null | ||
| Copy-Item -Path $src -Destination "$dstDir\config.toml" -Force | ||
| Write-Host "Copied: $src -> $dstDir\config.toml" | ||
| git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml | Out-File -FilePath "$dstDir\config.toml" -Encoding utf8NoBOM | ||
| Write-Host "Written: $dstDir\config.toml" |
There was a problem hiding this comment.
Out-File -Encoding utf8NoBOM is not supported in Windows PowerShell 5.1 (the default engine for Azure Pipelines powershell: steps). This can cause the pipeline step to fail at runtime. Use an encoding option compatible with Windows PowerShell (or switch the step to pwsh:), and still ensure the file is written without a BOM if Cargo/TOML parsing is sensitive to it. Also consider explicitly failing the step when git show returns a non-zero exit code so the pipeline doesn’t proceed with a missing/empty .cargo/config.toml.
This issue also appears on line 269 of the same file.
See below for a potential fix:
$dstFile = "$dstDir\config.toml"
New-Item -ItemType Directory -Force -Path $dstDir | Out-Null
$content = git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml | Out-String
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to read .github/workflows/ado-cargo-config.toml from git."
exit $LASTEXITCODE
}
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($dstFile, $content, $utf8NoBom)
Write-Host "Written: $dstFile"
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
.github/workflows/sign-and-release.yml:276
- Same issue as the x64 job:
($content -join "n")can join characters ifgit showreturns a scalar string (single-line output), which would produce an invalid.cargo/config.toml`. Make the capture/join logic robust to both string and string[] output so this step can’t silently corrupt the file.
$content = git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml
if ($LASTEXITCODE -ne 0) { throw "git show failed with exit code $LASTEXITCODE" }
[System.IO.File]::WriteAllText("$dstDir\config.toml", ($content -join "`n") + "`n", [System.Text.UTF8Encoding]::new($false))
Write-Host "Written: $dstDir\config.toml"
- Files reviewed: 3/3 changed files
- Comments generated: 1
| $content = git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml | ||
| if ($LASTEXITCODE -ne 0) { throw "git show failed with exit code $LASTEXITCODE" } | ||
| [System.IO.File]::WriteAllText("$dstDir\config.toml", ($content -join "`n") + "`n", [System.Text.UTF8Encoding]::new($false)) |
There was a problem hiding this comment.
In PowerShell, capturing an external command into a variable collapses single-line output into a scalar string. If ado-cargo-config.toml ever becomes a single-line file, ($content -join "n")will join characters rather than lines and corruptconfig.toml. Consider forcing $contentto an array before-join` (e.g., wrap it so it’s always treated as string[]), or capture the output as one raw string and write it directly.
This issue also appears on line 273 of the same file.
| $content = git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml | |
| if ($LASTEXITCODE -ne 0) { throw "git show failed with exit code $LASTEXITCODE" } | |
| [System.IO.File]::WriteAllText("$dstDir\config.toml", ($content -join "`n") + "`n", [System.Text.UTF8Encoding]::new($false)) | |
| $content = (git -C "$(Build.SourcesDirectory)" show HEAD:.github/workflows/ado-cargo-config.toml | Out-String) | |
| if ($LASTEXITCODE -ne 0) { throw "git show failed with exit code $LASTEXITCODE" } | |
| $content = $content.TrimEnd("`r", "`n") | |
| [System.IO.File]::WriteAllText("$dstDir\config.toml", $content + "`n", [System.Text.UTF8Encoding]::new($false)) |
007ee1b to
f22b416
Compare
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
Problem
ADO build 13878026 failed with:
Root Cause
OneBranch pipeline uses partial clone (
--filter=blob:none). Aftergit sparse-checkout disable, the working tree appears clean but file blobs are not fetched.Copy-Itemfails because the file content was never downloaded.Fix
Replace
Copy-Itemwithgit show HEAD:<path>which reads the blob directly from git object store (fetching it on demand if needed), bypassing the partial clone issue.Also removes the leftover
Get-Contentline in the arm64 job.