RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Configs/Copilot instructions/PowerShell/PowerShell

Copilot instructions

.github/instructions/powershell-module-organization.instructions.md
Copilot instructions

Quality

69/100

Scores the file, not the repository.

Length

672 words

21 headings · 5 code blocks

Repository

55k

— · pushed 2 days ago

Last changed

3 days ago

First indexed 3 days ago.
PowerShell/PowerShell/.github/instructions/powershell-module-organization.instructions.mdRawGitHub
1---
2applyTo:
3 - "tools/ci.psm1"
4 - "build.psm1"
5 - "tools/packaging/**/*.psm1"
6 - ".github/**/*.yml"
7 - ".github/**/*.yaml"
8---
9 
10# Guidelines for PowerShell Code Organization
11 
12## When to Move Code from YAML to PowerShell Modules
13 
14PowerShell code in GitHub Actions YAML files should be kept minimal. Move code to a module when:
15 
16### Size Threshold
17- **More than ~30 lines** of PowerShell in a YAML file step
18- **Any use of .NET types** like `[regex]`, `[System.IO.Path]`, etc.
19- **Complex logic** requiring multiple nested loops or conditionals
20- **Reusable functionality** that might be needed elsewhere
21 
22### Indicators to Move Code
231. Using .NET type accelerators (`[regex]`, `[PSCustomObject]`, etc.)
242. Complex string manipulation or parsing
253. File system operations beyond basic reads/writes
264. Logic that would benefit from unit testing
275. Code that's difficult to read/maintain in YAML format
28 
29## Which Module to Use
30 
31### ci.psm1 (`tools/ci.psm1`)
32**Purpose**: CI/CD-specific operations and workflows
33 
34**Use for**:
35- Build orchestration (invoking builds, tests, packaging)
36- CI environment setup and configuration
37- Test execution and result processing
38- Artifact handling and publishing
39- CI-specific validations and checks
40- Environment variable management for CI
41 
42**Examples**:
43- `Invoke-CIBuild` - Orchestrates build process
44- `Invoke-CITest` - Runs Pester tests
45- `Test-MergeConflictMarker` - Validates files for conflicts
46- `Set-BuildVariable` - Manages CI variables
47 
48**When NOT to use**:
49- Core build operations (use build.psm1)
50- Package creation logic (use packaging.psm1)
51- Platform-specific build steps
52 
53### build.psm1 (`build.psm1`)
54**Purpose**: Core build operations and utilities
55 
56**Use for**:
57- Compiling source code
58- Resource generation
59- Build configuration management
60- Core build utilities (New-PSOptions, Get-PSOutput, etc.)
61- Bootstrap operations
62- Cross-platform build helpers
63 
64**Examples**:
65- `Start-PSBuild` - Main build function
66- `Start-PSBootstrap` - Bootstrap dependencies
67- `New-PSOptions` - Create build configuration
68- `Start-ResGen` - Generate resources
69 
70**When NOT to use**:
71- CI workflow orchestration (use ci.psm1)
72- Package creation (use packaging.psm1)
73- Test execution
74 
75### packaging.psm1 (`tools/packaging/packaging.psm1`)
76**Purpose**: Package creation and distribution
77 
78**Use for**:
79- Creating distribution packages (MSI, RPM, DEB, etc.)
80- Package-specific metadata generation
81- Package signing operations
82- Platform-specific packaging logic
83 
84**Examples**:
85- `Start-PSPackage` - Create packages
86- `New-MSIXPackage` - Create Windows MSIX
87- `New-DotnetSdkContainerFxdPackage` - Create container packages
88 
89**When NOT to use**:
90- Building binaries (use build.psm1)
91- Running tests (use ci.psm1)
92- General utilities
93 
94## Best Practices
95 
96### Keep YAML Minimal
97```yaml
98# ❌ Bad - too much logic in YAML
99- name: Check files
100 shell: pwsh
101 run: |
102 $files = Get-ChildItem -Recurse
103 foreach ($file in $files) {
104 $content = Get-Content $file -Raw
105 if ($content -match $pattern) {
106 # ... complex processing ...
107 }
108 }
109 
110# ✅ Good - call function from module
111- name: Check files
112 shell: pwsh
113 run: |
114 Import-Module ./tools/ci.psm1
115 Test-SomeCondition -Path ${{ github.workspace }}
116```
117 
118### Document Functions
119Always include comment-based help for functions:
120```powershell
121function Test-MyFunction
122{
123 <#
124 .SYNOPSIS
125 Brief description
126 .DESCRIPTION
127 Detailed description
128 .PARAMETER ParameterName
129 Parameter description
130 .EXAMPLE
131 Test-MyFunction -ParameterName Value
132 #>
133 [CmdletBinding()]
134 param(
135 [Parameter(Mandatory)]
136 [string] $ParameterName
137 )
138 # Implementation
139}
140```
141 
142### Error Handling
143Use proper error handling in modules:
144```powershell
145try {
146 # Operation
147}
148catch {
149 Write-Error "Detailed error message: $_"
150 throw
151}
152```
153 
154### Verbose Output
155Use `Write-Verbose` for debugging information:
156```powershell
157Write-Verbose "Processing file: $filePath"
158```
159 
160## Module Dependencies
161 
162- **ci.psm1** imports both `build.psm1` and `packaging.psm1`
163- **build.psm1** is standalone (minimal dependencies)
164- **packaging.psm1** imports `build.psm1`
165 
166When adding new functions, consider these import relationships to avoid circular dependencies.
167 
168## Testing Modules
169 
170Functions in modules should be testable:
171```powershell
172# Test locally
173Import-Module ./tools/ci.psm1 -Force
174Test-MyFunction -Parameter Value
175 
176# Can be unit tested with Pester
177Describe "Test-MyFunction" {
178 It "Should return expected result" {
179 # Test implementation
180 }
181}
182```
183 
184## Migration Checklist
185 
186When moving code from YAML to a module:
187 
1881. ✅ Determine which module is appropriate (ci, build, or packaging)
1892. ✅ Create function with proper parameter validation
1903. ✅ Add comment-based help documentation
1914. ✅ Use `[CmdletBinding()]` for advanced function features
1925. ✅ Include error handling
1936. ✅ Add verbose output for debugging
1947. ✅ Test the function independently
1958. ✅ Update YAML to call the new function
1969. ✅ Verify the workflow still works end-to-end
197 
198## References
199 
200- PowerShell Advanced Functions: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced
201- Comment-Based Help: https://learn.microsoft.com/powershell/scripting/developer/help/writing-help-for-windows-powershell-scripts-and-functions
202 

Sections

  • Guidelines for PowerShell Code Organization
  • When to Move Code from YAML to PowerShell Modules
  • Size Threshold
  • Indicators to Move Code
  • Which Module to Use
  • ci.psm1 (`tools/ci.psm1`)
  • build.psm1 (`build.psm1`)
  • packaging.psm1 (`tools/packaging/packaging.psm1`)
  • Best Practices
  • Keep YAML Minimal
  • ❌ Bad - too much logic in YAML
  • ✅ Good - call function from module
  • Document Functions
  • Error Handling
  • Verbose Output
  • Module Dependencies
  • Testing Modules
  • Test locally
  • Can be unit tested with Pester
  • Migration Checklist
  • References

What it covers

buildtestcode-stylearchitecturedependenciesdatabase

Stack — with the evidence

csharp

(1.00)

dotnet

(1.00)

github-actions

(0.60)

Glob targeting

  • tools/ci.psm1
  • build.psm1
  • tools/packaging/**/*.psm1
  • .github/**/*.yml
  • .github/**/*.yaml

Format

Copilot instructions

Two layers: one always-on repo file, plus optional glob-scoped instruction files. Lives under .github/ rather than the repo root, which is the tell that it is aimed at the GitHub platform surface as much as the editor.

What the corpus says about it

Repository

Owner
PowerShell
Language
—
License
—
Archived
no

All configs in this repo

Also in PowerShell/PowerShell

Diff this repo’s formats

One 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?

The other instruction files in this repository
RepositoryFormatStackCoversScoreChanged
PowerShell/PowerShell.github/instructions/build-and-packaging-steps.instructions.md · 55kCopilot instructionscsharpdotnet+1buildagent-behaviour58/1003 days ago
PowerShell/PowerShell.github/instructions/build-checkout-prerequisites.instructions.md · 55kCopilot instructionscsharpdotnet+1setupbuildstylearch+181/1003 days ago
PowerShell/PowerShell.github/instructions/build-configuration-guide.instructions.md · 55kCopilot instructionscsharpdotnet+1buildteststyletesting-strategy+274/1003 days ago
PowerShell/PowerShell.github/instructions/code-review-branch-strategy.instructions.md · 55kCopilot instructionscsharpdotnet+1lint-formatstyletypesgit+162/1003 days ago
PowerShell/PowerShell.github/instructions/instruction-file-format.instructions.md · 55kCopilot instructionscsharpdotnet+1buildlint-formatstylearch+376/1003 days ago
PowerShell/PowerShell.github/instructions/log-grouping-guidelines.instructions.md · 55kCopilot instructionscsharpdotnet+1buildtestdo-not77/1003 days ago
PowerShell/PowerShell.github/instructions/onebranch-condition-syntax.instructions.md · 55kCopilot instructionscsharpdotnet+1buildstylearchdeployment+173/1003 days ago
PowerShell/PowerShell.github/instructions/onebranch-restore-phase-pattern.instructions.md · 55kCopilot instructionscsharpdotnet+1arch54/1003 days ago
PowerShell/PowerShell.github/instructions/onebranch-signing-configuration.instructions.md · 55kCopilot instructionscsharpdotnet+1buildstyledeployment62/1003 days ago
PowerShell/PowerShell.github/instructions/pester-set-itresult-pattern.instructions.md · 55kCopilot instructionscsharpdotnet+1setupstylearch62/1003 days ago
PowerShell/PowerShell.github/instructions/pester-test-status-and-working-meaning.instructions.md · 55kCopilot instructionscsharpdotnet+1teststyle54/1003 days ago
PowerShell/PowerShell.github/instructions/powershell-automatic-variables.instructions.md · 55kCopilot instructionscsharpdotnet+1stylearchgitdeployment+169/1003 days ago
PowerShell/PowerShell.github/instructions/powershell-parameter-naming.instructions.md · 55kCopilot instructionscsharpdotnet+1styledo-not65/1003 days ago
PowerShell/PowerShell.github/instructions/publishing-pester-result.instructions.md · 55kCopilot instructionscsharpdotnet+1testlint-formatstylearch+369/1003 days ago
PowerShell/PowerShell.github/instructions/script-module-file-format.instructions.md · 55kCopilot instructionscsharpdotnet+1lint-format54/1003 days ago
PowerShell/PowerShell.github/instructions/start-native-execution.instructions.md · 55kCopilot instructionscsharpdotnet+1buildstylearchgit+186/1003 days ago
PowerShell/PowerShell.github/instructions/start-psbuild-basics.instructions.md · 55kCopilot instructionscsharpdotnet+1buildtesting-strategydeploymentagent-behaviour54/1003 days ago
PowerShell/PowerShell.github/instructions/troubleshooting-builds.instructions.md · 55kCopilot instructionscsharpdotnet+1buildgitdeployment54/1003 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.

Same format, overlapping stack, ranked by quality
RepositoryFormatStackCoversScoreChanged
chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63Copilot instructionstypescriptreact+7buildlint-formatstylearch+4100/1003 days ago
louislam/uptime-kuma.github/copilot-instructions.md · 90kCopilot instructionstypescriptjavascript+10setupbuildtestlint-format+9100/1003 days ago
pytorch/pytorch.github/copilot-instructions.md · 102kCopilot instructionspythonpytorch+4setupbuildteststyle+5100/1003 days ago
dotnet/roslyn.github/instructions/Compiler.instructions.md · 21kCopilot instructionscsharpdotnet+1buildteststylearch+399/1003 days ago
hiyouga/LlamaFactory.github/copilot-instructions.md · 74kCopilot instructionspythontransformers+4setupbuildtestlint-format+597/1002 days ago
rtk-ai/rtk.github/copilot-instructions.md · 74kCopilot instructionsrustgithub-actionsbuildtestlint-formatstyle+297/1003 days ago
JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31kCopilot instructionstypescriptnode+7buildlint-formatstylearch+397/1002 days ago
dotnet/roslyn.github/copilot-instructions.md · 21kCopilot instructionscsharpdotnet+1buildteststylearch+397/1003 days ago
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack