microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v2.3.6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/README.md

173lines · modecode

1---
2title: Scripts
3description: PowerShell scripts for linting, validation, and security automation
4author: HVE Core Team
5ms.date: 2025-11-05
6ms.topic: reference
7keywords:
8 - powershell
9 - scripts
10 - automation
11 - linting
12 - security
13estimated_reading_time: 5
14---
15
16This directory contains PowerShell scripts for automating linting, validation, and security checks in the `hve-core` repository.
17
18## Directory Structure
19
20```text
21scripts/
22├── dev-tools/ Development utilities (PR reference generation)
23├── extension/ VS Code extension packaging utilities
24├── lib/ Shared utility modules
25├── linting/ PowerShell linting and validation scripts
26├── plugins/ Copilot CLI plugin generation and validation
27├── security/ Security scanning and SHA pinning scripts
28└── tests/ Pester test organization
29```
30
31## Dev Tools
32
33Development utilities for working with hve-core.
34
35| Script | Purpose |
36|----------------------------|-------------------------------------------|
37| `Generate-PrReference.ps1` | Generate PR reference XML for reviews |
38| `pr-ref-gen.sh` | Shell wrapper for PR reference generation |
39
40## Extension
41
42VS Code extension packaging utilities.
43
44| Script | Purpose |
45|-------------------------|------------------------------------------|
46| `Package-Extension.ps1` | Package the VS Code extension |
47| `Prepare-Extension.ps1` | Prepare extension contents for packaging |
48
49## Library
50
51Shared utility modules used across scripts.
52
53| Script | Purpose |
54|----------------------------|--------------------------------------|
55| `Get-VerifiedDownload.ps1` | Download files with SHA verification |
56
57## Linting Scripts
58
59The `linting/` directory contains scripts for validating code quality and documentation:
60
61* **PSScriptAnalyzer**: Static analysis for PowerShell files
62* **Markdown Frontmatter**: Validate YAML frontmatter in markdown files
63* **Link Language Check**: Detect en-us language paths in URLs
64* **Markdown Link Check**: Validate markdown links
65* **Shared Module**: Common helper functions for GitHub Actions integration
66
67See [linting/README.md](linting/README.md) for detailed documentation.
68
69## Security Scripts
70
71The `security/` directory contains scripts for security scanning and dependency management:
72
73* **Dependency Pinning**: Validate SHA pinning compliance
74* **SHA Staleness**: Check for outdated SHA pins
75* **SHA Updates**: Automate updating GitHub Actions SHA pins
76
77## Tests
78
79Pester test organization matching the scripts structure.
80
81| Directory | Tests For |
82|--------------|-------------------------------|
83| `dev-tools/` | PR reference generation tests |
84| `extension/` | Extension packaging tests |
85| `lib/` | Library utility tests |
86| `linting/` | Linting script tests |
87| `security/` | Security validation tests |
88
89Run all tests:
90
91```bash
92npm run test
93```
94
95## Usage
96
97All scripts are designed to run both locally and in GitHub Actions workflows. They support common parameters like `-Verbose` and `-Debug` for troubleshooting.
98
99**Local Testing**:
100
101```powershell
102# Test PSScriptAnalyzer on changed files
103./scripts/linting/Invoke-PSScriptAnalyzer.ps1 -ChangedFilesOnly -Verbose
104
105# Validate markdown frontmatter
106./scripts/linting/Validate-MarkdownFrontmatter.ps1 -Verbose
107
108# Check for language paths in URLs
109./scripts/linting/Invoke-LinkLanguageCheck.ps1 -Verbose
110```
111
112**GitHub Actions Integration**:
113
114All scripts automatically detect GitHub Actions environment and provide appropriate output formatting (annotations, summaries, artifacts).
115
116## Contributing
117
118When adding new scripts:
119
1201. Follow PowerShell best practices (PSScriptAnalyzer compliant)
1212. Include the entry point guard pattern (see below)
1223. Support `-Verbose` and `-Debug` parameters
1234. Add GitHub Actions integration using `LintingHelpers` module functions
1245. Include inline help with `.SYNOPSIS`, `.DESCRIPTION`, `.PARAMETER`, and `.EXAMPLE`
1256. Document in relevant README files
1267. Test locally before creating PR
127
128### Entry Point Guard Pattern
129
130All production scripts use a dot-source guard that enables Pester tests to import functions without executing main logic. Extract main logic into an `Invoke-*` orchestrator function and wrap direct execution in a guard block:
131
132```powershell
133#region Functions
134
135function Invoke-ScriptMain {
136 [CmdletBinding()]
137 param( <# script params #> )
138 # Main logic here
139}
140
141#endregion Functions
142
143#region Main Execution
144if ($MyInvocation.InvocationName -ne '.') {
145 try {
146 Invoke-ScriptMain @PSBoundParameters
147 exit 0
148 }
149 catch {
150 Write-Error -ErrorAction Continue "ScriptName failed: $($_.Exception.Message)"
151 Write-CIAnnotation -Message $_.Exception.Message -Level Error
152 exit 1
153 }
154}
155#endregion Main Execution
156```
157
158Key rules:
159
160* The `if` guard wraps `try`/`catch` (not the reverse)
161* Name the orchestrator `Invoke-*` matching the script noun
162* Use `#region Functions` and `#region Main Execution` markers
163* See [Generate-PrReference.ps1](dev-tools/Generate-PrReference.ps1) for a canonical example
164
165## Related Documentation
166
167* [Linting Scripts Documentation](linting/README.md)
168* [GitHub Workflows Documentation](../.github/workflows/README.md)
169* [Contributing Guidelines](../CONTRIBUTING.md)
170
171---
172
173🤖 Crafted with precision by ✨Copilot following brilliant human instruction, then carefully refined by our team of discerning human reviewers.