Copilot instructions
.github/instructions/powershell-module-organization.instructions.mdCopilot instructions
Quality
69/100
Scores the file, not the repository.Length
672 words
21 headings · 5 code blocksRepository
55k
— · pushed 2 days agoLast changed
3 days ago
First indexed 3 days ago.12345678910# Guidelines for PowerShell Code Organization1112## When to Move Code from YAML to PowerShell Modules1314PowerShell code in GitHub Actions YAML files should be kept minimal. Move code to a module when:1516### Size Threshold17- **More than ~30 lines** of PowerShell in a YAML file step18- **Any use of .NET types** like `[regex]`, `[System.IO.Path]`, etc.19- **Complex logic** requiring multiple nested loops or conditionals20- **Reusable functionality** that might be needed elsewhere2122### Indicators to Move Code231. Using .NET type accelerators (`[regex]`, `[PSCustomObject]`, etc.)242. Complex string manipulation or parsing253. File system operations beyond basic reads/writes264. Logic that would benefit from unit testing275. Code that's difficult to read/maintain in YAML format2829## Which Module to Use3031### ci.psm1 (`tools/ci.psm1`)32**Purpose**: CI/CD-specific operations and workflows3334**Use for**:35- Build orchestration (invoking builds, tests, packaging)36- CI environment setup and configuration37- Test execution and result processing38- Artifact handling and publishing39- CI-specific validations and checks40- Environment variable management for CI4142**Examples**:43- `Invoke-CIBuild` - Orchestrates build process44- `Invoke-CITest` - Runs Pester tests45- `Test-MergeConflictMarker` - Validates files for conflicts46- `Set-BuildVariable` - Manages CI variables4748**When NOT to use**:49- Core build operations (use build.psm1)50- Package creation logic (use packaging.psm1)51- Platform-specific build steps5253### build.psm1 (`build.psm1`)54**Purpose**: Core build operations and utilities5556**Use for**:57- Compiling source code58- Resource generation59- Build configuration management60- Core build utilities (New-PSOptions, Get-PSOutput, etc.)61- Bootstrap operations62- Cross-platform build helpers6364**Examples**:65- `Start-PSBuild` - Main build function66- `Start-PSBootstrap` - Bootstrap dependencies67- `New-PSOptions` - Create build configuration68- `Start-ResGen` - Generate resources6970**When NOT to use**:71- CI workflow orchestration (use ci.psm1)72- Package creation (use packaging.psm1)73- Test execution7475### packaging.psm1 (`tools/packaging/packaging.psm1`)76**Purpose**: Package creation and distribution7778**Use for**:79- Creating distribution packages (MSI, RPM, DEB, etc.)80- Package-specific metadata generation81- Package signing operations82- Platform-specific packaging logic8384**Examples**:85- `Start-PSPackage` - Create packages86- `New-MSIXPackage` - Create Windows MSIX87- `New-DotnetSdkContainerFxdPackage` - Create container packages8889**When NOT to use**:90- Building binaries (use build.psm1)91- Running tests (use ci.psm1)92- General utilities9394## Best Practices9596### Keep YAML Minimal97```yaml98# ❌ Bad - too much logic in YAML99- name: Check files100 shell: pwsh101 run: |102 $files = Get-ChildItem -Recurse103 foreach ($file in $files) {104 $content = Get-Content $file -Raw105 if ($content -match $pattern) {106 # ... complex processing ...107 }108 }109110# ✅ Good - call function from module111- name: Check files112 shell: pwsh113 run: |114 Import-Module ./tools/ci.psm1115 Test-SomeCondition -Path ${{ github.workspace }}116```117118### Document Functions119Always include comment-based help for functions:120```powershell121function Test-MyFunction122{123 <#124 .SYNOPSIS125 Brief description126 .DESCRIPTION127 Detailed description128 .PARAMETER ParameterName129 Parameter description130 .EXAMPLE131 Test-MyFunction -ParameterName Value132 #>133 [CmdletBinding()]134 param(135 [Parameter(Mandatory)]136 [string] $ParameterName137 )138 # Implementation139}140```141142### Error Handling143Use proper error handling in modules:144```powershell145try {146 # Operation147}148catch {149 Write-Error "Detailed error message: $_"150 throw151}152```153154### Verbose Output155Use `Write-Verbose` for debugging information:156```powershell157Write-Verbose "Processing file: $filePath"158```159160## Module Dependencies161162- **ci.psm1** imports both `build.psm1` and `packaging.psm1`163- **build.psm1** is standalone (minimal dependencies)164- **packaging.psm1** imports `build.psm1`165166When adding new functions, consider these import relationships to avoid circular dependencies.167168## Testing Modules169170Functions in modules should be testable:171```powershell172# Test locally173Import-Module ./tools/ci.psm1 -Force174Test-MyFunction -Parameter Value175176# Can be unit tested with Pester177Describe "Test-MyFunction" {178 It "Should return expected result" {179 # Test implementation180 }181}182```183184## Migration Checklist185186When moving code from YAML to a module:1871881. ✅ Determine which module is appropriate (ci, build, or packaging)1892. ✅ Create function with proper parameter validation1903. ✅ Add comment-based help documentation1914. ✅ Use `[CmdletBinding()]` for advanced function features1925. ✅ Include error handling1936. ✅ Add verbose output for debugging1947. ✅ Test the function independently1958. ✅ Update YAML to call the new function1969. ✅ Verify the workflow still works end-to-end197198## References199200- PowerShell Advanced Functions: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced201- Comment-Based Help: https://learn.microsoft.com/powershell/scripting/developer/help/writing-help-for-windows-powershell-scripts-and-functions202
Also in PowerShell/PowerShell
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| PowerShell/PowerShell.github/instructions/build-and-packaging-steps.instructions.md · 55k | Copilot instructions | buildagent-behaviour | 58/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-checkout-prerequisites.instructions.md · 55k | Copilot instructions | setupbuildstylearch+1 | 81/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-configuration-guide.instructions.md · 55k | Copilot instructions | buildteststyletesting-strategy+2 | 74/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/code-review-branch-strategy.instructions.md · 55k | Copilot instructions | lint-formatstyletypesgit+1 | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/instruction-file-format.instructions.md · 55k | Copilot instructions | buildlint-formatstylearch+3 | 76/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/log-grouping-guidelines.instructions.md · 55k | Copilot instructions | buildtestdo-not | 77/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-condition-syntax.instructions.md · 55k | Copilot instructions | buildstylearchdeployment+1 | 73/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-restore-phase-pattern.instructions.md · 55k | Copilot instructions | arch | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-signing-configuration.instructions.md · 55k | Copilot instructions | buildstyledeployment | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/pester-set-itresult-pattern.instructions.md · 55k | Copilot instructions | setupstylearch | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/pester-test-status-and-working-meaning.instructions.md · 55k | Copilot instructions | teststyle | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-automatic-variables.instructions.md · 55k | Copilot instructions | stylearchgitdeployment+1 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-parameter-naming.instructions.md · 55k | Copilot instructions | styledo-not | 65/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/publishing-pester-result.instructions.md · 55k | Copilot instructions | testlint-formatstylearch+3 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/script-module-file-format.instructions.md · 55k | Copilot instructions | lint-format | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/start-native-execution.instructions.md · 55k | Copilot instructions | buildstylearchgit+1 | 86/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/start-psbuild-basics.instructions.md · 55k | Copilot instructions | buildtesting-strategydeploymentagent-behaviour | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/troubleshooting-builds.instructions.md · 55k | Copilot instructions | buildgitdeployment | 54/100 | 3 days ago |
Diff against .github/instructions/build-and-packaging-steps.instructions.md Diff against .github/instructions/build-checkout-prerequisites.instructions.md Diff against .github/instructions/build-configuration-guide.instructions.md Diff against .github/instructions/code-review-branch-strategy.instructions.md Diff against .github/instructions/instruction-file-format.instructions.md Diff against .github/instructions/log-grouping-guidelines.instructions.md Diff against .github/instructions/onebranch-condition-syntax.instructions.md Diff against .github/instructions/onebranch-restore-phase-pattern.instructions.md Diff against .github/instructions/onebranch-signing-configuration.instructions.md Diff against .github/instructions/pester-set-itresult-pattern.instructions.md Diff against .github/instructions/pester-test-status-and-working-meaning.instructions.md Diff against .github/instructions/powershell-automatic-variables.instructions.md Diff against .github/instructions/powershell-parameter-naming.instructions.md Diff against .github/instructions/publishing-pester-result.instructions.md Diff against .github/instructions/script-module-file-format.instructions.md Diff against .github/instructions/start-native-execution.instructions.md Diff against .github/instructions/start-psbuild-basics.instructions.md Diff against .github/instructions/troubleshooting-builds.instructions.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | 3 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 2 days ago | |
| rtk-ai/rtk.github/copilot-instructions.md · 74k | Copilot instructions | buildtestlint-formatstyle+2 | 97/100 | 3 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago |
