From 5cdefdc6a5993addcc73090831e821460735e4c3 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 2 Jul 2020 03:25:34 +0100 Subject: [PATCH 01/10] chore(pre-commit): check commit message using `commitlint` --- .pre-commit-config.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..80909fd5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v2.2.3 + hooks: + - id: commitlint + name: Check commit message against @commitlint/config-conventional rules + stages: [commit-msg] + additional_dependencies: ['@commitlint/config-conventional@8.3.4'] From 5bccc810bafb666bc098255ddbff8017244c17f7 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 2 Jul 2020 03:30:15 +0100 Subject: [PATCH 02/10] chore(pre-commit): check Ruby files using `rubocop` --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 80909fd5..bfd26734 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ --- # 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/alessandrojcm/commitlint-pre-commit-hook rev: v2.2.3 @@ -11,3 +12,8 @@ repos: name: Check commit message against @commitlint/config-conventional rules stages: [commit-msg] additional_dependencies: ['@commitlint/config-conventional@8.3.4'] + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 2.1.3 + hooks: + - id: rubocop + exclude: ^Gemfile\.lock$ From 3f26ea7cd4aedeedc1c78fbe530ac774eb6d7dc9 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 2 Jul 2020 05:18:01 +0100 Subject: [PATCH 03/10] chore(pre-commit): check YAML files using `yamllint` --- .pre-commit-config.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bfd26734..1b636295 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,19 @@ repos: hooks: - id: rubocop exclude: ^Gemfile\.lock$ + - 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$ From c50c0810696d04fcc4709b80f5796de04fd811c0 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 2 Jul 2020 18:33:29 +0100 Subject: [PATCH 04/10] chore(pre-commit): check shell files using `shellcheck` --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b636295..0689c427 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,10 @@ repos: 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: From 70117620d7c279d21d00d960593914af0d7e2b52 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 2 Jul 2020 19:13:28 +0100 Subject: [PATCH 05/10] chore(pre-commit): check Salt files using `salt-lint` --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0689c427..fee836df 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,3 +37,9 @@ repos: .*\.(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)$ From 01fd4e65f44284357cdb06bc9a8a027887933deb Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Mon, 6 Jul 2020 16:39:38 +0100 Subject: [PATCH 06/10] chore(pre-commit): add utility script to install hooks and environments --- bin/install-hooks | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 bin/install-hooks diff --git a/bin/install-hooks b/bin/install-hooks new file mode 100755 index 00000000..840bb6c5 --- /dev/null +++ b/bin/install-hooks @@ -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 From d98d98f4da1096f4c60c5ec5c15d56d1945c9f50 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Mon, 6 Jul 2020 16:49:06 +0100 Subject: [PATCH 07/10] docs: fix whitespace --- docs/CHANGELOG.rst | 34 +++++++++++++++++----------------- docs/CONTRIBUTING_DOCS.rst | 1 - docs/README.rst | 1 - docs/_static/css/custom.css | 1 - 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index e1525b48..e6e9517c 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -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 `_ (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. diff --git a/docs/CONTRIBUTING_DOCS.rst b/docs/CONTRIBUTING_DOCS.rst index 55673df7..da01c703 100644 --- a/docs/CONTRIBUTING_DOCS.rst +++ b/docs/CONTRIBUTING_DOCS.rst @@ -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. - diff --git a/docs/README.rst b/docs/README.rst index 94c6ad75..f43dee2f 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -201,4 +201,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. - diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css index 4617efcd..e6cc1ded 100644 --- a/docs/_static/css/custom.css +++ b/docs/_static/css/custom.css @@ -18,4 +18,3 @@ { overflow: visible !important; } - From c78c06876eb4c117b3ab00f9da479e8a4c3f1cf5 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Mon, 6 Jul 2020 17:20:49 +0100 Subject: [PATCH 08/10] docs: add basic `pre-commit` usage instructions --- docs/README.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/README.rst b/docs/README.rst index f43dee2f..046fed5b 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -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 `_ for more details. +pre-commit +^^^^^^^^^^ + +`pre-commit `_ 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 `_, 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 ------------- From 6da26cca6a3b3ac89137d81b837633358c534396 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Fri, 10 Jul 2020 01:00:00 +0100 Subject: [PATCH 09/10] ci(travis): run linters using `pre-commit` --- .pre-commit-config.yaml | 11 ++++++++--- .travis.yml | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fee836df..528f996b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,13 +5,18 @@ # See https://pre-commit.com/hooks.html for more hooks default_stages: [commit] repos: - - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook - rev: v2.2.3 + - repo: https://github.com/dafyddj/commitlint-pre-commit-hook + rev: v2.3.0 hooks: - id: commitlint - name: Check commit message against @commitlint/config-conventional rules + 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: diff --git a/.travis.yml b/.travis.yml index 43158df6..bee439ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From a1d53a975882746fac27041f30092d6ce5cb7a77 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Tue, 28 Jul 2020 13:39:59 +0100 Subject: [PATCH 10/10] chore(pre-commit): check reST files using `rstcheck` --- .pre-commit-config.yaml | 6 ++++++ .rstcheck.cfg | 3 +++ docs/CONTRIBUTING_DOCS.rst | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .rstcheck.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 528f996b..4f05fda5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,3 +48,9 @@ repos: - 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] diff --git a/.rstcheck.cfg b/.rstcheck.cfg new file mode 100644 index 00000000..05856dc7 --- /dev/null +++ b/.rstcheck.cfg @@ -0,0 +1,3 @@ +[rstcheck] +report=error +ignore_language=rst diff --git a/docs/CONTRIBUTING_DOCS.rst b/docs/CONTRIBUTING_DOCS.rst index da01c703..b68bb77a 100644 --- a/docs/CONTRIBUTING_DOCS.rst +++ b/docs/CONTRIBUTING_DOCS.rst @@ -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