Skip to content

Run pre-commit hooks at CI level

License

Notifications You must be signed in to change notification settings

SonarSource/gh-action_pre-commit

Folders and files

NameName
Last commit message
Last commit date
Feb 19, 2025
Mar 6, 2024
Mar 6, 2024
Mar 6, 2024
Feb 28, 2024
Mar 15, 2024
Sep 13, 2024
Feb 19, 2025

Repository files navigation

SonarSource GitHub Action for pre-commit

GitHub Release Quality Gate Status .github/workflows/it-test.yml

Run pre-commit hooks at CI level

Usage

enforce pre-commit only to files changed within a pull request

Place a .pre-commit-config.yaml at the root of your project

Create a new GitHub workflow:

# .github/workflows/pre-commit.yml
on:
  pull_request:

jobs:
  pre-commit:
    name: "pre-commit"
    runs-on: ubuntu-latest
    steps:
      - uses: SonarSource/gh-action_pre-commit@0.0.1 <--- replace with the last tag
        with:
          extra-args: >
            --from-ref=origin/${{ github.event.pull_request.base.ref }}
            --to-ref=${{ github.event.pull_request.head.sha }}

Notice: the extra-args parameter defined upper ensure that only files changed within the PR are checked by pre-commit. If you rather like to ensure that all files are valid, have a look at the example below.

enforce pre-commit to all files systematically

Place a .pre-commit-config.yaml at the root of your project

Create a new GitHub workflow:

# .github/workflows/pre-commit.yml
on:
  branch:
    - master

jobs:
  pre-commit:
    name: "pre-commit"
    runs-on: ubuntu-latest
    steps:
      - uses: SonarSource/gh-action_pre-commit@0.0.1 <--- replace with last tag
        with:
          extra-args: --all-files

Options

Option name Description Default
config-path Used to specify a custom path to a given .pre-commit-config.yaml .pre-commit-config.yaml
extra-args Used to pass extra pre-commit args to the pre-commit run command -
ignore-failure Used to not fail the gh-action in case of pre-commit check failure false

Versioning

This project is using Semantic Versioning.

The master branch shall not be referenced by end-users, please use tags instead and Renovate or Dependabot to stay up to date.

Contribute

Contributions are welcome, please have a look at DEV.md