Skip to content

Commit

Permalink
feat(pre-commit): add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dafyddj committed Oct 2, 2020
1 parent bea257e commit e53c83b
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ssf_node_anchors:
specific_directories: []
specific_ssf:
- '/.github/workflows/': '@saltstack-formulas/ssf'
- '/bin/install-hooks': '@saltstack-formulas/ssf'
- '/bin/kitchen': '@saltstack-formulas/ssf'
- '/docs/AUTHORS.rst': '@saltstack-formulas/ssf'
- '/docs/CHANGELOG.rst': '@saltstack-formulas/ssf'
Expand All @@ -27,6 +28,8 @@ ssf_node_anchors:
- '/test/integration/**/README.md': '@saltstack-formulas/ssf'
- '/.gitignore': '@saltstack-formulas/ssf'
- '/.cirrus.yml': '@saltstack-formulas/ssf'
- '/.pre-commit-config.yaml': '@saltstack-formulas/ssf'
- '/.rstcheck.cfg': '@saltstack-formulas/ssf'
- '/.rubocop.yml': '@saltstack-formulas/ssf'
- '/.salt-lint': '@saltstack-formulas/ssf'
- '/.travis.yml': '@saltstack-formulas/ssf'
Expand Down
55 changes: 55 additions & 0 deletions ssf/files/default/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_stages: [commit]
repos:
- repo: https://github.com/dafyddj/commitlint-pre-commit-hook
rev: v2.3.0
hooks:
- id: commitlint
name: Check commit message using commitlint
description: Lint commit message against @commitlint/config-conventional rules
stages: [commit-msg]
additional_dependencies: ['@commitlint/config-conventional@8.3.4']
- id: commitlint-travis
stages: [manual]
additional_dependencies: ['@commitlint/config-conventional@8.3.4']
always_run: true
- repo: https://github.com/adithyabsk/mirrors-rubocop
rev: v0.91.0
hooks:
- id: rubocop
name: Check Ruby files with rubocop
args: [--debug]
always_run: true
pass_filenames: false
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.3
hooks:
- id: shellcheck
name: Check shell scripts with shellcheck
files: ^.*\.(sh|bash|ksh)$
types: []
args: []
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.23.0
hooks:
- id: yamllint
name: Check YAML syntax with yamllint
args: [--strict, '.']
always_run: true
pass_filenames: false
- repo: https://github.com/warpnet/salt-lint
rev: v0.3.0
hooks:
- id: salt-lint
name: Check Salt files using salt-lint
files: ^.*\.(sls|jinja|j2|tmpl|tst)$
- repo: https://github.com/myint/rstcheck
rev: 3f929574
hooks:
- id: rstcheck
name: Check reST files using rstcheck
args: [--report=warning]
3 changes: 3 additions & 0 deletions ssf/files/default/.rstcheck.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[rstcheck]
report=error
ignore_language=rst
22 changes: 12 additions & 10 deletions ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ jobs:
{{ comment_linters }}
- language: 'node_js'
node_js: 'lts/*'
{%- if semrel_formula in ['template'] %}
cache:
directories:
- $HOME/.cache/pre-commit
{%- endif %}
env: 'Lint'
name: '{{ name_linters }}'
before_install: 'skip'
Expand Down Expand Up @@ -149,12 +144,19 @@ jobs:
{#- Note: `--verbose` doesn't work yet, upstream issue created: #}
{#- - https://github.com/conventional-changelog/commitlint/issues/1695 #}
- commitlint-travis{{- ' --verbose' if semrel_formula == 'ssf' else '' }}
{%- if semrel_formula in ['template'] %}
# Run `pre-commit` linters in a single job
- language: 'python'
env: 'Lint_pre-commit'
name: 'Lint: pre-commit'
before_install: 'skip'
cache:
directories:
- $HOME/.cache/pre-commit
script:
# Install and run `pre-commit`
- pip install pre-commit
- pre-commit run --all-files --verbose
- pre-commit run --hook-stage manual --verbose commitlint-travis
{%- endif %}
- {{ pip_cmd }} install pre-commit==2.7.1
- pre-commit run --all-files --color always --verbose
- pre-commit run --color always --hook-stage manual --verbose commitlint-travis
{%- if not travis.use_single_job_for_linters %}
# Run the `rubocop` linter in a separate job that is allowed to fail
# Once these lint errors are fixed, this can be merged into a single job
Expand Down
16 changes: 16 additions & 0 deletions ssf/files/default/bin/install-hooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
set -o nounset # Treat unset variables as an error and immediately exit
set -o errexit # If a command fails exit the whole script

if [ "${DEBUG:-false}" = "true" ]; then
set -x # Run the entire script in debug mode
fi

if ! command -v pre-commit >/dev/null 2>&1; then
echo "pre-commit not found: please install or check your PATH" >&2
echo "See https://pre-commit.com/#installation" >&2
exit 1
fi

pre-commit install --install-hooks
pre-commit install --hook-type commit-msg --install-hooks
16 changes: 16 additions & 0 deletions ssf/files/tofs_.github/docs/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ So based on the example above:
* The ``(scope):`` will be shown in bold text without the brackets.
* The ``subject`` follows the ``scope`` as standard text.

pre-commit
^^^^^^^^^^

`pre-commit <https://pre-commit.com/>`_ is configured for this formula, which you may
optionally use to ease the steps involved in submitting your changes, including
checking the formatting of your commit messages.

First install the ``pre-commit`` package manager locally using the appropriate
`method <https://pre-commit.com/#installation>`_, then run ``bin/install-hooks`` in the
formula's root directory and now ``pre-commit`` will run automatically on each
``git commit``. ::

$ bin/install-hooks
pre-commit installed at .git/hooks/pre-commit
pre-commit installed at .git/hooks/commit-msg

Linting commit messages in Travis CI
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
7 changes: 7 additions & 0 deletions ssf/formulas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ ssf_node_anchors:
semrel_files: &semrel_files_default
.github/workflows/commitlint.yml: &file__--github__workflows__commitlint--yml
<<: *file_default
bin/install-hooks: &file__bin__install-hooks
<<: *file_default
mode: 755
bin/kitchen: &file__bin__kitchen
<<: *file_default
mode: 755
Expand All @@ -532,6 +535,10 @@ ssf_node_anchors:
.cirrus.yml: &file__--cirrus--yml
<<: *file_default
template: 'jinja'
.pre-commit-config.yaml: &file__--pre-commit-config--yaml
<<: *file_default
.rstcheck.cfg: &file__--rstcheck--cfg
<<: *file_default
.rubocop.yml: &file__--rubocop--yml
<<: *file_default
template: 'jinja'
Expand Down

0 comments on commit e53c83b

Please sign in to comment.