Skip to content

Commit ab3e7fc

Browse files
committed
feat: add pre-commit-hooks+config to use with pre-commit.com
And self-apply in github workflows.
1 parent 77f6500 commit ab3e7fc

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

.github/workflows/precommit.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: precommit
3+
4+
on:
5+
push:
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions: {}
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up Python
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: '3.x'
24+
- name: Install module from PSGallery
25+
shell: pwsh
26+
run: |
27+
Set-PSRepository PSGallery -InstallationPolicy Trusted
28+
Install-Module PSScriptAnalyzer -ErrorAction Stop
29+
- uses: pre-commit/action@v2.0.0
30+
with:
31+
extra_args: --all-files --show-diff-on-failure

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
#- repo: https://github.com/PowerShell/PSScriptAnalyzer
3+
- repo: https://github.com/juju4/PSScriptAnalyzer
4+
rev: 3e3b2d7b7548fc5513b367cb3a80860d5bfd24db
5+
hooks:
6+
- id: powershell_scriptanalyzer
7+
# Note that client and server path may be different.
8+
# Github image should be /usr/bin/pwsh
9+
# Linux/Macos is usually /usr/local/bin/pwsh unless using a user scope
10+
entry: /usr/bin/pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Severity Warning -Path . "
11+
# https://github.com/pre-commit/pre-commit/pull/2340#issuecomment-1098203344
12+
#- repo: local
13+
# hooks:
14+
# - id: pwsh
15+
# name: pwsh
16+
# entry: Invoke-ScriptAnalyzer.ps1 -Settings PSGallery -Recurse -EnableExit -Severity Warning -Path .
17+
# language: script
18+
# always_run: true
19+
# pass_filenames: false
20+
# verbose: true

.pre-commit-hooks.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- id: powershell_scriptanalyzer
2+
name: Powershell lint with PSScriptAnalyzer
3+
description: This runs PSScriptAnalyzer on your powershell files
4+
entry: pre-commit powershell_scriptanalyzer
5+
language: script
6+
files: ^.*\.ps1$
7+
types: [text]
8+
entry: pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Path ."
9+
require_serial: false
10+
additional_dependencies: []
11+
minimum_pre_commit_version: '0'
12+
pass_filenames: false
13+
verbose: true

0 commit comments

Comments
 (0)