Skip to content

Commit c3bc2fa

Browse files
Create comprehensive GitHub Copilot instruction file
Co-authored-by: MariusStorhaug <[email protected]>
1 parent 464110a commit c3bc2fa

File tree

1 file changed

+320
-0
lines changed

1 file changed

+320
-0
lines changed

.github/copilot-instructions.md

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
# GitHub Copilot Instructions for Process-PSModule
2+
3+
This repository provides a comprehensive GitHub Actions workflow system for PowerShell module development, testing, building, and publishing. When contributing to this project or using it as a reference, please follow these guidelines and patterns.
4+
5+
## Repository Overview
6+
7+
**Process-PSModule** is a reusable workflow that:
8+
- Builds, tests, and publishes PowerShell modules using the PSModule framework
9+
- Provides multi-OS testing (Linux, macOS, Windows)
10+
- Generates documentation and publishes to GitHub Pages
11+
- Publishes modules to PowerShell Gallery
12+
- Follows Test-Driven Development and Continuous Delivery practices
13+
14+
## PowerShell Development Standards
15+
16+
### Code Structure
17+
- **Public Functions**: Place in `src/functions/public/`
18+
- **Private Functions**: Place in `src/functions/private/`
19+
- **Classes**: Place in `src/classes/public/` or `src/classes/private/`
20+
- **Data Files**: Place in `src/data/` (`.psd1` files)
21+
- **Module Manifest**: `src/manifest.psd1`
22+
23+
### Function Standards
24+
```powershell
25+
function Verb-Noun {
26+
<#
27+
.SYNOPSIS
28+
Brief description of what the function does.
29+
30+
.DESCRIPTION
31+
Detailed description of the function's purpose and behavior.
32+
33+
.PARAMETER ParameterName
34+
Description of the parameter.
35+
36+
.EXAMPLE
37+
Verb-Noun -ParameterName 'Value'
38+
39+
Description of what this example does.
40+
41+
.NOTES
42+
Additional notes about the function.
43+
44+
.LINK
45+
https://github.com/PSModule/Process-PSModule
46+
#>
47+
[CmdletBinding()]
48+
param (
49+
# Parameter description
50+
[Parameter(Mandatory)]
51+
[string] $ParameterName
52+
)
53+
54+
begin {
55+
# Initialization code
56+
}
57+
58+
process {
59+
# Main function logic
60+
}
61+
62+
end {
63+
# Cleanup code
64+
}
65+
}
66+
```
67+
68+
### Code Style Requirements
69+
70+
Based on PSScriptAnalyzer configuration:
71+
72+
#### Indentation and Spacing
73+
- Use **4 spaces** for indentation (no tabs)
74+
- Maximum line length: **150 characters**
75+
- Place opening braces on the same line
76+
- Place closing braces on new line
77+
- Use consistent whitespace around operators and separators
78+
79+
#### Bracing Style
80+
```powershell
81+
# Correct
82+
if ($condition) {
83+
Write-Output "Good"
84+
}
85+
86+
# Incorrect
87+
if ($condition)
88+
{
89+
Write-Output "Bad"
90+
}
91+
```
92+
93+
#### Variable and Parameter Naming
94+
- Use PascalCase for parameters: `$ModuleName`
95+
- Use camelCase for local variables: `$tempPath`
96+
- Use meaningful, descriptive names
97+
98+
#### Error Handling
99+
```powershell
100+
try {
101+
# Main logic
102+
}
103+
catch {
104+
Write-Error "Detailed error message: $($_.Exception.Message)"
105+
throw
106+
}
107+
```
108+
109+
## Testing Patterns
110+
111+
### Pester Test Structure
112+
```powershell
113+
Describe 'Function-Name' {
114+
Context 'When condition is met' {
115+
It 'Should perform expected action' {
116+
# Arrange
117+
$input = 'test value'
118+
119+
# Act
120+
$result = Function-Name -Parameter $input
121+
122+
# Assert
123+
$result | Should -Be 'expected value'
124+
}
125+
}
126+
127+
Context 'When validation fails' {
128+
It 'Should throw meaningful error' {
129+
{ Function-Name -Parameter $null } | Should -Throw
130+
}
131+
}
132+
}
133+
```
134+
135+
### Test File Organization
136+
- Unit tests: `tests/Unit/`
137+
- Integration tests: `tests/Integration/`
138+
- Test files should mirror source structure
139+
- Name test files: `[FunctionName].Tests.ps1`
140+
141+
## Documentation Standards
142+
143+
### Comment-Based Help
144+
Every public function must include:
145+
- `.SYNOPSIS` - Brief one-line description
146+
- `.DESCRIPTION` - Detailed explanation
147+
- `.PARAMETER` - For each parameter
148+
- `.EXAMPLE` - At least one working example
149+
- `.NOTES` - Additional context if needed
150+
- `.LINK` - Reference links
151+
152+
### Markdown Documentation
153+
- Function documentation: `src/functions/public/[Category]/[Category].md`
154+
- Use clear headings and code examples
155+
- Include real-world usage scenarios
156+
157+
## Configuration Patterns
158+
159+
### PSModule.yml Structure
160+
```yaml
161+
Name: ModuleName
162+
163+
Test:
164+
Skip: false
165+
SourceCode:
166+
Skip: false
167+
PSModule:
168+
Skip: false
169+
Module:
170+
Skip: false
171+
CodeCoverage:
172+
PercentTarget: 80
173+
174+
Build:
175+
Skip: false
176+
Module:
177+
Skip: false
178+
Docs:
179+
Skip: false
180+
181+
Publish:
182+
Module:
183+
Skip: false
184+
AutoCleanup: true
185+
AutoPatching: true
186+
```
187+
188+
## Workflow Understanding
189+
190+
### Pipeline Stages
191+
1. **Get-Settings** - Read configuration
192+
2. **Build-Module** - Compile source into module
193+
3. **Test-SourceCode** - Test source files
194+
4. **Lint-SourceCode** - PSScriptAnalyzer validation
195+
5. **Test-Module** - PSModule framework tests
196+
6. **Test-ModuleLocal** - Pester tests from repo
197+
7. **Get-TestResults** - Aggregate test results
198+
8. **Get-CodeCoverage** - Calculate coverage
199+
9. **Build-Docs** - Generate documentation
200+
10. **Build-Site** - Create static site
201+
11. **Publish** - Release to PowerShell Gallery and GitHub
202+
203+
### Conditional Execution
204+
- Tests run on multiple OS platforms (matrix strategy)
205+
- Steps can be skipped via configuration
206+
- Publishing only occurs on merged PRs
207+
208+
## GitHub Actions Patterns
209+
210+
### Workflow Inputs
211+
```yaml
212+
inputs:
213+
Name:
214+
type: string
215+
description: Module name
216+
required: false
217+
SettingsPath:
218+
type: string
219+
description: Path to settings file
220+
default: .github/PSModule.yml
221+
Debug:
222+
type: boolean
223+
description: Enable debug output
224+
default: false
225+
```
226+
227+
### Secrets Required
228+
- `APIKEY` - PowerShell Gallery API key for publishing
229+
230+
## Common Patterns
231+
232+
### Module Requirements
233+
Use `#Requires` statements at the top of files that need specific modules:
234+
```powershell
235+
#Requires -Modules @{ModuleName='RequiredModule'; ModuleVersion='1.0.0'}
236+
```
237+
238+
### Alias Definitions
239+
```powershell
240+
# Multiple alias methods supported
241+
[Alias('Short-Name1')]
242+
[Alias('Short-Name2')]
243+
function Long-FunctionName {
244+
# Function body
245+
}
246+
247+
# Alternative alias definitions at end of file
248+
New-Alias Short-Name3 Long-FunctionName
249+
New-Alias -Name Short-Name4 -Value Long-FunctionName
250+
Set-Alias Short-Name5 Long-FunctionName
251+
```
252+
253+
### PSScriptAnalyzer Suppressions
254+
When suppression is necessary, use the standard format:
255+
```powershell
256+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
257+
'RuleName', 'Target', Scope = 'Function',
258+
Justification = 'Clear reason for suppression'
259+
)]
260+
function Function-Name {
261+
# Function body
262+
}
263+
```
264+
265+
### Validation
266+
```powershell
267+
[Parameter(Mandatory)]
268+
[ValidateNotNullOrEmpty()]
269+
[ValidatePattern('^[a-zA-Z0-9-]+$')]
270+
[string] $ModuleName
271+
```
272+
273+
## File Patterns to Follow
274+
275+
### Directory Structure
276+
```
277+
.github/
278+
workflows/ # GitHub Actions workflows
279+
linters/ # Linter configurations
280+
PSModule.yml # Project configuration
281+
src/
282+
functions/
283+
public/ # Exported functions
284+
private/ # Internal functions
285+
classes/
286+
public/ # Exported classes
287+
private/ # Internal classes
288+
data/ # Configuration files
289+
assemblies/ # Binary dependencies
290+
modules/ # Nested modules
291+
tests/
292+
Unit/ # Unit tests
293+
Integration/ # Integration tests
294+
docs/ # Additional documentation
295+
```
296+
297+
## Best Practices
298+
299+
1. **Follow PowerShell naming conventions** - Use approved verbs (`Get-Verb`)
300+
2. **Write comprehensive tests first** (TDD approach)
301+
3. **Include proper error handling** with meaningful messages
302+
4. **Document all public interfaces** with comment-based help
303+
5. **Use semantic versioning** for releases
304+
6. **Validate inputs thoroughly** using parameter validation
305+
7. **Write clean, readable code** that follows the style guide
306+
8. **Test on multiple platforms** when making changes
307+
308+
## Troubleshooting
309+
310+
### Common Issues
311+
- **PSScriptAnalyzer violations** - Check against rules in `.powershell-psscriptanalyzer.psd1`
312+
- **Test failures** - Ensure tests follow Pester v5 syntax
313+
- **Build failures** - Verify module manifest and dependencies
314+
- **Documentation errors** - Check mkdocs.yml configuration
315+
316+
When making changes, always:
317+
1. Run PSScriptAnalyzer locally
318+
2. Execute relevant tests
319+
3. Update documentation
320+
4. Follow the established patterns in existing code

0 commit comments

Comments
 (0)