Skip to content

Commit

Permalink
Create initial pre-commit configuration
Browse files Browse the repository at this point in the history
The commit introduces a basic `pre-commit` configuration
with hooks for auto-fixing common code quality issues:

* Ensure files end with a newline (`end-of-file-fixer`),
* Standardizing line endings to LF (`mixed-line-ending`), and
* Removing trailing whitespace (`trailing-whitespace`).

Use a home-brewed pre-commit CI action, because the organization
cannot install the necessary pre-commit GitHub application.

Draw inspiration from:
* https://github.com/isaak654/sandboxie-docs/blob/6169c206fa9978641dafddf34303404604beaf33/.pre-commit-config.yaml
* https://github.com/isaak654/sandboxie-docs/blob/84751989d8fdee890520f116ea9e2ab0ff9f9b53/.github/workflows/action.yml#L59-L87

Signed-off-by: Stavros Ntentos <[email protected]>
  • Loading branch information
stdedos authored and isaak654 committed Sep 15, 2024
1 parent 0d11dd5 commit bce1b27
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: pre-commit

on:
# Triggers the workflow on ALL push or pull request events
# except for the `gh-pages`` branch
push:
branches-ignore:
- gh-pages
pull_request:
branches-ignore:
- gh-pages

permissions:
contents: write

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x

- uses: pre-commit/[email protected]

- name: Commit changes
if: ${{ !cancelled() && failure() }}
shell: bash
run: |
git config --local user.name "pre-commit-ci[bot]"
git config --local user.email "66853113+pre-commit-ci[bot]@users.noreply.github.com"
git commit -m "[pre-commit.ci] auto-fixes from pre-commit hooks" -a
git push origin HEAD:${{ github.head_ref || github.ref_name }}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
ghp-import site --push
- uses: actions/[email protected]
with:
path: './site'
path: './site'
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ci:
autofix_commit_msg: '[pre-commit.ci] auto-fixes from pre-commit hooks'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
args:
- --maxkb=10000
- id: check-merge-conflict
- id: mixed-line-ending
args:
- --fix=lf
- id: detect-private-key
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: trailing-whitespace

0 comments on commit bce1b27

Please sign in to comment.