-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Create github copilot setup workflow #26285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
969938a
Create github copilot setup workflow
TravisEz13 2b60d3a
Enhance CI workflow with logging and .NET setup
TravisEz13 f6e3706
Refactor Copilot setup steps and enhance .NET tool installation process
TravisEz13 6d85f63
Apply suggestion from @TravisEz13
TravisEz13 06a26d4
Merge branch 'master' into TravisEz13-patch-6
TravisEz13 a3b18ca
Update workflow triggers for Copilot setup steps to include pull requ…
TravisEz13 ae2f304
Enhance Start-PSBootstrap function to include 'All' option for depend…
TravisEz13 7d0b581
Enhance Find-Dotnet function to restore original PATH and add .NET gl…
TravisEz13 0fab971
Merge branch 'TravisEz13-patch-6' of https://github.com/PowerShell/Po…
TravisEz13 b86fe1c
Apply suggestion from @TravisEz13
daxian-dbw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: "Copilot Setup Steps" | ||
|
|
||
| # Allow testing of the setup steps from your repository's "Actions" tab. | ||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| pull_request: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - ".github/workflows/copilot-setup-steps.yml" | ||
|
|
||
| jobs: | ||
| # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. | ||
| # See https://docs.github.com/en/copilot/customizing-copilot/customizing-the-development-environment-for-copilot-coding-agent | ||
| copilot-setup-steps: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| # You can define any steps you want, and they will run before the agent starts. | ||
| # If you do not check out your code, Copilot will do this for you. | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 1000 | ||
|
|
||
| - name: Bootstrap | ||
| if: success() | ||
| run: |- | ||
| $title = 'Import Build.psm1' | ||
| Write-Host "::group::$title" | ||
| Import-Module ./build.psm1 -Verbose -ErrorAction Stop | ||
| Write-LogGroupEnd -Title $title | ||
|
|
||
| $title = 'Switch to public feed' | ||
| Write-LogGroupStart -Title $title | ||
| Switch-PSNugetConfig -Source Public | ||
| Write-LogGroupEnd -Title $title | ||
|
|
||
| $title = 'Bootstrap' | ||
| Write-LogGroupStart -Title $title | ||
| Start-PSBootstrap -Scenario DotNet | ||
| Write-LogGroupEnd -Title $title | ||
|
|
||
| $title = 'Install .NET Tools' | ||
| Write-LogGroupStart -Title $title | ||
| Start-PSBootstrap -Scenario Tools | ||
| Write-LogGroupEnd -Title $title | ||
|
|
||
| $title = 'Sync Tags' | ||
| Write-LogGroupStart -Title $title | ||
| Sync-PSTags -AddRemoteIfMissing | ||
| Write-LogGroupEnd -Title $title | ||
|
|
||
| $title = 'Setup .NET environment variables' | ||
| Write-LogGroupStart -Title $title | ||
| Find-DotNet -SetDotnetRoot | ||
| Write-LogGroupEnd -Title $title | ||
| shell: pwsh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2282,7 +2282,12 @@ function Start-PSBootstrap { | |
| [switch]$BuildLinuxArm, | ||
| [switch]$Force, | ||
| [Parameter(Mandatory = $true)] | ||
| [ValidateSet("Package", "DotNet", "Both")] | ||
| # Package: Install dependencies for packaging tools (fpm, rpmbuild, WiX) | ||
| # DotNet: Install the .NET SDK | ||
| # Both: Package and DotNet scenarios | ||
| # Tools: Install .NET global tools (e.g., dotnet-format) | ||
| # All: Install all dependencies (packaging, .NET SDK, and tools) | ||
| [ValidateSet("Package", "DotNet", "Both", "Tools", "All")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed offline, the
The cleanup can be done in a separate PR. |
||
| [string]$Scenario = "Package" | ||
| ) | ||
|
|
||
|
|
@@ -2402,15 +2407,15 @@ function Start-PSBootstrap { | |
|
|
||
| # Install [fpm](https://github.com/jordansissel/fpm) | ||
| # Note: fpm is now only needed for DEB and macOS packages; RPM packages use rpmbuild directly | ||
| if ($Scenario -eq 'Both' -or $Scenario -eq 'Package') { | ||
| if ($Scenario -in 'All', 'Both', 'Package') { | ||
| # Install fpm on Debian-based systems, macOS, and Mariner (where DEB packages are built) | ||
| if (($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner)) -or $environment.IsMacOS) { | ||
| Install-GlobalGem -Sudo $sudo -GemName "dotenv" -GemVersion "2.8.1" | ||
| Install-GlobalGem -Sudo $sudo -GemName "ffi" -GemVersion "1.16.3" | ||
| Install-GlobalGem -Sudo $sudo -GemName "fpm" -GemVersion "1.15.1" | ||
| Install-GlobalGem -Sudo $sudo -GemName "rexml" -GemVersion "3.2.5" | ||
| } | ||
|
|
||
| # For RPM-based systems, ensure rpmbuild is available | ||
| if ($environment.IsLinux -and ($environment.IsRedHatFamily -or $environment.IsSUSEFamily -or $environment.IsMariner)) { | ||
| Write-Verbose -Verbose "Checking for rpmbuild..." | ||
|
|
@@ -2422,7 +2427,7 @@ function Start-PSBootstrap { | |
| } | ||
| } | ||
|
|
||
| if ($Scenario -eq 'DotNet' -or $Scenario -eq 'Both') { | ||
| if ($Scenario -in 'All', 'Both', 'DotNet') { | ||
|
|
||
| Write-Verbose -Verbose "Calling Find-Dotnet from Start-PSBootstrap" | ||
|
|
||
|
|
@@ -2479,6 +2484,19 @@ function Start-PSBootstrap { | |
| } | ||
| } | ||
|
|
||
| if ($Scenario -in 'All', 'Tools') { | ||
| Write-Log -message "Installing .NET global tools" | ||
|
|
||
| # Ensure dotnet is available | ||
| Find-Dotnet | ||
|
|
||
| # Install dotnet-format | ||
| Write-Verbose -Verbose "Installing dotnet-format global tool" | ||
| Start-NativeExecution { | ||
| dotnet tool install --global dotnet-format | ||
| } | ||
| } | ||
|
|
||
| if ($env:TF_BUILD) { | ||
| Write-Verbose -Verbose "--- Start - Capturing nuget sources" | ||
| dotnet nuget list source --format detailed | ||
|
|
@@ -2646,6 +2664,63 @@ function Start-ResGen | |
| } | ||
| } | ||
|
|
||
| function Add-PSEnvironmentPath { | ||
| <# | ||
| .SYNOPSIS | ||
| Adds a path to the process PATH and persists to GitHub Actions workflow if running in GitHub Actions | ||
| .PARAMETER Path | ||
| Path to add to PATH | ||
| .PARAMETER Prepend | ||
| If specified, prepends the path instead of appending | ||
| #> | ||
| param ( | ||
| [Parameter(Mandatory)] | ||
| [string]$Path, | ||
|
|
||
| [switch]$Prepend | ||
| ) | ||
|
|
||
| # Set in current process | ||
| if ($Prepend) { | ||
| $env:PATH = $Path + [IO.Path]::PathSeparator + $env:PATH | ||
| } else { | ||
| $env:PATH += [IO.Path]::PathSeparator + $Path | ||
| } | ||
|
|
||
| # Persist to GitHub Actions workflow if running in GitHub Actions | ||
| if ($env:GITHUB_ACTIONS -eq 'true') { | ||
| Write-Verbose -Verbose "Adding $Path to GITHUB_PATH" | ||
| Add-Content -Path $env:GITHUB_PATH -Value $Path | ||
| } | ||
| } | ||
|
|
||
| function Set-PSEnvironmentVariable { | ||
| <# | ||
| .SYNOPSIS | ||
| Sets an environment variable in the process and persists to GitHub Actions workflow if running in GitHub Actions | ||
| .PARAMETER Name | ||
| The name of the environment variable | ||
| .PARAMETER Value | ||
| The value of the environment variable | ||
| #> | ||
| param ( | ||
| [Parameter(Mandatory)] | ||
| [string]$Name, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$Value | ||
| ) | ||
|
|
||
| # Set in current process | ||
| Set-Item -Path "env:$Name" -Value $Value | ||
|
|
||
| # Persist to GitHub Actions workflow if running in GitHub Actions | ||
| if ($env:GITHUB_ACTIONS -eq 'true') { | ||
| Write-Verbose -Verbose "Setting $Name in GITHUB_ENV" | ||
| Add-Content -Path $env:GITHUB_ENV -Value "$Name=$Value" | ||
| } | ||
| } | ||
|
|
||
| function Find-Dotnet { | ||
| param ( | ||
| [switch] $SetDotnetRoot | ||
|
|
@@ -2676,25 +2751,40 @@ function Find-Dotnet { | |
| if ($dotnetCLIInstalledVersion -ne $chosenDotNetVersion) { | ||
| Write-Warning "The 'dotnet' in the current path can't find SDK version ${dotnetCLIRequiredVersion}, prepending $dotnetPath to PATH." | ||
| # Globally installed dotnet doesn't have the required SDK version, prepend the user local dotnet location | ||
| $env:PATH = $dotnetPath + [IO.Path]::PathSeparator + $env:PATH | ||
| 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 | ||
daxian-dbw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| elseif ($SetDotnetRoot) { | ||
| # If we found dotnet, also add the global tools path to PATH | ||
| # Add .NET global tools to PATH when setting up the environment | ||
| $dotnetToolsPath = Join-Path $dotnetPath "tools" | ||
| if (Test-Path $dotnetToolsPath) { | ||
| Write-Verbose -Verbose "Adding .NET tools path to PATH: $dotnetToolsPath" | ||
| Add-PSEnvironmentPath -Path $dotnetToolsPath | ||
| } | ||
| } | ||
| } | ||
|
|
||
| <# | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.