microsoft/hve-core

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3cade0d7dd510bcfa350a1dc9512159a1f60ae4f

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/README.md

201lines · modecode

1---
2title: Scripts
3description: PowerShell scripts for linting, validation, and security automation
4author: HVE Core Team
5ms.date: 2026-03-17
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├── collections/ Collection validation and shared helpers
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
27└── security/ Security scanning and dependency pinning scripts
28└── tests/ Pester test organization
29```
30
31## Extension
32
33VS Code extension packaging utilities.
34
35| Script | Purpose |
36|-------------------------|------------------------------------------|
37| `Package-Extension.ps1` | Package the VS Code extension |
38| `Prepare-Extension.ps1` | Prepare extension contents for packaging |
39
40## Library
41
42Shared utility modules used across scripts.
43
44| Script | Purpose |
45|----------------------------|--------------------------------------|
46| `Get-VerifiedDownload.ps1` | Download files with SHA verification |
47
48## Linting Scripts
49
50The `linting/` directory contains scripts for validating code quality and documentation:
51
52| Script | Purpose |
53|------------------------------------|----------------------------------------------------|
54| `Invoke-PSScriptAnalyzer.ps1` | Static analysis for PowerShell files |
55| `Validate-MarkdownFrontmatter.ps1` | Validate YAML frontmatter in markdown files |
56| `Validate-SkillStructure.ps1` | Validate skill directory structure and frontmatter |
57| `Invoke-LinkLanguageCheck.ps1` | Detect en-us language paths in URLs |
58| `Link-Lang-Check.ps1` | Link language checking entry point |
59| `Markdown-Link-Check.ps1` | Validate markdown links |
60| `Invoke-YamlLint.ps1` | YAML file validation |
61| `Test-CopyrightHeaders.ps1` | Validate copyright headers in source files |
62| `Invoke-MsDateFreshnessCheck.ps1` | Check ms.date frontmatter freshness |
63| `Invoke-PythonLint.ps1` | Python linting via ruff |
64| `Invoke-PythonTests.ps1` | Python tests via pytest |
65
66See [linting/README.md](linting/README.md) for detailed documentation.
67
68## Security Scripts
69
70The `security/` directory contains scripts for security scanning and dependency management:
71
72| Script | Purpose |
73|-------------------------------------|-------------------------------------------|
74| `Test-DependencyPinning.ps1` | Validate dependency pinning compliance |
75| `Test-SHAStaleness.ps1` | Check for outdated SHA pins |
76| `Update-ActionSHAPinning.ps1` | Automate updating GitHub Actions SHA pins |
77| `Test-ActionVersionConsistency.ps1` | Validate action version consistency |
78
79## Plugins
80
81Copilot CLI plugin generation and validation.
82
83| Script | Purpose |
84|----------------------------|-------------------------------------------|
85| `Generate-Plugins.ps1` | Generate plugin packages from collections |
86| `Validate-Marketplace.ps1` | Validate marketplace metadata |
87
88## Collections
89
90Collection validation and shared helpers.
91
92| Script | Purpose |
93|----------------------------|--------------------------------------------|
94| `Validate-Collections.ps1` | Validate collection metadata and structure |
95
96## Tests
97
98Pester test organization matching the scripts structure.
99
100| Directory | Tests For |
101|----------------|---------------------------|
102| `collections/` | Collection helpers tests |
103| `extension/` | Extension packaging tests |
104| `lib/` | Library utility tests |
105| `linting/` | Linting script tests |
106| `security/` | Security validation tests |
107| `plugins/` | Plugin generation tests |
108| `Fixtures/` | Shared test fixtures |
109| `Mocks/` | Shared mock data |
110
111Run all tests:
112
113```bash
114npm run test:ps
115```
116
117## Usage
118
119All scripts are designed to run both locally and in GitHub Actions workflows. They support common parameters like `-Verbose` and `-Debug` for troubleshooting.
120
121### Local Testing
122
123```powershell
124# Test PSScriptAnalyzer on changed files
125./scripts/linting/Invoke-PSScriptAnalyzer.ps1 -ChangedFilesOnly -Verbose
126
127# Validate markdown frontmatter
128./scripts/linting/Validate-MarkdownFrontmatter.ps1 -Verbose
129
130# Check for language paths in URLs
131./scripts/linting/Invoke-LinkLanguageCheck.ps1 -Verbose
132```
133
134### GitHub Actions Integration
135
136All scripts automatically detect GitHub Actions environment and provide appropriate output formatting (annotations, summaries, artifacts).
137
138## Contributing
139
140When adding new scripts:
141
1421. Follow PowerShell best practices (PSScriptAnalyzer compliant)
1432. Include the entry point guard pattern (see below)
1443. Support `-Verbose` and `-Debug` parameters
1454. Add GitHub Actions integration using `LintingHelpers` module functions
1465. Include inline help with `.SYNOPSIS`, `.DESCRIPTION`, `.PARAMETER`, and `.EXAMPLE`
1476. Document in relevant README files
1487. Test locally before creating PR
149
150### Entry Point Guard Pattern
151
152All 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:
153
154```powershell
155#region Functions
156
157function Invoke-ScriptMain {
158 [CmdletBinding()]
159 param( <# script params #> )
160 # Main logic here
161}
162
163#endregion Functions
164
165#region Main Execution
166if ($MyInvocation.InvocationName -ne '.') {
167 try {
168 Invoke-ScriptMain @PSBoundParameters
169 exit 0
170 }
171 catch {
172 Write-Error -ErrorAction Continue "ScriptName failed: $($_.Exception.Message)"
173 Write-CIAnnotation -Message $_.Exception.Message -Level Error
174 exit 1
175 }
176}
177#endregion Main Execution
178```
179
180Key rules:
181
182* The `if` guard wraps `try`/`catch` (not the reverse)
183* Name the orchestrator `Invoke-*` matching the script noun
184* Use `#region Functions` and `#region Main Execution` markers
185* See [Package-Extension.ps1](extension/Package-Extension.ps1) for a canonical example
186
187## Related Documentation
188
189* [Collection Scripts Documentation](collections/README.md)
190* [Extension Packaging Documentation](extension/README.md)
191* [Library Utilities Documentation](lib/README.md)
192* [Linting Scripts Documentation](linting/README.md)
193* [Plugin Generation Documentation](plugins/README.md)
194* [Security Scripts Documentation](security/README.md)
195* [Test Organization Documentation](tests/README.md)
196* [GitHub Workflows Documentation](../.github/workflows/README.md)
197* [Contributing Guidelines](../CONTRIBUTING.md)
198
199---
200
201🤖 Crafted with precision by ✨Copilot following brilliant human instruction, then carefully refined by our team of discerning human reviewers.