Skip to content

Commit

Permalink
Merge pull request #12 from Kpler/story/add-generic-github-action
Browse files Browse the repository at this point in the history
feat: add generic gh action
  • Loading branch information
leo-dur authored Dec 2, 2021
2 parents 8377731 + bf3a567 commit 877530b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pre-commit-hooks
================

Some out-of-the-box hooks for [pre-commit](https://github.com/pre-commit/pre-commit).
Some out-of-the-box hooks for [pre-commit](https://github.com/pre-commit/pre-commit), and
a github action to easily run all kind of hooks from github CI.

### Using pre-commit-hooks with pre-commit

Expand Down Expand Up @@ -39,6 +40,27 @@ Time is fleeting, we change services.
Consequently to keep the code futureproof we don't
want links to ephemeral thrid party stuff (slack, clubhouse, atlassian)

### Github actions

Run pre-commit hooks of type: commit, push and commit-msg

Example:
```yaml
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Kpler/kp-pre-commit-hooks@version
with:
skipped-hooks: 'no-commit-to-branch'
main-branch: 'master'
```

#### Alternatives:
- [The official pre-commit action](https://github.com/pre-commit/action): deprecated and hard to use with several type of hooks
- [The pre-commit CI](https://pre-commit.ci/): yet another CI and expensive (pricing per user)

### Contributing

#### Debugging / testing
Expand Down
44 changes: 44 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'Pre-commit'
description: 'Run pre-commit hooks'
inputs:
skipped-hooks:
description: 'Skip some hooks, eg "no-commit-to-branch,foo"'
required: true
default: ''
main-branch:
description: 'master or main'
required: true
default: 'main'
runs:
using: "composite"
steps:
- uses: actions/setup-python@v2
- name: Skip some hooks
run: echo "SKIP=${{ inputs.skipped-hooks }}" >> $GITHUB_ENV
if: ${{ inputs.skipped-hooks }} != ''
shell: bash
- name: Install pre-commit
run: pip install pre-commit
shell: bash
- name: Cache pre-commit hooks
uses: actions/cache@v2
with:
path: '~/.cache/pre-commit'
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage commit
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage push
# https://github.com/jorisroovers/gitlint/issues/148
git config --add user.email ''
git config --add user.name ''
git fetch origin ${{ inputs.main-branch }} 2> /dev/null
for commit in $(git rev-list origin/${{ inputs.main-branch }}..HEAD)
do
git show -s --pretty=format:%B $commit > tmp
pre-commit run --color=always --hook-stage commit-msg --commit-msg-filename tmp
done
shell: bash

0 comments on commit 877530b

Please sign in to comment.