From ab3e7fcb5d72cf6ecb22e8bedda1b5baba678867 Mon Sep 17 00:00:00 2001 From: juju4 Date: Sun, 8 Jan 2023 13:30:57 +0000 Subject: [PATCH 1/2] feat: add pre-commit-hooks+config to use with pre-commit.com And self-apply in github workflows. --- .github/workflows/precommit.yml | 31 +++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 20 ++++++++++++++++++++ .pre-commit-hooks.yaml | 13 +++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/precommit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .pre-commit-hooks.yaml 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..aeff69beb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: +#- repo: https://github.com/PowerShell/PSScriptAnalyzer +- repo: https://github.com/juju4/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 \ No newline at end of file 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 From 8a8643b38c48f0816849b32d92a0f5519b29ef2c Mon Sep 17 00:00:00 2001 From: juju4 Date: Sat, 26 Aug 2023 12:42:42 +0000 Subject: [PATCH 2/2] ci(pre-commit): revert repo to PowerShell/PSScriptAnalyzer --- .pre-commit-config.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aeff69beb..55aff9734 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,5 @@ repos: -#- repo: https://github.com/PowerShell/PSScriptAnalyzer -- repo: https://github.com/juju4/PSScriptAnalyzer +- repo: https://github.com/PowerShell/PSScriptAnalyzer rev: 3e3b2d7b7548fc5513b367cb3a80860d5bfd24db hooks: - id: powershell_scriptanalyzer @@ -17,4 +16,4 @@ repos: # language: script # always_run: true # pass_filenames: false -# verbose: true \ No newline at end of file +# verbose: true