Skip to content

Commit

Permalink
Merge pull request #200 from dafyddj/precommit-commitlint
Browse files Browse the repository at this point in the history
chore: add optional `pre-commit` configuration
  • Loading branch information
myii authored Jul 28, 2020
2 parents 55bc69a + a1d53a9 commit 01a7eaa
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 23 deletions.
56 changes: 56 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions .rstcheck.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[rstcheck]
report=error
ignore_language=rst
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions 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
34 changes: 17 additions & 17 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -1317,7 +1317,7 @@ Other
----------------------------------------------------------------------------------------------------------


*
*
Examples must be consistent. [Daniel Dehennin]

The “template” is kept during rendering.
Expand All @@ -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.
Expand All @@ -1335,30 +1335,30 @@ 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/”
* TOFS_pattern.md: document the new use of “prefix” supporting colon “:”.
* 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.
Expand All @@ -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]
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions docs/CONTRIBUTING_DOCS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

21 changes: 19 additions & 2 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
-------------

Expand Down Expand Up @@ -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.

1 change: 0 additions & 1 deletion docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
{
overflow: visible !important;
}

0 comments on commit 01a7eaa

Please sign in to comment.