Skip to content

Conversation

@WilliamBerryiii
Copy link
Member

@WilliamBerryiii WilliamBerryiii commented Feb 11, 2026

Pull Request

Description

Standardized all PowerShell entry point guards across the repository to use a single canonical pattern: if ($MyInvocation.InvocationName -ne '.') wrapping try/catch. Removed the legacy $script:SkipMain / HVE_SKIP_MAIN environment variable mechanism and extracted orchestrator functions from scripts that previously embedded logic directly in their main blocks.

Key changes:

  • Adopted canonical if-wraps-try guard pattern (if ($MyInvocation.InvocationName -ne '.') { try { ... } catch { ... } }) across 16 production scripts
  • Removed $script:SkipMain and $env:HVE_SKIP_MAIN from 6 scripts that used the environment variable mechanism
  • Extracted named orchestrator functions (Invoke-VideoConversion, Invoke-PSScriptAnalyzerCore, Invoke-YamlLintCore, Invoke-LinkLanguageCheck, Invoke-MarkdownLinkCheck, Invoke-CopyrightHeaderCheck, Invoke-ActionVersionConsistencyCheck, Invoke-DependencyPinningAnalysis) for direct testability
  • Swapped if/try ordering to canonical form in scripts that had try-wraps-if
  • Added [CmdletBinding()] to functions missing the attribute
  • Updated 9 test files to use dot-source pattern instead of HVE_SKIP_MAIN env var manipulation
  • Documented the canonical guard pattern in scripts/README.md and scripts/linting/README.md

Related Issue(s)

Closes #325
Closes #327

Type of Change

Select all that apply:

Code & Documentation:

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update

Infrastructure & Configuration:

  • GitHub Actions workflow
  • Linting configuration (markdown, PowerShell, etc.)
  • Security configuration
  • DevContainer configuration
  • Dependency update

AI Artifacts:

  • Reviewed contribution with prompt-builder agent and addressed all feedback
  • Copilot instructions (.github/instructions/*.instructions.md)
  • Copilot prompt (.github/prompts/*.prompt.md)
  • Copilot agent (.github/agents/*.agent.md)
  • Copilot skill (.github/skills/*/SKILL.md)

Other:

  • Script/automation (.ps1, .sh, .py)
  • Other (please describe):

Testing

  • All 900 Pester tests pass (npm run test:ps)
  • All linters clean: npm run lint:md, npm run lint:ps, npm run lint:frontmatter, npm run lint:md-links
  • Test files updated to call extracted orchestrator functions directly instead of using HVE_SKIP_MAIN env var
  • Verified scripts execute correctly when run directly and produce no output when dot-sourced

Checklist

Required Checks

  • Documentation is updated (if applicable)
  • Files follow existing naming conventions
  • Changes are backwards compatible (if applicable)
  • Tests added for new functionality (if applicable)

Required Automated Checks

The following validation commands must pass before merging:

  • Markdown linting: npm run lint:md
  • Spell checking: npm run spell-check
  • Frontmatter validation: npm run lint:frontmatter
  • Link validation: npm run lint:md-links
  • PowerShell analysis: npm run lint:ps

Security Considerations

  • This PR does not contain any sensitive or NDA information
  • Any new dependencies have been reviewed for security issues
  • Security-related scripts follow the principle of least privilege

Additional Notes

  • This is a breaking change for any external consumers that relied on $env:HVE_SKIP_MAIN = '1' to suppress script main block execution. The new pattern uses $MyInvocation.InvocationName -ne '.' which requires dot-sourcing for function isolation.
  • Test-DependencyPinning.ps1 was normalized in a separate preparatory commit (9252b08) before the main standardization commit (2a18d9a).
  • Six follow-up items were identified during task review and documented for future backlog triage.

🔧 - Generated by Copilot

…ing.ps1

- add [CmdletBinding()] to 8 functions missing it
- extract ~70 lines of inline main logic into Invoke-DependencyPinningAnalysis
- restructure guard to canonical if-wraps-try form with Write-Error + Write-CIAnnotation
- remove else clause that rejected dot-sourcing
- add #region/#endregion Functions and Main Execution markers

🔧 - Generated by Copilot
- normalize 5 Pattern A scripts to canonical if-wraps-try form
- migrate 6 Pattern B scripts from HVE_SKIP_MAIN to dot-source guard
- add guards and extract Invoke-* orchestrators for 4 unguarded scripts
- update 10 Pester test files for new guard consumption pattern
- document guard convention in scripts/README.md and scripts/linting/README.md

🔧 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii requested a review from a team as a code owner February 11, 2026 20:05
Copilot AI review requested due to automatic review settings February 11, 2026 20:05
@github-actions
Copy link

github-actions bot commented Feb 11, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 57.56303% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.43%. Comparing base (8133b36) to head (3b17433).

Files with missing lines Patch % Lines
scripts/security/Test-ActionVersionConsistency.ps1 3.70% 26 Missing ⚠️
scripts/security/Test-DependencyPinning.ps1 56.09% 18 Missing ⚠️
scripts/linting/Test-CopyrightHeaders.ps1 82.69% 9 Missing ⚠️
scripts/security/Update-ActionSHAPinning.ps1 50.00% 6 Missing ⚠️
scripts/linting/Invoke-LinkLanguageCheck.ps1 16.66% 5 Missing ⚠️
scripts/linting/Invoke-PSScriptAnalyzer.ps1 80.76% 5 Missing ⚠️
scripts/linting/Invoke-YamlLint.ps1 81.48% 5 Missing ⚠️
scripts/linting/Markdown-Link-Check.ps1 37.50% 5 Missing ⚠️
scripts/security/Test-SHAStaleness.ps1 70.58% 5 Missing ⚠️
scripts/extension/Package-Extension.ps1 20.00% 4 Missing ⚠️
... and 5 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #477      +/-   ##
==========================================
+ Coverage   76.22%   83.43%   +7.21%     
==========================================
  Files          20       20              
  Lines        3503     3507       +4     
==========================================
+ Hits         2670     2926     +256     
+ Misses        833      581     -252     
Flag Coverage Δ
pester 83.43% <57.56%> (+7.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
scripts/extension/Prepare-Extension.ps1 83.73% <0.00%> (ø)
scripts/dev-tools/Generate-PrReference.ps1 94.82% <25.00%> (ø)
scripts/lib/Get-VerifiedDownload.ps1 80.24% <25.00%> (ø)
scripts/linting/Link-Lang-Check.ps1 75.92% <25.00%> (+27.77%) ⬆️
scripts/linting/Validate-MarkdownFrontmatter.ps1 65.31% <25.00%> (-0.46%) ⬇️
scripts/extension/Package-Extension.ps1 93.24% <20.00%> (ø)
scripts/linting/Invoke-LinkLanguageCheck.ps1 85.48% <16.66%> (-4.52%) ⬇️
scripts/linting/Invoke-PSScriptAnalyzer.ps1 90.00% <80.76%> (-2.31%) ⬇️
scripts/linting/Invoke-YamlLint.ps1 93.05% <81.48%> (-2.78%) ⬇️
scripts/linting/Markdown-Link-Check.ps1 63.39% <37.50%> (+33.27%) ⬆️
... and 5 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Standardizes PowerShell script entry-point behavior across the repo by replacing the $env:HVE_SKIP_MAIN/$script:SkipMain mechanism with a canonical dot-source guard (if ($MyInvocation.InvocationName -ne '.') { try { ... } catch { ... } }) and by extracting orchestrator functions to make scripts easier to test.

Changes:

  • Refactored multiple production scripts to expose Invoke-* orchestrator functions and run them only under the dot-source guard.
  • Updated Pester tests to dot-source scripts (for function access) and call orchestrators directly instead of manipulating HVE_SKIP_MAIN.
  • Documented the canonical guard pattern in scripts/README.md and updated linting docs examples.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
scripts/security/Update-ActionSHAPinning.ps1 Extracts Invoke-ActionSHAPinningUpdate and converts main block to canonical guard.
scripts/security/Test-SHAStaleness.ps1 Extracts Invoke-SHAStalenessCheck, updates failure semantics to throw under guard.
scripts/security/Test-DependencyPinning.ps1 Extracts Invoke-DependencyPinningAnalysis and adds [CmdletBinding()] to multiple functions.
scripts/security/Test-ActionVersionConsistency.ps1 Extracts Invoke-ActionVersionConsistencyCheck and normalizes guard behavior.
scripts/linting/Validate-MarkdownFrontmatter.ps1 Normalizes guard/try ordering and updates error handling in main execution.
scripts/linting/Test-CopyrightHeaders.ps1 Extracts Invoke-CopyrightHeaderCheck for testability and converts to guard pattern.
scripts/linting/Markdown-Link-Check.ps1 Extracts Invoke-MarkdownLinkCheck and converts main execution to guard + throw model.
scripts/linting/Link-Lang-Check.ps1 Adds shebang and introduces Invoke-LinkLanguageCheck orchestrator with canonical guard.
scripts/linting/Invoke-YamlLint.ps1 Extracts Invoke-YamlLintCore and adjusts flow to return/throw instead of exiting mid-function.
scripts/linting/Invoke-PSScriptAnalyzer.ps1 Extracts Invoke-PSScriptAnalyzerCore and converts to return/throw + guarded entry point.
scripts/linting/Invoke-LinkLanguageCheck.ps1 Updates wrapper entry point to canonical guard (dot-source friendly).
scripts/lib/Get-VerifiedDownload.ps1 Swaps guard/try ordering to canonical pattern.
scripts/extension/Prepare-Extension.ps1 Swaps guard/try ordering and normalizes error message string.
scripts/extension/Package-Extension.ps1 Swaps guard/try ordering and normalizes error message string.
.github/skills/video-to-gif/scripts/convert.ps1 Extracts Invoke-VideoConversion and adds canonical guard for dot-sourcing.
scripts/tests/security/Update-ActionSHAPinning.Tests.ps1 Removes HVE_SKIP_MAIN manipulation; relies on dot-sourcing for isolation.
scripts/tests/security/Test-SHAStaleness.Tests.ps1 Removes HVE_SKIP_MAIN usage; updates test description to dot-source pattern.
scripts/tests/security/Test-DependencyPinning.Tests.ps1 Removes dot-sourcing error assertion (behavior changed under new guard model).
scripts/tests/security/Test-ActionVersionConsistency.Tests.ps1 Removes HVE_SKIP_MAIN usage and updates subprocess helpers accordingly.
scripts/tests/linting/Test-CopyrightHeaders.Tests.ps1 Dot-sources script and invokes extracted orchestrator for testing.
scripts/tests/linting/Markdown-Link-Check.Tests.ps1 Removes HVE_SKIP_MAIN toggling; continues integration testing via direct invocation.
scripts/tests/linting/Link-Lang-Check.Tests.ps1 Removes HVE_SKIP_MAIN toggling; continues integration testing via direct invocation.
scripts/tests/linting/Invoke-YamlLint.Tests.ps1 Dot-sources script and tests Invoke-YamlLintCore directly.
scripts/tests/linting/Invoke-PSScriptAnalyzer.Tests.ps1 Dot-sources script and tests Invoke-PSScriptAnalyzerCore directly.
scripts/tests/linting/Invoke-LinkLanguageCheck.Tests.ps1 Removes HVE_SKIP_MAIN manipulation; relies on dot-sourcing.
scripts/linting/README.md Updates example to match new orchestrator + guard pattern and throw-based failures.
scripts/README.md Documents canonical entry-point guard pattern for future scripts.

…ror calls

- add -ErrorAction Continue to 13 Write-Error calls across 12 script files
- move Set-StrictMode from file scope to function body in Update-ActionSHAPinning.ps1
- add null-coalescing git fallback in Test-CopyrightHeaders.ps1 Path parameter
- update scripts/README.md guard template with -ErrorAction Continue and Write-CIAnnotation

🔧 - Generated by Copilot
- add tests for Invoke-MarkdownLinkCheck, Test-SHAStaleness, Update-ActionSHAPinning
- add SecurityClasses tests and npm-violations test fixture
- fix Update-WorkflowFile to return PSCustomObject instead of hashtable

🧪 - Generated by Copilot
Copilot AI review requested due to automatic review settings February 12, 2026 02:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.

- restore GITHUB_OUTPUT in Test-SHAStaleness test AfterEach to prevent env leak
- replace raw >> with guarded Out-File pattern in pester-tests workflow
- move StaleDependencies init to script scope for correct cross-function access
- add -ErrorAction Continue to Write-Error in catch blocks and README example
- replace null-coalescing operator with if/else for PS 5.1 compatibility

🔧 - Generated by Copilot
@WilliamBerryiii
Copy link
Member Author

@chaosdinosaur - there's a solid chance this PR is going to cause some re-work on #482 ... my apologies in advance

Copy link
Contributor

@katriendg katriendg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge PR, I have used the great PR Reviewer to help identify any inconsistencies. Leaving two comments and one general remark (maybe in a subsequent issue) - see pester-tests.yml comment.

- restructure guard pattern in Generate-PrReference.ps1

- correct test name typo in Update-ActionSHAPinning.Tests.ps1

- guard GITHUB_ENV writes in pester-tests.yml

🔧 - Generated by Copilot
Copilot AI review requested due to automatic review settings February 12, 2026 17:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.

- restore GITHUB_TOKEN in AfterAll to prevent env var leakage across tests
- rename misleading test description to match actual assertion behavior
- add FRONTMATTER_VALIDATION_FAILED assertion with try/finally cleanup

🔧 - Generated by Copilot
- Set-CIEnv writes to GITHUB_ENV file, not the current process
- mock Set-CIEnv and use Should -Invoke with ParameterFilter

🔧 - Generated by Copilot
Copilot AI review requested due to automatic review settings February 12, 2026 18:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.

@WilliamBerryiii WilliamBerryiii merged commit 6b84a8e into main Feb 12, 2026
23 checks passed
@WilliamBerryiii WilliamBerryiii deleted the refactor/standardize-ps1-entry-point-guards branch February 12, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(scripts): improve test coverage for Update-ActionSHAPinning.ps1 refactor: Standardize script entry point pattern across PowerShell scripts

3 participants