Skip to content

fix(pipeline): use git show to read ado-cargo-config.toml (bypass partial clone) - #52

Merged
Shengyu Fu (shengyfu) merged 3 commits into
mainfrom
fix/pipeline-partial-clone-cargo-config
Apr 19, 2026
Merged

fix(pipeline): use git show to read ado-cargo-config.toml (bypass partial clone)#52
Shengyu Fu (shengyfu) merged 3 commits into
mainfrom
fix/pipeline-partial-clone-cargo-config

Conversation

@msftsiwei

Copy link
Copy Markdown
Member

Problem

ADO build 13878026 failed with:

Copy-Item : Cannot find path 'C:\__w\1\s\.github\workflows\ado-cargo-config.toml' because it does not exist.

Root Cause

OneBranch pipeline uses partial clone (--filter=blob:none). After git sparse-checkout disable, the working tree appears clean but file blobs are not fetched. Copy-Item fails because the file content was never downloaded.

Fix

Replace Copy-Item with git 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-Content line in the arm64 job.

Copilot AI review requested due to automatic review settings April 19, 2026 02:05

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.

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-Item of .github/workflows/ado-cargo-config.toml with git show HEAD:<path> piped to Out-File.
  • Remove a leftover Get-Content in 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 utf8NoBOM is not available in Windows PowerShell 5.1 used by Azure Pipelines powershell: steps, so this may break the arm64 job. Use a PowerShell 5.1-compatible BOM-less write approach (or run the step under pwsh:), and explicitly fail when git show cannot 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

Comment on lines 140 to +143
$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"

Copilot AI Apr 19, 2026

Copy link

Choose a reason for hiding this comment

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

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"

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 19, 2026 04:06
@shengyfu
Shengyu Fu (shengyfu) enabled auto-merge (squash) April 19, 2026 04:07

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'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

Comment on lines +142 to +144
$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))

Copilot AI Apr 19, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
$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))

Copilot uses AI. Check for mistakes.
@shengyfu
Shengyu Fu (shengyfu) force-pushed the fix/pipeline-partial-clone-cargo-config branch from 007ee1b to f22b416 Compare April 19, 2026 04:12
Copilot AI review requested due to automatic review settings April 19, 2026 04:28
@shengyfu
Shengyu Fu (shengyfu) merged commit b71ecaa into main Apr 19, 2026
7 checks passed
@shengyfu
Shengyu Fu (shengyfu) deleted the fix/pipeline-partial-clone-cargo-config branch April 19, 2026 04:28

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'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

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.

3 participants