microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
scripts/README.md
201lines · modecode
| 1 | --- |
| 2 | title: Scripts |
| 3 | description: PowerShell scripts for linting, validation, and security automation |
| 4 | author: HVE Core Team |
| 5 | ms.date: 2026-03-17 |
| 6 | ms.topic: reference |
| 7 | keywords: |
| 8 | - powershell |
| 9 | - scripts |
| 10 | - automation |
| 11 | - linting |
| 12 | - security |
| 13 | estimated_reading_time: 5 |
| 14 | --- |
| 15 | |
| 16 | This directory contains PowerShell scripts for automating linting, validation, and security checks in the `hve-core` repository. |
| 17 | |
| 18 | ## Directory Structure |
| 19 | |
| 20 | ```text |
| 21 | scripts/ |
| 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 | |
| 33 | VS 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 | |
| 42 | Shared utility modules used across scripts. |
| 43 | |
| 44 | | Script | Purpose | |
| 45 | |----------------------------|--------------------------------------| |
| 46 | | `Get-VerifiedDownload.ps1` | Download files with SHA verification | |
| 47 | |
| 48 | ## Linting Scripts |
| 49 | |
| 50 | The `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 | |
| 66 | See [linting/README.md](linting/README.md) for detailed documentation. |
| 67 | |
| 68 | ## Security Scripts |
| 69 | |
| 70 | The `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 | |
| 81 | Copilot 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 | |
| 90 | Collection validation and shared helpers. |
| 91 | |
| 92 | | Script | Purpose | |
| 93 | |----------------------------|--------------------------------------------| |
| 94 | | `Validate-Collections.ps1` | Validate collection metadata and structure | |
| 95 | |
| 96 | ## Tests |
| 97 | |
| 98 | Pester 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 | |
| 111 | Run all tests: |
| 112 | |
| 113 | ```bash |
| 114 | npm run test:ps |
| 115 | ``` |
| 116 | |
| 117 | ## Usage |
| 118 | |
| 119 | All 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 | |
| 136 | All scripts automatically detect GitHub Actions environment and provide appropriate output formatting (annotations, summaries, artifacts). |
| 137 | |
| 138 | ## Contributing |
| 139 | |
| 140 | When adding new scripts: |
| 141 | |
| 142 | 1. Follow PowerShell best practices (PSScriptAnalyzer compliant) |
| 143 | 2. Include the entry point guard pattern (see below) |
| 144 | 3. Support `-Verbose` and `-Debug` parameters |
| 145 | 4. Add GitHub Actions integration using `LintingHelpers` module functions |
| 146 | 5. Include inline help with `.SYNOPSIS`, `.DESCRIPTION`, `.PARAMETER`, and `.EXAMPLE` |
| 147 | 6. Document in relevant README files |
| 148 | 7. Test locally before creating PR |
| 149 | |
| 150 | ### Entry Point Guard Pattern |
| 151 | |
| 152 | All 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 | |
| 157 | function Invoke-ScriptMain { |
| 158 | [CmdletBinding()] |
| 159 | param( <# script params #> ) |
| 160 | # Main logic here |
| 161 | } |
| 162 | |
| 163 | #endregion Functions |
| 164 | |
| 165 | #region Main Execution |
| 166 | if ($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 | |
| 180 | Key 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. |