Skip to content

Commit

Permalink
Merge pull request #69 from trinitronx/add-pre-commit-hook
Browse files Browse the repository at this point in the history
Add pre commit hook
  • Loading branch information
mrtazz authored Nov 15, 2022
2 parents 7e99987 + 486ea26 commit 4e37f3a
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: pre-commit

on:
pull_request:
branches:
- master
- main
paths:
- '.pre-commit-config.yaml'
- '.pre-commit-hooks.yaml'
- 'Makefile'
- 'makefile'
- 'GNUmakefile'
- '**.mk'
- '**.make'
push:
paths:
- '.pre-commit-config.yaml'
- '.pre-commit-hooks.yaml'
- 'Makefile'
- 'makefile'
- 'GNUmakefile'
- '**.mk'
- '**.make'

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go
- uses: pre-commit/[email protected]
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exclude: |
(?x)^(
vendor/.*
)$
repos:
- repo: https://github.com/mrtazz/checkmake.git
rev: 0.2.2
hooks:
- id: checkmake
exclude: |
(?x)^(
vendor/.*|
fixtures/missing_phony\.make
)$
11 changes: 11 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- id: checkmake
name: Makefile linter/analyzer
entry: checkmake
language: golang
pass_filenames: true
files: |
(?x)^(
(GNU)?[Mm]akefile|
.*\.mk|
.*\.make
)$
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,68 @@ Then run it with your Makefile attached, below is an example of it assuming the
docker run -v "$PWD"/Makefile:/Makefile checker
```

## `pre-commit` usage

This repo includes a `pre-commit` hook, which you may choose to use in your own
repos. Simply add a `.pre-commit-config.yaml` to your repo's top-level directory

```yaml
repos:
- repo: https://github.com/mrtazz/checkmake.git
rev: 0.2.2
hooks:
- id: checkmake
```
Then, run `pre-commit` as usual. For example:

```sh
pre-commit run --all-files
```

You may also choose to run this as a GitHub Actions workflow. To do this, add a
`.github/workflows/pre-commit.yml` workflow to your repo:

```yaml
name: pre-commit
on:
pull_request:
branches:
- master
- main
paths:
- '.pre-commit-config.yaml'
- '.pre-commit-hooks.yaml'
- 'Makefile'
- 'makefile'
- 'GNUmakefile'
- '**.mk'
- '**.make'
push:
paths:
- '.pre-commit-config.yaml'
- '.pre-commit-hooks.yaml'
- 'Makefile'
- 'makefile'
- 'GNUmakefile'
- '**.mk'
- '**.make'
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go
- uses: pre-commit/[email protected]
```

## Installation

### Requirements
Expand Down

0 comments on commit 4e37f3a

Please sign in to comment.