[release/v7.5] Create github copilot setup workflow#26807
Conversation
Co-authored-by: Dongbo Wang <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR backports a Copilot “setup steps” GitHub Actions workflow to release/v7.5 and extends Start-PSBootstrap to support additional bootstrap scenarios intended to prepare the Copilot agent environment.
Changes:
- Add
.github/workflows/copilot-setup-steps.ymlto run Copilot pre-agent setup viaworkflow_dispatch(and on PR edits to the workflow). - Extend
Start-PSBootstrap -ScenariowithToolsandAll, and installdotnet-formatas a global tool for theToolsscenario. - Add helpers to persist PATH/environment variables into GitHub Actions job environment and update
Find-Dotnetto use them.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| build.psm1 | Adds new bootstrap scenarios, installs .NET global tools, and persists PATH/DOTNET_ROOT to GitHub Actions environment files. |
| .github/workflows/copilot-setup-steps.yml | Introduces a Copilot setup workflow to run bootstrap/tag sync/environment setup steps before the agent starts. |
|
|
||
| pull_request: | ||
| branches: | ||
| - master |
There was a problem hiding this comment.
This workflow’s pull_request trigger is restricted to master. Since this file is being backported to release/v7.5, PRs targeting release/** (including this branch) won’t run the workflow to validate changes. Consider adding release/** (matching other CI workflows here) or removing the branch filter so edits are validated on release branches too.
| - master | |
| - master | |
| - release/** |
| # All: Install all dependencies (packaging, .NET SDK, and tools) | ||
| [ValidateSet("Package", "DotNet", "Both", "Tools", "All")] |
There was a problem hiding this comment.
Scenario = 'All' is documented as installing packaging + .NET SDK + tools, but several dependency-install branches earlier in Start-PSBootstrap still only check for Both/Package (e.g., OS package deps, WiX on Windows). As-is, All won't actually include all packaging dependencies. Update the other $Scenario -eq 'Both' -or $Scenario -eq 'Package' checks to include All (or switch them to the same -in 'All','Both','Package' pattern used below).
| # All: Install all dependencies (packaging, .NET SDK, and tools) | |
| [ValidateSet("Package", "DotNet", "Both", "Tools", "All")] | |
| [ValidateSet("Package", "DotNet", "Both", "Tools")] |
| # Install dotnet-format | ||
| Write-Verbose -Verbose "Installing dotnet-format global tool" | ||
| Start-NativeExecution { | ||
| dotnet tool install --global dotnet-format | ||
| } |
There was a problem hiding this comment.
The .NET global tools install uses dotnet tool install --global dotnet-format, which is not idempotent (it fails if the tool is already installed). Consider switching to dotnet tool update --global or checking dotnet tool list --global first so Start-PSBootstrap can be safely re-run.
| # Install dotnet-format | |
| Write-Verbose -Verbose "Installing dotnet-format global tool" | |
| Start-NativeExecution { | |
| dotnet tool install --global dotnet-format | |
| } | |
| # Ensure dotnet-format is installed as a global tool (idempotent) | |
| Write-Verbose -Verbose "Ensuring dotnet-format global tool is installed" | |
| $dotnetToolListOutput = Start-NativeExecution -IgnoreExitcode { | |
| dotnet tool list --global | |
| } | |
| $dotnetFormatInstalled = $false | |
| if ($LASTEXITCODE -eq 0 -and $dotnetToolListOutput -match '^\s*dotnet-format\b') { | |
| $dotnetFormatInstalled = $true | |
| } | |
| if ($dotnetFormatInstalled) { | |
| Write-Verbose -Verbose "dotnet-format is already installed. Updating global tool." | |
| Start-NativeExecution { | |
| dotnet tool update --global dotnet-format | |
| } | |
| } | |
| else { | |
| Write-Verbose -Verbose "dotnet-format is not installed. Installing global tool." | |
| Start-NativeExecution { | |
| dotnet tool install --global dotnet-format | |
| } | |
| } |
| Add-PSEnvironmentPath -Path $dotnetPath -Prepend | ||
|
|
||
| if ($SetDotnetRoot) { | ||
| Write-Verbose -Verbose "Setting DOTNET_ROOT to $dotnetPath" | ||
| $env:DOTNET_ROOT = $dotnetPath | ||
| Set-PSEnvironmentVariable -Name 'DOTNET_ROOT' -Value $dotnetPath | ||
| } | ||
| } elseif ($SetDotnetRoot) { | ||
| Write-Verbose -Verbose "Expected dotnet version found, setting DOTNET_ROOT to $dotnetPath" | ||
| $env:DOTNET_ROOT = $dotnetPath | ||
| Set-PSEnvironmentVariable -Name 'DOTNET_ROOT' -Value $dotnetPath | ||
| } | ||
| } | ||
| else { | ||
| Write-Warning "Could not find 'dotnet', appending $dotnetPath to PATH." | ||
| $env:PATH += [IO.Path]::PathSeparator + $dotnetPath | ||
| Add-PSEnvironmentPath -Path $dotnetPath | ||
|
|
||
| if ($SetDotnetRoot) { | ||
| Write-Verbose -Verbose "Setting DOTNET_ROOT to $dotnetPath" | ||
| Set-PSEnvironmentVariable -Name 'DOTNET_ROOT' -Value $dotnetPath | ||
| } | ||
| } | ||
|
|
||
| if (-not (precheck 'dotnet' "Still could not find 'dotnet', restoring PATH.")) { | ||
| # Give up, restore original PATH. There is nothing to persist since we didn't make a change. | ||
| $env:PATH = $originalPath | ||
| } |
There was a problem hiding this comment.
Find-Dotnet now persists PATH/DOTNET_ROOT to GitHub Actions via Add-PSEnvironmentPath/Set-PSEnvironmentVariable before the final precheck succeeds. If precheck fails, the code restores only $env:PATH, but any prior writes to $GITHUB_PATH/$GITHUB_ENV (and DOTNET_ROOT in-process) remain, leaving the job environment inconsistent. Persist only after the final precheck passes, or stage changes locally and write to GitHub env files conditionally on success.
| # Add .NET global tools to PATH when setting up the environment | ||
| $dotnetToolsPath = Join-Path $dotnetPath "tools" |
There was a problem hiding this comment.
The global tools PATH being added uses Join-Path $dotnetPath "tools". On Windows, dotnet tool install --global typically installs to $env:USERPROFILE\.dotnet\tools, not under $env:LocalAppData\Microsoft\dotnet\tools, so this may not put global tools on PATH. Consider computing the tools path per-platform (or from DOTNET_CLI_HOME/USERPROFILE) to ensure dotnet-format is discoverable.
| # Add .NET global tools to PATH when setting up the environment | |
| $dotnetToolsPath = Join-Path $dotnetPath "tools" | |
| # Compute .NET global tools path based on DOTNET_CLI_HOME/USERPROFILE/HOME | |
| $dotnetCliHome = if (-not [string]::IsNullOrWhiteSpace($env:DOTNET_CLI_HOME)) { | |
| $env:DOTNET_CLI_HOME | |
| } | |
| elseif ($environment.IsWindows) { | |
| $env:USERPROFILE | |
| } | |
| else { | |
| $env:HOME | |
| } | |
| $dotnetToolsRoot = Join-Path $dotnetCliHome ".dotnet" | |
| $dotnetToolsPath = Join-Path $dotnetToolsRoot "tools" |
Backport of #26285 to release/v7.5
Triggered by @daxian-dbw on behalf of @TravisEz13
Original CL Label: CL-Tools
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Adds a new GitHub Actions workflow for Copilot setup steps that allows testing and customization of the environment setup. Also adds new bootstrap scenarios (Tools, All) to build.psm1.
Customer Impact
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
The workflow can be tested from the Actions tab using workflow_dispatch. The new bootstrap scenarios were validated as part of the original PR.
Risk
REQUIRED: Check exactly one box.
Only adds new optional tooling workflow and new bootstrap scenarios. Does not modify existing behavior or critical code paths.