Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pre-commit): add pre-commit #259

Merged
merged 2 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ ignore: |
test/**/states/**/*.sls
.kitchen/
ssf/files/default/.cirrus.yml
ssf/files/default/.pre-commit-config.yaml
ssf/files/default/.rubocop.yml
ssf/files/default/.salt-lint
ssf/files/default/.travis.yml
ssf/files/default/.yamllint
ssf/files/default/kitchen.yml
ssf/files/default/inspec/inspec.yml
ssf/files/default/kitchen.yml
ssf/files/tofs_arvados-formula/.travis.yml
ssf/files/tofs_ssf-formula/.yamllint

Expand Down
3 changes: 3 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ ssf:
- zabbix
semrel_files:
- .github/workflows/commitlint.yml
- bin/install-hooks
- bin/kitchen
- docs/CONTRIBUTING.rst
- docs/TOFS_pattern.rst
Expand All @@ -183,6 +184,8 @@ ssf:
- inspec/README.md
- .gitignore
- .cirrus.yml
- .pre-commit-config.yaml
- .rstcheck.cfg
- .rubocop.yml
- .salt-lint
- .travis.yml
Expand Down
2 changes: 1 addition & 1 deletion ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ prepare-git-branch-for-{{ formula }}:
{%- if (semrel_file == '.cirrus.yml' and not use_cirrus_ci) or
(semrel_file == 'formula/libsaltcli.jinja' and not use_libsaltcli) or
(semrel_file in ['docs/TOFS_pattern.rst', 'formula/libtofs.jinja'] and not use_tofs) or
(semrel_file in ['docs/CONTRIBUTING.rst'] and formula not in ['.github'])
(semrel_file in ['docs/CONTRIBUTING.rst'] and formula not in ['.github', 'ssf-formula'])
%}
{%- set add_or_rm = ['rm', 'remove', 'absent'] %}
{%- endif %}
Expand Down
7 changes: 5 additions & 2 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 Expand Up @@ -55,8 +58,8 @@ ssf_node_anchors:
# An alternative method could be to use:
# `git describe --abbrev=0 --tags`
# yamllint disable rule:line-length rule:quoted-strings
title: "chore: standardise structure [skip ci]"
body: '* Automated using https://github.com/myii/ssf-formula/pull/261'
title: "ci(pre-commit): add to formula [skip ci]"
body: '* Automated using https://github.com/myii/ssf-formula/pull/259'
# yamllint enable rule:line-length rule:quoted-strings
github:
owner: 'saltstack-formulas'
Expand Down
57 changes: 57 additions & 0 deletions ssf/files/default/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- 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
{%- if travis.use_single_job_for_linters %}
- 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
{%- endif %}
- 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
26 changes: 15 additions & 11 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,7 @@ 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'] %}
# 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 %}

{%- 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 All @@ -167,6 +157,20 @@ jobs:
{{- format_rubocop_linter() }}
{%- endif %}

# 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_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 platforms and not use_cirrus_ci %}

## Define the rest of the matrix based on Kitchen testing
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
myii marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 14 additions & 0 deletions ssf/files/tofs_arvados-formula/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ jobs:
@commitlint/travis-cli
- commitlint-travis

# 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==2.7.1
- pre-commit run --all-files --color always --verbose
- pre-commit run --color always --hook-stage manual --verbose commitlint-travis

## Define the rest of the matrix based on Kitchen testing
# Make sure the instances listed below match up with
# the `platforms` defined in `kitchen.yml`
Expand Down
14 changes: 13 additions & 1 deletion 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,11 @@ ssf_node_anchors:
.cirrus.yml: &file__--cirrus--yml
<<: *file_default
template: 'jinja'
.pre-commit-config.yaml: &file__--pre-commit-config--yaml
<<: *file_default
template: 'jinja'
.rstcheck.cfg: &file__--rstcheck--cfg
<<: *file_default
.rubocop.yml: &file__--rubocop--yml
<<: *file_default
template: 'jinja'
Expand Down Expand Up @@ -4131,12 +4139,13 @@ ssf:
ignore:
additional:
- ssf/files/default/.cirrus.yml
- ssf/files/default/.pre-commit-config.yaml
- ssf/files/default/.rubocop.yml
- ssf/files/default/.salt-lint
- ssf/files/default/.travis.yml
- ssf/files/default/.yamllint
- ssf/files/default/kitchen.yml
- ssf/files/default/inspec/inspec.yml
- ssf/files/default/kitchen.yml
- ssf/files/tofs_arvados-formula/.travis.yml
- ssf/files/tofs_ssf-formula/.yamllint
rules:
Expand All @@ -4146,10 +4155,13 @@ ssf:
- ssf/formulas.yaml
semrel_files:
.github/workflows/commitlint.yml: *file__--github__workflows__commitlint--yml
bin/install-hooks: *file__bin__install-hooks
docs/CONTRIBUTING.rst: *file__docs__CONTRIBUTING--rst
docs/TOFS_pattern.rst: *file__docs__TOFS_pattern--rst
formula/libtofs.jinja: *file__formula__libtofs--jinja
.gitignore: *file__--gitignore
.pre-commit-config.yaml: *file__--pre-commit-config--yaml
.rstcheck.cfg: *file__--rstcheck--cfg
.rubocop.yml: *file__--rubocop--yml
.salt-lint: *file__--salt-lint
.travis.yml: *file__--travis--yml
Expand Down