fix(pipeline): inline cargo config to avoid git dependency in windows_build_container - #53
Conversation
…_build_container OneBranch windows_build_container strips .git and uses partial clone (--filter=blob:none), so git commands fail. Write config inline via PowerShell Set-Content instead of relying on git show or file presence.
There was a problem hiding this comment.
Pull request overview
This PR updates the OneBranch sign-and-release workflow to make the ADO Cargo configuration independent of git metadata and local blob availability, which is necessary in windows_build_container (no .git, partial clone with missing blobs).
Changes:
- Replace
git show-based materialization of.cargo/config.tomlwith an inline PowerShellSet-Contentwrite. - Apply the same inline config generation in both Windows x64 and Windows arm64 signing jobs.
- Update step naming/commentary to reflect the new approach.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/sign-and-release.yml |
Writes ADO-specific Cargo config inline to avoid reliance on .git/blob presence in OneBranch Windows build containers. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
.github/workflows/sign-and-release.yml:159
Set-Content -Encoding UTF8in Windows PowerShell 5.1 writes a UTF-8 BOM. Previously this step wrote UTF-8 without BOM (viaUTF8Encoding($false)), and some TOML consumers can choke on a BOM at the beginning of the file. Consider writing the file with an explicit no-BOM UTF8 encoding (e.g., keep using[System.IO.File]::WriteAllText/WriteAllLineswithUTF8Encoding($false)), while still inlining the content.
$lines = @(
'[registries.devdiv-deepprompt]',
'index = "sparse+https://pkgs.dev.azure.com/devdiv/_packaging/DeepPrompt/Cargo/index/"',
'',
'[source.crates-io]',
'replace-with = "devdiv-deepprompt"',
'',
'[source.devdiv-deepprompt]',
'registry = "sparse+https://pkgs.dev.azure.com/devdiv/_packaging/DeepPrompt/Cargo/index/"',
'',
'[target.x86_64-pc-windows-msvc]',
'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE /CETCOMPAT"]',
'',
'[target.aarch64-pc-windows-msvc]',
'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE"]'
)
$lines | Set-Content -Path "$dstDir\config.toml" -Encoding UTF8 -Force
Write-Host "Written: $dstDir\config.toml"
.github/workflows/sign-and-release.yml:157
- The same TOML payload is duplicated in both Windows jobs. This creates a maintenance risk if the registry URL or rustflags need to change (the two blocks can silently diverge). Consider factoring this into a single reusable YAML anchor/variable, or generating it from a shared PowerShell here-string/function reused by both jobs.
$lines = @(
'[registries.devdiv-deepprompt]',
'index = "sparse+https://pkgs.dev.azure.com/devdiv/_packaging/DeepPrompt/Cargo/index/"',
'',
'[source.crates-io]',
'replace-with = "devdiv-deepprompt"',
'',
'[source.devdiv-deepprompt]',
'registry = "sparse+https://pkgs.dev.azure.com/devdiv/_packaging/DeepPrompt/Cargo/index/"',
'',
'[target.x86_64-pc-windows-msvc]',
'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE /CETCOMPAT"]',
'',
'[target.aarch64-pc-windows-msvc]',
'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE"]'
)
- Files reviewed: 1/1 changed files
- Comments generated: 1
| # OneBranch uses windows_build_container which strips .git and | ||
| # uses partial clone (--filter=blob:none), so file blobs are not | ||
| # on disk and git commands fail. We write the config inline here. | ||
| # Content mirrors .pipelines/.cargo/config.toml in the repo. |
There was a problem hiding this comment.
The comment says the inline content mirrors .pipelines/.cargo/config.toml, but this repo doesn’t appear to have a .pipelines directory. It looks like the source-of-truth is .github/workflows/ado-cargo-config.toml (the file that used to be git show’d). Update the comment (and consider removing/relocating the now-unreferenced TOML file to avoid future drift).
This issue also appears in the following locations of the same file:
- line 142
- line 142
| # Content mirrors .pipelines/.cargo/config.toml in the repo. | |
| # Content mirrors .github/workflows/ado-cargo-config.toml in the repo. |
There was a problem hiding this comment.
Fixed: updated the comment to remove the stale .pipelines reference, and deleted .github/workflows/ado-cargo-config.toml from this branch since it is no longer referenced.
… .pipelines/.cargo/
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:297
- Same as the x64 job:
Set-Content -Encoding UTF8on Windows PowerShell 5.1 writes UTF-8 with BOM, whereas the previous implementation wrote UTF-8 without BOM. Consider writing the joined$lineswithUTF8Encoding($false)to keep the file format stable across agents.
'[target.aarch64-pc-windows-msvc]',
'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE"]'
)
$lines | Set-Content -Path "$dstDir\config.toml" -Encoding UTF8 -Force
Write-Host "Written: $dstDir\config.toml"
- Files reviewed: 2/2 changed files
- Comments generated: 4
| $lines | Set-Content -Path "$dstDir\config.toml" -Encoding UTF8 -Force | ||
| Write-Host "Written: $dstDir\config.toml" |
There was a problem hiding this comment.
This switches the config write from an explicit UTF-8 without BOM (previous UTF8Encoding($false)) to Set-Content -Encoding UTF8, which in Windows PowerShell 5.1 writes UTF-8 with BOM. To preserve the prior on-disk format (and avoid any BOM-sensitive TOML consumers), write via .NET with new UTF8Encoding($false) (or equivalent) using the $lines array content.
This issue also appears on line 293 of the same file.
| $lines | Set-Content -Path "$dstDir\config.toml" -Encoding UTF8 -Force | |
| Write-Host "Written: $dstDir\config.toml" | |
| $configPath = "$dstDir\config.toml" | |
| $utf8NoBom = New-Object System.Text.UTF8Encoding($false) | |
| $content = [string]::Join([Environment]::NewLine, $lines) | |
| [System.IO.File]::WriteAllText($configPath, $content, $utf8NoBom) | |
| Write-Host "Written: $configPath" |
There was a problem hiding this comment.
Fixed: switched to [System.IO.File]::WriteAllText($configPath, $content, $utf8NoBom) with New-Object System.Text.UTF8Encoding($false) to produce UTF-8 without BOM. ADO pipelines run in FullLanguage mode so .NET methods are available.
| # on disk and git commands fail. We write the config inline here. | ||
| # (ado-cargo-config.toml in this directory was the former source | ||
| # of truth; it has been removed since it is no longer referenced.) |
There was a problem hiding this comment.
The top-of-file "How it works" section still states that .github/workflows/ado-cargo-config.toml is copied into .cargo/config.toml, but this PR removes that file and writes the config inline. Please update that header documentation to match the new behavior so future pipeline debugging isn't misled.
| # on disk and git commands fail. We write the config inline here. | |
| # (ado-cargo-config.toml in this directory was the former source | |
| # of truth; it has been removed since it is no longer referenced.) | |
| # on disk and git commands fail. This workflow defines the cargo | |
| # config inline in this step and writes it to .cargo/config.toml. |
There was a problem hiding this comment.
Fixed: the comment now reads "We write the config inline here. (ado-cargo-config.toml in this directory was the former source of truth; it has been removed since it is no longer referenced.)"
| # Step 4: Write ADO-specific .cargo/config.toml. | ||
| # OneBranch uses windows_build_container which strips .git and | ||
| # uses partial clone (--filter=blob:none), so file blobs are not | ||
| # on disk and git commands fail. We write the config inline here. | ||
| # (ado-cargo-config.toml in this directory was the former source | ||
| # of truth; it has been removed since it is no longer referenced.) |
There was a problem hiding this comment.
The PR description mentions mirroring .pipelines/.cargo/config.toml, but this repo doesn't appear to have a .pipelines directory and the prior source of truth was .github/workflows/ado-cargo-config.toml. Please correct the description (or add the referenced file) to avoid confusion about where the canonical config lives.
There was a problem hiding this comment.
Fixed: updated the PR description to correctly reference .github/workflows/ado-cargo-config.toml as the former source of truth.
| $lines = @( | ||
| '[registries.devdiv-deepprompt]', | ||
| 'index = "sparse+https://pkgs.dev.azure.com/devdiv/_packaging/DeepPrompt/Cargo/index/"', | ||
| '', | ||
| '[source.crates-io]', | ||
| 'replace-with = "devdiv-deepprompt"', | ||
| '', | ||
| '[source.devdiv-deepprompt]', | ||
| 'registry = "sparse+https://pkgs.dev.azure.com/devdiv/_packaging/DeepPrompt/Cargo/index/"', | ||
| '', | ||
| '[target.x86_64-pc-windows-msvc]', | ||
| 'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE /CETCOMPAT"]', | ||
| '', | ||
| '[target.aarch64-pc-windows-msvc]', | ||
| 'rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE"]' | ||
| ) |
There was a problem hiding this comment.
The inline $lines = @(... ) config block is duplicated in both jobs. Since this is now the only source of truth, consider de-duplicating via a YAML anchor/alias or a shared template variable to prevent the two copies drifting over time.
There was a problem hiding this comment.
ADO YAML (used by OneBranch) does not support YAML anchors/aliases, so the $lines block cannot be de-duplicated via YAML. A shared template step would require a separate template file and extends: syntax, which is a larger refactor outside the scope of this fix. The duplication is intentional and documented.
Problem
The OneBranch
windows_build_containerstrips.gitand uses partial clone (--filter=blob:none), so:C:\__w\1\sis NOT a git repogit show HEAD:.github/workflows/ado-cargo-config.tomlfails with "fatal: not a git repository"Solution
Write the cargo config inline via PowerShell + .NET
WriteAllTextwithUTF8Encoding($false)(no BOM) instead of relying on git or file presence.Also removes the now-unreferenced
.github/workflows/ado-cargo-config.toml.Notes
[System.IO.File]::WriteAllTextwithnew UTF8Encoding($false)produces UTF-8 without BOM, matching the prior on-disk format$linesblock is intentionally duplicated in both x64 and arm64 jobs — ADO YAML does not support YAML anchors/aliases, so de-duplication is not possible without a shared template