diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..2f7d9b7 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -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/action@v2.0.3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100755 index 0000000..8f30690 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 + )$ diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100755 index 0000000..f3aa652 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,11 @@ +- id: checkmake + name: Makefile linter/analyzer + entry: checkmake + language: golang + pass_filenames: true + files: | + (?x)^( + (GNU)?[Mm]akefile| + .*\.mk| + .*\.make + )$ diff --git a/README.md b/README.md index 66f84d0..50d08a1 100644 --- a/README.md +++ b/README.md @@ -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/action@v2.0.3 +``` + ## Installation ### Requirements