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

Pre-commit CI #230

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
52 changes: 40 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# See https://pre-commit.com/hooks.html for more hooks
default_install_hook_types: [pre-commit, pre-push]
default_stages: [commit, push]
fail_fast: true
minimum_pre_commit_version: "2.18"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
# identify invalid files
- id: check-ast
Expand Down Expand Up @@ -41,17 +40,36 @@ repos:
- id: check-executables-have-shebangs
- id: end-of-file-fixer

- repo: https://github.com/hadolint/hadolint
rev: v2.12.1-beta
- repo: https://github.com/AleksaC/hadolint-py
rev: v2.12.0.3
hooks:
- id: hadolint-docker
- id: hadolint

- repo: https://github.com/ambv/black
rev: 23.7.0
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py310-plus]

- repo: https://github.com/adamchainz/django-upgrade
rev: 1.15.0
hooks:
- id: django-upgrade
args: [--target-version, "4.0"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.0
hooks:
- id: black
exclude: ^app/core/migrations/

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==23.12.0

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
Expand All @@ -71,32 +89,39 @@ repos:
flake8-executable,
flake8-pytest-style,
flake8-django,
flake8-comprehensions,
flake8-tidy-imports,
]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: ["--filter-files", "--force-single-line-imports"]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
rev: 1.7.6
hooks:
- id: bandit
exclude: ^app/core/tests/

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
- id: pyupgrade
- id: shellcheck

# - repo: https://github.com/econchick/interrogate
# rev: 1.4.0
# hooks:
# - id: interrogate
# args: [-vv, -i, --fail-under=80]

- repo: https://github.com/mxr/sync-pre-commit-deps
rev: v0.0.1
hooks:
- id: sync-pre-commit-deps

- repo: local
hooks:
- id: buildrun
Expand All @@ -121,3 +146,6 @@ repos:
language: system
types: [python] # hook only runs if a python file is staged
pass_filenames: false

ci:
skip: [check-django-migrations]
2 changes: 1 addition & 1 deletion app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."

while ! nc -z $SQL_HOST $SQL_PORT; do
while ! nc -z "$SQL_HOST" "$SQL_PORT"; do
sleep 0.1
done

Expand Down
3 changes: 0 additions & 3 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
black~=22.3.0
cryptography~=37.0.2
Django~=4.0.1
django-extensions~=3.1.5
Expand All @@ -8,8 +7,6 @@ django-timezone-field==5.0
djangorestframework~=3.13.1
drf-jwt~=1.19.2
drf-spectacular==0.22.1
flake8~=4.0.1
isort~=5.10.1
markdown~=3.4.1
psycopg2-binary~=2.9.3
pydot~=1.4.2
Expand Down
54 changes: 5 additions & 49 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ This command will unstage a file that you don't want included in the commit. The
git reset HEAD “filename.ext”
```

### 4.8 Run pre-commit checks
### 4.8 Install pre-commit

**Important: before committing each file, make sure to run the pre-commit hook:\***
This will check your changes for common problems.

```bash
./scripts/precommit-check.sh
```
See the [Pre-commit page](tools/pre-commit.md) for installation instructions.

For consistency, an automated bot will perform the same checks on the repository side when you open a pull request.

### 4.9 Commit staged changes

Expand Down Expand Up @@ -398,50 +398,6 @@ If you go to your online GitHub repository this should remove the message "This

To create a new issue, please use the blank issue template (available when you click New Issue). If you want to create an issue for other projects to use, please create the issue in your own repository and send a slack message to one of your hack night hosts with the link.

## 6. Pre-commit Hooks

The pre-commit hook in git is currently a work in progress.

The pre-commit hook in git will run before each commit and will abort the commit on failure. The advantage of this over GitHub Actions is that GitHub Actions work on code that's already committed, so it needs to allow code to be committed first.

We're setting a set of fast checks to run on each commit and longer checks such as a full rebuild to run when trying to push the code.

The hooks run when doing normal `git commit` and `git push` commands. It's recommended to do this in the command line. If performing these actions from a gui application, the interface may seem to hang for some time.

Installing the pre-commit hooks to git

1. Install pre-commit (virtual environment or at least per-user install is recommended)

```bash
pip install pre-commit --local
```

1. Add the hook to git

```bash
pre-commit install
```

1. Update pre-commit and plugins to the latest version

```bash
pre-commit autoupdate
```

1. Test run the hooks (this runs it against all files rather than only staged files)

```bash
pre-commit run --all-files
```

1. (Extra info) More commands to test run the hooks

```bash
pre-commit run --all-files --hook-stage push
pre-commit run --all-files --hook-stage commit
pre-commit run test --all-files --hook-stage push
```

# Appendix

## A. Submitting Bugs for Third Party Packages / Apps
Expand Down
Loading