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

chore: add CI tests for the pre-commit hooks #9

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/test-pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
jobs:
test-hooks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure git safedir properly
run: git config --global --add safe.directory $(pwd)
amchiclet marked this conversation as resolved.
Show resolved Hide resolved
- name: Fake update file
run: git mv tests/python_simple.py python_simple.py
- name: Test semgrep pre-commit hook
uses: pre-commit/[email protected]
with:
extra_args: semgrep --hook-stage manual --files python_simple.py
- name: Test semgrep-ci pre-commit hook
uses: pre-commit/[email protected]
with:
extra_args: semgrep-ci --hook-stage manual --files python_simple.py
- name: Test semgrep-docker-develop pre-commit hook
uses: pre-commit/[email protected]
with:
extra_args: semgrep-docker-develop --hook-stage manual --files python_simple.py
- name: Test semgrep-docker pre-commit hook
uses: pre-commit/[email protected]
with:
extra_args: semgrep-docker --hook-stage manual --files python_simple.py

name: pre-commit-hook-test
on:
pull_request: null
push:
branches:
- develop
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# These hooks are meant to be triggered in CI to test the pre-commit hooks,
# so rather than triggering at every commit, including locally, they are triggered
# whenever the test-hooks CI workflow is run.
default_stages: [manual]

repos:
- repo: https://github.com/semgrep/pre-commit
rev: 'v1.76.0'
Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- repo: https://github.com/semgrep/pre-commit
rev: 'v1.76.0'
- repo: local

Can we just make this a local hook so it is testing the current configuration, rather than being a pointer to potentially something else?

See https://pre-commit.com/#repository-local-hooks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I can't just swap in local and there's more config fields that I need to understand. I'm gonna give up on trying that for now.

Copy link
Collaborator

@kopecs kopecs Jul 2, 2024

Choose a reason for hiding this comment

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

It may not be supported for the Python ones. Not sure.

ETA: Oh I see. Yeah, I don't like this, but that's more complex than I thought.

hooks:
- id: semgrep
name: Pre-commit semgrep
args: ["--config", "tests/python_simple.yml"]
- id: semgrep-ci
name: Pre-commit semgrep-ci
args: ["--config", "tests/python_simple.yml"]
- id: semgrep-docker-develop
name: Pre-commit semgrep-docker-develop
args: ["--config", "tests/python_simple.yml"]
- id: semgrep-docker
name: Pre-commit semgrep-docker
args: ["--config", "tests/python_simple.yml"]
1 change: 1 addition & 0 deletions tests/python_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
7 changes: 7 additions & 0 deletions tests/python_simple.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
- id: simple-python-rule
pattern: "0"
message: Simple python rule
languages:
- python
severity: INFO
Loading