diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml new file mode 100644 index 000000000..d6fb95c53 --- /dev/null +++ b/.github/workflows/precommit.yml @@ -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 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..55aff9734 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 +#- 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 diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 000000000..1568ba478 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -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 \ No newline at end of file