Skip to content

Commit

Permalink
Merge pull request #167 from hartwork/replace-therapist-by-pre-commit
Browse files Browse the repository at this point in the history
Replace Therapist by pre-commit + make GitHub Actions enforce pre-commit clean code (fixes #161)
  • Loading branch information
peterbe authored Apr 19, 2024
2 parents e068483 + 5d36e8b commit f3d7cf0
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 13 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/pre-commit-detect-outdated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license

name: Detect outdated pre-commit hooks

on:
schedule:
- cron: '0 18 * * 5' # Every Friday 6pm
workflow_dispatch:

# NOTE: This will drop all permissions from GITHUB_TOKEN except metadata read,
# and then (re)add the ones listed below:
permissions:
contents: write
pull-requests: write

jobs:
pre_commit_detect_outdated:
name: Detect outdated pre-commit hooks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Set up Python 3.12
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: 3.12

- name: Install pre-commit
run: |-
pip install \
--disable-pip-version-check \
--no-warn-script-location \
--user \
pre-commit
echo "PATH=${HOME}/.local/bin:${PATH}" >> "${GITHUB_ENV}"
- name: Check for outdated hooks
run: |-
pre-commit autoupdate
git diff -- .pre-commit-config.yaml
- name: Create pull request from changes (if any)
id: create-pull-request
uses: peter-evans/create-pull-request@c55203cfde3e5c11a452d352b4393e68b85b4533 # v6.0.3
with:
author: 'pre-commit <pre-commit@tools.invalid>'
base: master
body: |-
For your consideration.
:warning: Please **CLOSE AND RE-OPEN** this pull request so that [further workflow runs get triggered](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs) for this pull request.
branch: precommit-autoupdate
commit-message: "pre-commit: Autoupdate"
delete-branch: true
draft: true
labels: enhancement
title: "pre-commit: Autoupdate"

- name: Log pull request URL
if: "${{ steps.create-pull-request.outputs.pull-request-url }}"
run: |
echo "Pull request URL is: ${{ steps.create-pull-request.outputs.pull-request-url }}"
24 changes: 24 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license

name: Run pre-commit

on:
- pull_request
- push
- workflow_dispatch

# Drop permissions to minimum for security
permissions:
contents: read

jobs:
pre-commit:
name: Run pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: 3.12
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
9 changes: 0 additions & 9 deletions .therapist.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ Code Style
All Python code should be run through `Black <https://pypi.org/project/black/>`_.
This is checked in CI and you can test it locally with ``tox``.

Also, this project uses `therapist <https://pypi.org/project/therapist/>`_
which helps with checking code style as a git pre-commit hook. ``therapist``
Also, this project uses `pre-commit <https://pre-commit.com/>`_
which helps with checking code style as a git pre-commit hook. ``pre-commit``
is used in ``tox``. To run all code style checks, use ``tox -e lint`` but
make sure your version of ``tox`` is built on a Python 3.

Expand Down
2 changes: 1 addition & 1 deletion lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flake8==7.0.0
black==24.2.0
setuptools==69.1.1
therapist==2.0.1
pre-commit==3.7.0
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ commands = pytest tests -v {posargs}
[testenv:lint]
deps =
-rlint-requirements.txt
commands=therapist run --use-tracked-files
commands=pre-commit run --all-files --show-diff-on-failure

[testenv:restlint]
deps =
Expand Down

0 comments on commit f3d7cf0

Please sign in to comment.