Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pre-commit-hooks+config to use with pre-commit.com #1879

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: precommit

on:
push:
pull_request:
workflow_dispatch:

permissions: {}

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install module from PSGallery
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -ErrorAction Stop
- uses: pre-commit/action@v2.0.0
with:
extra_args: --all-files --show-diff-on-failure
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/PowerShell/PSScriptAnalyzer
rev: 3e3b2d7b7548fc5513b367cb3a80860d5bfd24db
hooks:
- id: powershell_scriptanalyzer
# Note that client and server path may be different.
# Github image should be /usr/bin/pwsh
# Linux/Macos is usually /usr/local/bin/pwsh unless using a user scope
entry: /usr/bin/pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Severity Warning -Path . "
# https://github.com/pre-commit/pre-commit/pull/2340#issuecomment-1098203344
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this just be removed?

Copy link
Author

Choose a reason for hiding this comment

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

If removed, should be somewhere in docs (where?) as user may need to adapt powershell path

#- repo: local
# hooks:
# - id: pwsh
# name: pwsh
# entry: Invoke-ScriptAnalyzer.ps1 -Settings PSGallery -Recurse -EnableExit -Severity Warning -Path .
# language: script
# always_run: true
# pass_filenames: false
# verbose: true
13 changes: 13 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- id: powershell_scriptanalyzer
name: Powershell lint with PSScriptAnalyzer
description: This runs PSScriptAnalyzer on your powershell files
entry: pre-commit powershell_scriptanalyzer
language: script
files: ^.*\.ps1$
types: [text]
entry: pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Path ."
require_serial: false
additional_dependencies: []
minimum_pre_commit_version: '0'
pass_filenames: false
verbose: true