Lint #91
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lint | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
defaults: | |
run: | |
shell: bash | |
env: | |
PWSH_EXTS: '*.ps1 *.psd1 *.psm1' | |
jobs: | |
lint-hooks: | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup the Python Environment | |
uses: Qwerty-133/python-setup@v1 | |
with: | |
python-version: '3.11' | |
- name: Run pre-commit hooks | |
run: poetry run pre-commit run --show-diff-on-failure --color=always --all-files | |
lint-pwsh: | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: pwsh | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install PSScriptAnalyzer | |
run: | | |
$analyzerModule = Get-Module -ListAvailable -Name PSScriptAnalyzer | |
if ($null -eq $analyzerModule) { | |
Install-Module -Name PSScriptAnalyzer -Force | |
} | |
- name: Analyze PowerShell files | |
run: | | |
Invoke-ScriptAnalyzer -Path '.\' -Recurse -EnableExit | |
- name: Format PowerShell files | |
run: | | |
$exts = (-split $env:PWSH_EXTS) | |
$files = Get-ChildItem -File -LiteralPath '.\' -Recurse -Force -Include $exts | |
$files | ForEach-Object { | |
$file = $_.FullName | |
$contents = Get-Content -LiteralPath $file -Raw | |
$formatted = Invoke-Formatter -ScriptDefinition $contents | |
if ($contents -ne $formatted) { | |
Set-Content -LiteralPath $file -Value $formatted | |
} | |
} | |
- name: Check for changes | |
shell: bash | |
run: > | |
git diff --exit-code |