Merge pull request #200 from dafyddj/precommit-commitlint

chore: add optional `pre-commit` configuration
This commit is contained in:
Imran Iqbal 2020-07-28 16:22:55 +01:00 committed by GitHub
commit 01a7eaa865
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 120 additions and 23 deletions

56
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,56 @@
# -*- 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/jumanjihouse/pre-commit-hooks
rev: 2.1.3
hooks:
- id: rubocop
exclude: ^Gemfile\.lock$
- id: shellcheck
name: Check shell scripts with shellcheck
exclude_types: [zsh]
args: []
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.23.0
hooks:
- id: yamllint
name: Check YAML syntax with yamllint
args: [--strict]
types: [file]
files: >
(?x)^(
\.salt-lint|
\.yamllint|
.*\.example|
test/.*\.sls|
.*\.(yaml|yml)
)$
exclude: ^test/.*/states/.*\.sls$
- 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
.rstcheck.cfg Normal file
View file

@ -0,0 +1,3 @@
[rstcheck]
report=error
ignore_language=rst

View file

@ -31,6 +31,9 @@ jobs:
# Run all of the linters in a single job
- language: 'node_js'
node_js: 'lts/*'
cache:
directories:
- $HOME/.cache/pre-commit
env: 'Lint'
name: 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint'
before_install: 'skip'
@ -54,6 +57,10 @@ jobs:
- npm i -D @commitlint/config-conventional
@commitlint/travis-cli
- commitlint-travis
# Install and run `pre-commit`
- pip install pre-commit
- pre-commit run --all-files --verbose
- pre-commit run --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

16
bin/install-hooks Executable file
View file

@ -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

View file

@ -821,20 +821,20 @@ BREAKING CHANGES
^^^^^^^^^^^^^^^^
*
*
**tofs:** every formula writer will need to change the import
to use this new version.
*
*
template/libtofs.jinja: provides the “files_switch” macro.
*
*
docs/TOFS_pattern.rst: update documentation to use the new path.
*
*
template/config/clean.sls: change import from “macros.jinja” to “libtofs.jinja”.
*
*
template/config/file.sls: ditoo.
`1.2.6 <https://github.com/saltstack-formulas/template-formula/compare/v1.2.5...v1.2.6>`_ (2019-03-24)
@ -1292,7 +1292,7 @@ Other
* Updated changelog and version. [Alexander Weidinger]
*
*
Map.jinja: use grains.filter_by instead of defaults.merge. [Alexander Weidinger]
because defaults.merge does not work with salt-ssh. https://github.com/saltstack/salt/issues/51605
@ -1317,7 +1317,7 @@ Other
----------------------------------------------------------------------------------------------------------
*
*
Examples must be consistent. [Daniel Dehennin]
The “template” is kept during rendering.
@ -1326,7 +1326,7 @@ Other
* TOFS_pattern.md: add “template” to rendered state.
* template/macros.jinja: ditoo.
*
*
Remove double slash in generated salt URL. [Daniel Dehennin]
When the files are “full path” with leading slash “/”, the generated URL contain a double slash because of the join.
@ -1335,22 +1335,22 @@ Other
* template/macros.jinja: remove leading slash before joining parts.
* TOFS_pattern.md: mirror changes of “macros.jinja”.
*
*
Add an example for “ntp” of the use of “files_switch” [Daniel Dehennin]
*
*
Accept pillar separator in “files_switch” prefix. [Daniel Dehennin]
The prefix was used for 2 purposes:
* define the pillar prefix where to lookup “:files_switch”. It supports the colon “:” separator to lookup in pillar subtree like “foo:bar”
*
*
define the path prefix where to look for “files/”, It did not support separator to lookup inside directory tree.
This patch only replace any colon “:” with “/” when looking up “files/” directory, with the “foo:bar” prefix:
*
*
lookup “foo:bar:files_switch” pillar to get list of grains to match
* lookup files under “salt://foo/bar/files/”
@ -1358,7 +1358,7 @@ Other
* template/macros.jinja: transform any colon “:” in “prefix” by slash
“/” to lookup files.
*
*
Make TOFS pattern example usable. [Daniel Dehennin]
The example could not be used as-is. This commit improve conformity to formula conventions.
@ -1367,14 +1367,14 @@ Other
* TOFS_pattern.md: add missing commas “,” in “map.jinja” and extra one
to ease the addition of new entries. Import “map.jinja” in “init.sls” and “conf.sls”. Declare descriptive state IDs. Use the “module.function” notation. Use the “name” parameter.
*
*
Cosmetics modification of TOFS pattern documentation. [Daniel Dehennin]
* TOFS_pattern.md: add myself as modifier.
Trim trailing whitespaces. Separate titles from first paragraph.
*
*
Switch template.config to TOFS pattern. [Daniel Dehennin]
* Import TOFS pattern from Zabbix formula. [Daniel Dehennin]
@ -1413,12 +1413,12 @@ Other
* Change states to use short-dec style. [Seth House]
* Update CHANGELOG.rst. [Nitin Madhok]
*
*
Update README.rst. [Nitin Madhok]
Fix broken link
*
*
Fixing pillar to match the map file. [Forrest]
Map file and pillar didn't match.

View file

@ -34,11 +34,11 @@ Adding a new page involves two steps:
a. Do not just append it to the list.
#. Select the best place where it fits within the overall documentation.
.. _saltstack_formulas_rst_page_template:
SaltStack-Formulas' RST page template
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. _saltstack_formulas_rst_page_template
Use the following template when creating a new page.
This ensures consistency across the documentation for this formula.
The heading symbols have been selected in accordance to the output rendered by the
@ -93,4 +93,3 @@ we are using for some of the pages of this documentation.
Obviously, it is not necessary to follow the steps in the order above.
For example, it is usually easier to write the ``[Introductory paragraph]``
at the end.

View file

@ -3,7 +3,7 @@
TEMPLATE-formula
================
|img_travis| |img_sr|
|img_travis| |img_sr| |img_pc|
.. |img_travis| image:: https://travis-ci.com/saltstack-formulas/TEMPLATE-formula.svg?branch=master
:alt: Travis CI Build Status
@ -13,6 +13,10 @@ TEMPLATE-formula
:alt: Semantic Release
:scale: 100%
:target: https://github.com/semantic-release/semantic-release
.. |img_pc| image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
:alt: pre-commit
:scale: 100%
:target: https://github.com/pre-commit/pre-commit
A SaltStack formula that is empty. It has dummy content to help with a quick
start on a new formula and it serves as a style guide.
@ -39,10 +43,24 @@ If you need (non-default) configuration, please pay attention to the ``pillar.ex
Contributing to this repo
-------------------------
Commit messages
^^^^^^^^^^^^^^^
**Commit message formatting is significant!!**
Please see `How to contribute <https://github.com/saltstack-formulas/.github/blob/master/CONTRIBUTING.rst>`_ for more details.
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.
First install the ``pre-commit`` package manager using the appropriate `method <https://pre-commit.com/#installation>`_, then run ``bin/install-hooks`` 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
Special notes
-------------
@ -201,4 +219,3 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri
^^^^^^^^^^^^^^^^^^^^^
Gives you SSH access to the instance for manual testing.

View file

@ -18,4 +18,3 @@
{
overflow: visible !important;
}