Skip to content

Commit 877530b

Browse files
authored
Merge pull request #12 from Kpler/story/add-generic-github-action
feat: add generic gh action
2 parents 8377731 + bf3a567 commit 877530b

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
pre-commit-hooks
22
================
33

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

67
### Using pre-commit-hooks with pre-commit
78

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

43+
### Github actions
44+
45+
Run pre-commit hooks of type: commit, push and commit-msg
46+
47+
Example:
48+
```yaml
49+
jobs:
50+
pre-commit:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v2
54+
- uses: Kpler/kp-pre-commit-hooks@version
55+
with:
56+
skipped-hooks: 'no-commit-to-branch'
57+
main-branch: 'master'
58+
```
59+
60+
#### Alternatives:
61+
- [The official pre-commit action](https://github.com/pre-commit/action): deprecated and hard to use with several type of hooks
62+
- [The pre-commit CI](https://pre-commit.ci/): yet another CI and expensive (pricing per user)
63+
4264
### Contributing
4365

4466
#### Debugging / testing

action.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Pre-commit'
2+
description: 'Run pre-commit hooks'
3+
inputs:
4+
skipped-hooks:
5+
description: 'Skip some hooks, eg "no-commit-to-branch,foo"'
6+
required: true
7+
default: ''
8+
main-branch:
9+
description: 'master or main'
10+
required: true
11+
default: 'main'
12+
runs:
13+
using: "composite"
14+
steps:
15+
- uses: actions/setup-python@v2
16+
- name: Skip some hooks
17+
run: echo "SKIP=${{ inputs.skipped-hooks }}" >> $GITHUB_ENV
18+
if: ${{ inputs.skipped-hooks }} != ''
19+
shell: bash
20+
- name: Install pre-commit
21+
run: pip install pre-commit
22+
shell: bash
23+
- name: Cache pre-commit hooks
24+
uses: actions/cache@v2
25+
with:
26+
path: '~/.cache/pre-commit'
27+
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
28+
- name: Run pre-commit
29+
run: |
30+
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage commit
31+
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage push
32+
33+
# https://github.com/jorisroovers/gitlint/issues/148
34+
git config --add user.email ''
35+
git config --add user.name ''
36+
37+
git fetch origin ${{ inputs.main-branch }} 2> /dev/null
38+
for commit in $(git rev-list origin/${{ inputs.main-branch }}..HEAD)
39+
do
40+
git show -s --pretty=format:%B $commit > tmp
41+
pre-commit run --color=always --hook-stage commit-msg --commit-msg-filename tmp
42+
done
43+
shell: bash
44+

0 commit comments

Comments
 (0)