From ac9b7a5c4cf953aba96c5162f48e7be0dfe8fbe4 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 14:35:40 +0100 Subject: [PATCH 01/13] refactor(defaults): use node anchors for common `line_length` values * To be reused for upcoming `rubocop` settings as well --- ssf/defaults.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index c89acd6b..479eadd4 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -3,6 +3,11 @@ --- ssf_node_anchors: defaults: + common: + lint: + line_length: + bugbear: &line_length_bugbear 88 + default: &line_length_default 80 formula: &formula_default context: &context_default git: @@ -207,9 +212,9 @@ ssf_node_anchors: key-duplicates: {} # key-ordering: {} line-length: - bugbear: 88 - default: 80 - max: 88 + bugbear: *line_length_bugbear + default: *line_length_default + max: *line_length_bugbear # new-line-at-end-of-file: {} # new-lines: {} octal-values: From dbee3f7e48756957f975698441e78165f2c287bb Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 17:43:14 +0100 Subject: [PATCH 02/13] feat(travis): update for new structure of merging the `lint` stage --- ssf/files/default/.travis.yml | 93 ++++++++++++++++++++--------------- ssf/libcimatrix.jinja | 9 +++- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/ssf/files/default/.travis.yml b/ssf/files/default/.travis.yml index 0a327e51..83deaebc 100644 --- a/ssf/files/default/.travis.yml +++ b/ssf/files/default/.travis.yml @@ -2,20 +2,10 @@ # vim: ft=yaml --- {%- from tplroot ~ "/libcimatrix.jinja" import format_ci_matrix with context %} +## Machine config dist: {{ travis.dist }} -stages: - {%- if platforms and not use_cirrus_ci %} - - test - {%- endif %} - - lint - - name: release - if: branch = master AND type != pull_request {%- if platforms and not use_cirrus_ci %} - sudo: required -cache: bundler -language: ruby - services: - docker {%- set travis_addons = travis.addons %} @@ -29,59 +19,80 @@ addons: # yamllint enable rule:indentation {%- endif %} -# Make sure the instances listed below match up with -# the `platforms` defined in `kitchen.yml` -{%- if semrel_formula == 'template' %} -# NOTE: Please try to select up to six instances that add some meaningful -# testing of the formula's behaviour. If possible, try to refrain from -# the classical "chosing all the instances because I want to test on -# another/all distro/s" trap: it will just add time to the testing (see -# the discussion on #121). As an example, the set chosen below covers -# the most used distros families, systemd and non-systemd and the latest -# three supported Saltstack versions with python2 and 3. -# As for `kitchen.yml`, that should still contain all of the platforms, -# to allow for comprehensive local testing -# Ref: https://github.com/saltstack-formulas/template-formula/issues/118 -# Ref: https://github.com/saltstack-formulas/template-formula/issues/121 -{%- endif %} -env: - matrix: - {%- if semrel_formula == 'salt' %} - # The ordering used below has been selected based on the time required in Travis - # The slower ones are kept as high up as possible, to run concurrently rather than - # slow down the entire run at the end (i.e. `centos-6` and `opensuse`) - # However, the groupings needed to be maintained in some semblance of order - # so this is a best-effort matrix, in the circumstances - {%- endif %} - {{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula) }} +## Language and cache config +language: ruby +cache: bundler +## Script to run for the test stage script: {%- for pre_cmd in script_kitchen.pre %} - {{ pre_cmd }} {%- endfor %} - - {{ script_kitchen.bin }} {{ script_kitchen.cmd }} ${INSTANCE} + - {{ script_kitchen.bin }} {{ script_kitchen.cmd }} "${INSTANCE}" {%- for post_cmd in script_kitchen.post %} - {{ post_cmd }} {%- endfor %} {%- endif %} +## Stages and jobs matrix +stages: + - test + - name: release + if: branch = master AND type != pull_request jobs: include: - # Define the `lint` stage (runs `yamllint` and `commitlint`) - - stage: lint - language: node_js + ## Define the test stage that runs the linters (and testing matrix, if applicable) + + # Run all of the linters in a single job + - language: node_js node_js: lts/* + env: 'Lint: salt-lint, yamllint, rubocop & commitlint' before_install: skip script: + # Install and run `salt-lint` + - pip install --user salt-lint + - git ls-files | grep '\.sls$\|\.jinja$\|\.j2$\|\.tmpl$' + | xargs -I {} salt-lint {} # Install and run `yamllint` # Need at least `v1.17.0` for the `yaml-files` setting - pip install --user yamllint>=1.17.0 - yamllint -s . + # Install and run `rubocop` + - gem install rubocop + - rubocop -d # Install and run `commitlint` - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D - commitlint-travis - # Define the release stage that runs `semantic-release` + + {%- if platforms and not use_cirrus_ci %} + + ## 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` + {%- if semrel_formula == 'template' %} + # NOTE: Please try to select up to six instances that add some meaningful + # testing of the formula's behaviour. If possible, try to refrain from + # the classical "chosing all the instances because I want to test on + # another/all distro/s" trap: it will just add time to the testing (see + # the discussion on #121). As an example, the set chosen below covers + # the most used distros families, systemd and non-systemd and the latest + # three supported Saltstack versions with python2 and 3. + # As for `kitchen.yml`, that should still contain all of the platforms, + # to allow for comprehensive local testing + # Ref: https://github.com/saltstack-formulas/template-formula/issues/118 + # Ref: https://github.com/saltstack-formulas/template-formula/issues/121 + {%- elif semrel_formula == 'salt' %} + # The ordering used below has been selected based on the time required in Travis + # The slower ones are kept as high up as possible, to run concurrently rather than + # slow down the entire run at the end (i.e. `centos-6` and `opensuse`) + # However, the groupings needed to be maintained in some semblance of order + # so this is a best-effort matrix, in the circumstances + {%- endif %} + {{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, use_new_travis_format=True) }} + {%- endif %} + + ## Define the release stage that runs `semantic-release` - stage: release language: node_js node_js: lts/* diff --git a/ssf/libcimatrix.jinja b/ssf/libcimatrix.jinja index 7ef96130..50c4fef2 100644 --- a/ssf/libcimatrix.jinja +++ b/ssf/libcimatrix.jinja @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{%- macro format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=4) %} +{%- macro format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=4, use_new_travis_format=False ) %} {%- filter indent(width) %} {#- Centralise duplication from here and `kitchen.yml` #} {%- set platform_and_suite_names_done = [] %} @@ -48,6 +48,11 @@ {%- set include_instance = False %} {%- endif %} {%- endif %} +{#- Define `instance_and_env`, modified for new Travis format #} +{%- set instance_and_env = 'INSTANCE: ' %} +{%- if use_new_travis_format %} +{%- set instance_and_env = 'env: INSTANCE=' %} +{%- endif %} {%- if include_instance %} {#- Only add a prefix if suite_name is given #} {%- set prefix = '' %} @@ -62,7 +67,7 @@ salt_ver | replace('.', '-'), py_ver, ) %} -{{ comment }}- INSTANCE: {{ instance }} +{{ comment }}- {{instance_and_env }}{{ instance }} {%- endif %} {%- endif %} {%- endif %} From 8d86eb4a32c095a49d80a7c27e4b4ea9d4c69dcc Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 19:49:23 +0100 Subject: [PATCH 03/13] feat(travis): use `env` and `name` for improved display in Travis * https://github.com/saltstack-formulas/template-formula/pull/175#discussion_r332613933 --- ssf/files/default/.travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ssf/files/default/.travis.yml b/ssf/files/default/.travis.yml index 83deaebc..e6723b8b 100644 --- a/ssf/files/default/.travis.yml +++ b/ssf/files/default/.travis.yml @@ -46,7 +46,8 @@ jobs: # Run all of the linters in a single job - language: node_js node_js: lts/* - env: 'Lint: salt-lint, yamllint, rubocop & commitlint' + env: Lint + name: 'Lint: salt-lint, yamllint, rubocop & commitlint' before_install: skip script: # Install and run `salt-lint` @@ -96,6 +97,8 @@ jobs: - stage: release language: node_js node_js: lts/* + env: Release + name: 'Run semantic-release inc. file updates to AUTHORS, CHANGELOG & FORMULA' before_install: skip script: # Update `AUTHORS.md` From 1d9636e6e27eafd096916a1cda7eca7e5d302176 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Fri, 4 Oct 2019 17:24:25 +0100 Subject: [PATCH 04/13] feat(salt-lint): include for this repo --- pillar.example | 1 + ssf/config/formulas.sls | 1 + ssf/defaults.yaml | 6 ++++-- ssf/files/default/.salt-lint | 13 +++++++++++++ ssf/formulas.yaml | 5 +++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 ssf/files/default/.salt-lint diff --git a/pillar.example b/pillar.example index 8b89e0d5..bcae88d7 100644 --- a/pillar.example +++ b/pillar.example @@ -127,6 +127,7 @@ ssf: - inspec/README.md - .gitignore - .cirrus.yml + - .salt-lint - .travis.yml - .yamllint - commitlint.config.js diff --git a/ssf/config/formulas.sls b/ssf/config/formulas.sls index b4ba1f31..f19ec14c 100644 --- a/ssf/config/formulas.sls +++ b/ssf/config/formulas.sls @@ -109,6 +109,7 @@ prepare-git-branch-for-{{ formula }}: platforms: {{ context.platforms | yaml }} platforms_matrix: {{ context.platforms_matrix | yaml }} platforms_matrix_commented_includes: {{ context.platforms_matrix_commented_includes | yaml }} + salt_lint: {{ context.salt_lint | yaml }} script_kitchen: {{ context.script_kitchen | yaml }} suite: {{ suite | yaml }} travis: {{ context.travis | yaml }} diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index 479eadd4..ab389c1b 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -22,8 +22,8 @@ ssf_node_anchors: # An alternative method could be to use: # `git describe --abbrev=0 --tags` # yamllint disable rule:line-length - title: 'feat(tofs): implementation for all file.managed' - body: '* Checked using https://github.com/myii/ssf-formula/pull/54' + title: 'ci: merge travis matrix, add `salt-lint` & `rubocop` to `lint` job' + body: '* Automated using https://github.com/myii/ssf-formula/pull/60' # yamllint enable rule:line-length github: owner: saltstack-formulas @@ -164,6 +164,7 @@ ssf_node_anchors: # To deal with excessive instances when mimicking `kitchen list -b` # If values are set, only use these as commented entries in the matrix platforms_matrix_commented_includes: [] + salt_lint: {} script_kitchen: bin: bin/kitchen cmd: verify @@ -187,6 +188,7 @@ ssf_node_anchors: default: - '*.yaml' - '*.yml' + - '.salt-lint' - '.yamllint' additional_ssf: - '*.example' diff --git a/ssf/files/default/.salt-lint b/ssf/files/default/.salt-lint new file mode 100644 index 00000000..a539954b --- /dev/null +++ b/ssf/files/default/.salt-lint @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: [] +skip_list: + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index 632a4a3b..b8a615dc 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -181,6 +181,9 @@ ssf_node_anchors: .cirrus.yml: &file__--cirrus--yml <<: *file_default template: jinja + .salt-lint: &file__--salt-lint + <<: *file_default + template: jinja .travis.yml: &file__--travis--yml <<: *file_default template: jinja @@ -1256,6 +1259,7 @@ ssf: ignore: additional: - ssf/files/default/.cirrus.yml + - ssf/files/default/.salt-lint - ssf/files/default/.travis.yml - ssf/files/default/.yamllint - ssf/files/default/kitchen.yml @@ -1274,6 +1278,7 @@ ssf: docs/TOFS_pattern.rst: *file__docs__TOFS_pattern--rst formula/libtofs.jinja: *file__formula__libtofs--jinja .gitignore: *file__--gitignore + .salt-lint: *file__--salt-lint .travis.yml: *file__--travis--yml .yamllint: *file__--yamllint commitlint.config.js: *file__commitlint--config--js From f4fc3c16051ce0dea1a173cd6b39307225c1fe3f Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 14:57:17 +0100 Subject: [PATCH 05/13] feat(rubocop): include for this repo --- .yamllint | 1 + pillar.example | 1 + ssf/config/formulas.sls | 1 + ssf/defaults.yaml | 7 +++++++ ssf/files/default/.rubocop.yml | 37 ++++++++++++++++++++++++++++++++++ ssf/formulas.yaml | 5 +++++ 6 files changed, 52 insertions(+) create mode 100644 ssf/files/default/.rubocop.yml diff --git a/.yamllint b/.yamllint index 04440a0f..845783cc 100644 --- a/.yamllint +++ b/.yamllint @@ -15,6 +15,7 @@ ignore: | test/**/states/**/*.sls .kitchen/ ssf/files/default/.cirrus.yml + ssf/files/default/.rubocop.yml ssf/files/default/.travis.yml ssf/files/default/.yamllint ssf/files/default/kitchen.yml diff --git a/pillar.example b/pillar.example index bcae88d7..4d42e733 100644 --- a/pillar.example +++ b/pillar.example @@ -127,6 +127,7 @@ ssf: - inspec/README.md - .gitignore - .cirrus.yml + - .rubocop.yml - .salt-lint - .travis.yml - .yamllint diff --git a/ssf/config/formulas.sls b/ssf/config/formulas.sls index f19ec14c..16ade30a 100644 --- a/ssf/config/formulas.sls +++ b/ssf/config/formulas.sls @@ -109,6 +109,7 @@ prepare-git-branch-for-{{ formula }}: platforms: {{ context.platforms | yaml }} platforms_matrix: {{ context.platforms_matrix | yaml }} platforms_matrix_commented_includes: {{ context.platforms_matrix_commented_includes | yaml }} + rubocop: {{ context.rubocop | yaml }} salt_lint: {{ context.salt_lint | yaml }} script_kitchen: {{ context.script_kitchen | yaml }} suite: {{ suite | yaml }} diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index ab389c1b..d68106ec 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -164,6 +164,13 @@ ssf_node_anchors: # To deal with excessive instances when mimicking `kitchen list -b` # If values are set, only use these as commented entries in the matrix platforms_matrix_commented_includes: [] + rubocop: + AllCops: {} + Cops: + Metrics/LineLength: + Bugbear: *line_length_bugbear + Default: *line_length_default + Max: *line_length_bugbear salt_lint: {} script_kitchen: bin: bin/kitchen diff --git a/ssf/files/default/.rubocop.yml b/ssf/files/default/.rubocop.yml new file mode 100644 index 00000000..e2e69981 --- /dev/null +++ b/ssf/files/default/.rubocop.yml @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# General overrides used across formulas in the org +{%- set MLL = 'Metrics/LineLength' %} +{{ MLL }}: + {%- set rbcp_MLL = rubocop.Cops.get(MLL) %} + {%- if rbcp_MLL.Max == rbcp_MLL.Bugbear %} + # Increase from default of `{{ rbcp_MLL.Default }}` + # Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`) + {%- endif %} + Max: {{ rbcp_MLL.Max }} + +{%- if rubocop.AllCops %} + +# General settings across all cops in this formula +AllCops: + {#- This is purposefully simplistic for the time being, + until (if ever) more advanced configuration is necessary #} + {%- if rubocop.AllCops.Exclude %} + # Files to ignore completely + Exclude: + {%- for path in rubocop.AllCops.Exclude %} + - {{ path }} + {%- endfor %} + {%- endif %} +{%- endif %} + +# Any offenses that should be fixed, e.g. collected via. `rubocop --auto-gen-config` +{%- for cop, config in rubocop.Cops.items() if cop not in [MLL] %} +{{ cop }}: + {#- This is purposefully simplistic for the time being, + until (if ever) more advanced configuration is necessary #} + {%- for k, v in config.items() %} + {{ k }}: {{ v }} + {%- endfor %} +{%- endfor %} diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index b8a615dc..6d37ca2e 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -181,6 +181,9 @@ ssf_node_anchors: .cirrus.yml: &file__--cirrus--yml <<: *file_default template: jinja + .rubocop.yml: &file__--rubocop--yml + <<: *file_default + template: jinja .salt-lint: &file__--salt-lint <<: *file_default template: jinja @@ -1259,6 +1262,7 @@ ssf: ignore: additional: - ssf/files/default/.cirrus.yml + - ssf/files/default/.rubocop.yml - ssf/files/default/.salt-lint - ssf/files/default/.travis.yml - ssf/files/default/.yamllint @@ -1278,6 +1282,7 @@ ssf: docs/TOFS_pattern.rst: *file__docs__TOFS_pattern--rst formula/libtofs.jinja: *file__formula__libtofs--jinja .gitignore: *file__--gitignore + .rubocop.yml: *file__--rubocop--yml .salt-lint: *file__--salt-lint .travis.yml: *file__--travis--yml .yamllint: *file__--yamllint From e0ec88a2fc28f5912115b417a95aa8d499da8e1a Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 03:05:00 +0100 Subject: [PATCH 06/13] fix(gemfile): fix `rubocop` errors --- ssf/files/default/Gemfile | 7 ++++--- ssf/files/tofs_vault-formula/Gemfile | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ssf/files/default/Gemfile b/ssf/files/default/Gemfile index 3b36de32..5a232b61 100644 --- a/ssf/files/default/Gemfile +++ b/ssf/files/default/Gemfile @@ -1,6 +1,7 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' gem 'kitchen-docker', '>= 2.9' -gem 'kitchen-salt', '>= 0.6.0' gem 'kitchen-inspec', '>= 1.1' - +gem 'kitchen-salt', '>= 0.6.0' diff --git a/ssf/files/tofs_vault-formula/Gemfile b/ssf/files/tofs_vault-formula/Gemfile index 2c331187..f2c41f6d 100644 --- a/ssf/files/tofs_vault-formula/Gemfile +++ b/ssf/files/tofs_vault-formula/Gemfile @@ -1,7 +1,8 @@ -source "https://rubygems.org" +# frozen_string_literal: true +source 'https://rubygems.org' + +gem 'inspec', '~> 4.16.0' gem 'kitchen-docker', '>= 2.9' -gem 'kitchen-salt', '>= 0.6.0' gem 'kitchen-inspec', '>= 1.1' -gem 'inspec', '~> 4.16.0' - +gem 'kitchen-salt', '>= 0.6.0' From 58881a71d4a51dc413dba63835d7552ad42d6f3a Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 03:06:54 +0100 Subject: [PATCH 07/13] fix(bin/kitchen): fix `rubocop` errors --- ssf/files/default/bin/kitchen | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ssf/files/default/bin/kitchen b/ssf/files/default/bin/kitchen index 1cd44f3a..dcfdb4ca 100755 --- a/ssf/files/default/bin/kitchen +++ b/ssf/files/default/bin/kitchen @@ -8,22 +8,25 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ load(bundle_binstub) else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + abort( + 'Your `bin/bundle` was not generated by Bundler, '\ + 'so this binstub cannot run. Replace `bin/bundle` by running '\ + '`bundle binstubs bundler --force`, then run this command again.' + ) end end -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("test-kitchen", "kitchen") +load Gem.bin_path('test-kitchen', 'kitchen') From 212edf087b87d78ca833253215594c358c39b823 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 14:57:45 +0100 Subject: [PATCH 08/13] feat(rubocop): add per-formula overrides --- ssf/formulas.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index 6d37ca2e..cb7908b4 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -262,6 +262,10 @@ ssf: # - [ubuntu , 18.04, develop, 3, preferences] - [debian , 9 , 2019.2, 3, preferences] - [ubuntu , 18.04, 2019.2, 3, preferences] + rubocop: + Cops: + Metrics/BlockLength: + Max: 55 semrel_files: *semrel_files_default apt-cacher: context: @@ -1257,6 +1261,10 @@ ssf: inspec_suites_matrix: [] platforms: [] platforms_matrix: [] + rubocop: + AllCops: + Exclude: + - 'ssf/files/**/*' use_tofs: true yamllint: ignore: @@ -1551,6 +1559,10 @@ ssf: - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, centos6] + rubocop: + Cops: + Metrics/BlockLength: + Max: 36 use_tofs: true semrel_files: *semrel_files_default timezone: From 5c2f134b5e592daa1b1b5c636140342713d98d08 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 9 Oct 2019 03:36:33 +0100 Subject: [PATCH 09/13] feat(travis): use conditional to provide one or two lint jobs * Main goal: one lint job * Alternative: split `rubocop` into a separate lint job (`allow_failures`) * Long-term: to be able to fully revert this commit when a single lint job can be use for all formulas --- ssf/defaults.yaml | 1 + ssf/files/default/.travis.yml | 47 +++++++++++++++++++++++++++++++---- ssf/formulas.yaml | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index d68106ec..ecdb9ce7 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -180,6 +180,7 @@ ssf_node_anchors: travis: addons: {} dist: bionic + use_single_job_for_linters: true use_cirrus_ci: false use_tofs: false yamllint: diff --git a/ssf/files/default/.travis.yml b/ssf/files/default/.travis.yml index e6723b8b..8e306f37 100644 --- a/ssf/files/default/.travis.yml +++ b/ssf/files/default/.travis.yml @@ -2,6 +2,31 @@ # vim: ft=yaml --- {%- from tplroot ~ "/libcimatrix.jinja" import format_ci_matrix with context %} + +{%- macro format_allow_failures(use_single_job_for_linters) %} +{%- filter indent(2) %} +{%- if not use_single_job_for_linters %} +allow_failures: + - env: Lint_rubocop +fast_finish: true +{%- endif %} +{%- endfilter %} +{%- endmacro %} + +{%- macro format_rubocop_linter() %} +{%- filter indent(8) %} +# Install and run `rubocop` +- gem install rubocop +- rubocop -d +{%- endfilter %} +{%- endmacro %} + +{%- set comment_linters = '# Run all of the linters in a single job' %} +{%- set name_linters = 'Lint: salt-lint, yamllint, rubocop & commitlint' %} +{%- if not travis.use_single_job_for_linters %} +{%- set comment_linters = comment_linters ~ ' (except `rubocop`)' %} +{%- set name_linters = 'Lint: salt-lint, yamllint & commitlint' %} +{%- endif %} ## Machine config dist: {{ travis.dist }} {%- if platforms and not use_cirrus_ci %} @@ -40,14 +65,15 @@ stages: - name: release if: branch = master AND type != pull_request jobs: + {{- format_allow_failures(travis.use_single_job_for_linters) }} include: ## Define the test stage that runs the linters (and testing matrix, if applicable) - # Run all of the linters in a single job + {{ comment_linters }} - language: node_js node_js: lts/* env: Lint - name: 'Lint: salt-lint, yamllint, rubocop & commitlint' + name: '{{ name_linters }}' before_install: skip script: # Install and run `salt-lint` @@ -58,13 +84,24 @@ jobs: # Need at least `v1.17.0` for the `yaml-files` setting - pip install --user yamllint>=1.17.0 - yamllint -s . - # Install and run `rubocop` - - gem install rubocop - - rubocop -d + {%- if travis.use_single_job_for_linters %} + {{- format_rubocop_linter() }} + {%- endif %} # Install and run `commitlint` - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D - 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 + - language: node_js + node_js: lts/* + env: Lint_rubocop + name: 'Lint: rubocop' + before_install: skip + script: + {{- format_rubocop_linter() }} + {%- endif %} {%- if platforms and not use_cirrus_ci %} diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index cb7908b4..a79ec1e3 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -145,6 +145,9 @@ ssf_node_anchors: - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + # yamllint disable-line rule:line-length + travis_do_not_use_single_job_for_linters: &travis_do_not_use_single_job_for_linters + use_single_job_for_linters: false yamllint: rules: rule: @@ -285,6 +288,7 @@ ssf: - '*': - .ng.server platforms_matrix: *platforms_matrix_osfamily_debian + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: <<: *semrel_files_default @@ -309,6 +313,7 @@ ssf: - . - .config platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters yamllint: rules: comments-indentation: @@ -340,6 +345,7 @@ ssf: - '*': - states/setup-certs-to-remove - . + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default chrony: context: @@ -351,6 +357,7 @@ ssf: inspec_yml: summary: >- Verify that the chrony formula is setup and configured correctly + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default collectd: @@ -376,6 +383,7 @@ ssf: - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default cron: context: @@ -391,6 +399,7 @@ ssf: pillars_from_files: - .sls: test/salt/pillar/cron.sls platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default deepsea: context: @@ -434,6 +443,7 @@ ssf: # - [opensuse/leap, 15 , 2017.7, 2, default] # # - [amazonlinux , 2 , 2017.7, 2, default] # # - [arch-base , latest, 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default dhcpd: @@ -460,6 +470,7 @@ ssf: # - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default exim: context: @@ -476,6 +487,7 @@ ssf: pillars_from_files: - .sls: test/salt/pillar/exim.sls platforms_matrix: *platforms_matrix_osfamily_debian + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default fail2ban: @@ -507,6 +519,7 @@ ssf: # - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default golang: context: @@ -528,6 +541,7 @@ ssf: - [fedora , 29 , 2018.3, 2, default] # - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default grafana: @@ -541,6 +555,7 @@ ssf: summary: >- Verify that the grafana formula is setup and configured correctly platforms_matrix: *platforms_matrix_osfamily_debian + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default influxdb: @@ -557,6 +572,7 @@ ssf: pillars_from_files: - .sls: test/salt/pillar/influxdb.sls platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default iptables: context: @@ -596,6 +612,7 @@ ssf: - [centos , 7 , 2018.3, 2, default] # - [centos , 6 , 2017.7, 2, default] - [opensuse/leap, 15 , 2017.7, 2, tables] + travis: *travis_do_not_use_single_job_for_linters yamllint: rules: key-duplicates: @@ -615,6 +632,7 @@ ssf: pre: - sudo modprobe ip_vs travis: + <<: *travis_do_not_use_single_job_for_linters addons: apt: packages: @@ -670,6 +688,7 @@ ssf: - [opensuse/leap, 15 , 2018.3, 2, default] - [fedora , 29 , 2017.7, 2, default] # - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default locale: @@ -706,6 +725,7 @@ ssf: - [fedora , 29 , 2018.3, 2, fedora] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default logrotate: context: @@ -728,6 +748,7 @@ ssf: - . - .jobs platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default lvm: context: @@ -765,6 +786,7 @@ ssf: # - [centos , 6 , 2017.7, 2, default] - [amazonlinux , 2 , 2017.7, 2, default] # # - [arch-base , latest, 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default mysql: context: @@ -787,6 +809,7 @@ ssf: - [ubuntu , 18.04, 2019.2, 3, default] - [debian , 9 , 2018.3, 2, default] - [debian , 8 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters yamllint: ignore: additional: @@ -815,6 +838,7 @@ ssf: - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default openssh: @@ -834,6 +858,7 @@ ssf: - '*': - .config platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default openvpn: @@ -862,6 +887,7 @@ ssf: # - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default php: context: @@ -939,6 +965,7 @@ ssf: - [fedora , 29 , 2018.3, 2, redhat] - [opensuse/leap, 15 , 2018.3, 2, suse] - [centos , 6 , 2017.7, 2, redhat] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default postfix: @@ -958,6 +985,7 @@ ssf: - '*': - . - .config + travis: *travis_do_not_use_single_job_for_linters yamllint: rules: key-duplicates: @@ -996,6 +1024,7 @@ ssf: - postgres/osmap.yaml - postgres/repo.yaml - test/salt/pillar/postgres.sls + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default prometheus: context: @@ -1008,6 +1037,7 @@ ssf: summary: >- Verify that the prometheus formula is setup and configured correctly platforms_matrix: *platforms_matrix_osfamily_debian + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default redis: @@ -1035,6 +1065,7 @@ ssf: - [debian , 9 , 2018.3, 2, default] - [ubuntu , 16.04, 2018.3, 2, default] - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default rkhunter: context: @@ -1084,6 +1115,7 @@ ssf: - [fedora , 29 , 2018.3, 2, redhat] - [opensuse/leap, 15 , 2018.3, 2, suse] - [centos , 6 , 2017.7, 2, redhat] + travis: *travis_do_not_use_single_job_for_linters use_cirrus_ci: true use_tofs: true semrel_files: *semrel_files_default @@ -1240,6 +1272,7 @@ ssf: # - [centos , 7 , 2019.2, 3, v201902-py3] - [fedora , 30 , 2019.2, 3, v201902-py3] - [opensuse/leap, 15 , 2019.2, 3, v201902-py3] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true yamllint: ignore: @@ -1314,6 +1347,7 @@ ssf: - debian - ubuntu - centos + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: docs/TOFS_pattern.rst: @@ -1353,6 +1387,7 @@ ssf: - [debian , 9 , 2019.2, 3, default] - [ubuntu , 18.04, 2019.2, 3, default] - [debian , 9 , 2018.3, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default sudoers: context: @@ -1376,6 +1411,7 @@ ssf: - '*': - . - .included + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default sysctl: context: @@ -1399,6 +1435,7 @@ ssf: - [fedora , 29 , 2018.3, 2, default] - [opensuse/leap, 15 , 2018.3, 2, default] # - [centos , 6 , 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default syslog-ng: context: @@ -1413,6 +1450,7 @@ ssf: provisioner: pillars_from_files: - .sls: test/salt/pillar/syslog_ng.sls + travis: *travis_do_not_use_single_job_for_linters use_cirrus_ci: true use_tofs: true semrel_files: @@ -1436,6 +1474,7 @@ ssf: inspec_yml: summary: >- Verify that the sysstat formula is setup and configured correctly + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default systemd: @@ -1486,6 +1525,7 @@ ssf: - [amazonlinux , 2 , 2017.7, 2] - [arch-base , latest, 2017.7, 2] platforms_matrix: *platforms_matrix_systemd_only + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default telegraf: @@ -1509,6 +1549,7 @@ ssf: - [fedora , 30 , 2019.2, 3, default] - [opensuse/leap, 15 , 2018.3, 2, default] - [ubuntu , 16.04, 2017.7, 2, default] + travis: *travis_do_not_use_single_job_for_linters use_tofs: true semrel_files: *semrel_files_default template: @@ -1578,6 +1619,7 @@ ssf: provisioner: pillars_from_files: - .sls: test/salt/pillar/timezone.sls + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default ufw: context: @@ -1602,6 +1644,7 @@ ssf: - [arch-base , latest, 2018.3, 2, default] - [ubuntu , 16.04, 2017.7, 2, default] travis: + <<: *travis_do_not_use_single_job_for_linters # Facing errors with `xenial` at time of adding # https://travis-ci.org/myii/ufw-formula/jobs/561205378#L906 # Persisting with `bionic` as well @@ -1623,6 +1666,7 @@ ssf: pillars_from_files: - .sls: test/salt/pillar/default.sls platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default vault: context: @@ -1696,6 +1740,7 @@ ssf: - [fedora , 29 , 2017.7, 2, ''] - [opensuse/leap, 15 , 2017.7, 2, ''] - [amazonlinux , 2 , 2017.7, 2, ''] + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default vim: context: @@ -1711,6 +1756,7 @@ ssf: pillars_from_files: - .sls: test/salt/pillar/vim.sls platforms_matrix: *platforms_matrix_without_arch + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default vsftpd: context: @@ -1725,4 +1771,5 @@ ssf: provisioner: pillars_from_files: - .sls: test/salt/pillar/vsftpd.sls + travis: *travis_do_not_use_single_job_for_linters semrel_files: *semrel_files_default From 9ec9b1e54ef24573bb263a2ab5ecccddb319435b Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 9 Oct 2019 19:29:33 +0100 Subject: [PATCH 10/13] feat(salt-lint): add per-formula overrides (via. TOFS) --- ssf/files/tofs_mysql-formula/.salt-lint | 16 ++++++++++++++++ ssf/files/tofs_openssh-formula/.salt-lint | 17 +++++++++++++++++ ssf/files/tofs_php-formula/.salt-lint | 15 +++++++++++++++ ssf/files/tofs_postfix-formula/.salt-lint | 16 ++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 ssf/files/tofs_mysql-formula/.salt-lint create mode 100644 ssf/files/tofs_openssh-formula/.salt-lint create mode 100644 ssf/files/tofs_php-formula/.salt-lint create mode 100644 ssf/files/tofs_postfix-formula/.salt-lint diff --git a/ssf/files/tofs_mysql-formula/.salt-lint b/ssf/files/tofs_mysql-formula/.salt-lint new file mode 100644 index 00000000..3f397d15 --- /dev/null +++ b/ssf/files/tofs_mysql-formula/.salt-lint @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: [] +skip_list: + # TODO: Formula-specific override to remove eventually + # A lot of attention is going to be needed to resolve the existing long lines + - 204 # Lines should be no longer that 160 chars + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 diff --git a/ssf/files/tofs_openssh-formula/.salt-lint b/ssf/files/tofs_openssh-formula/.salt-lint new file mode 100644 index 00000000..26216b6d --- /dev/null +++ b/ssf/files/tofs_openssh-formula/.salt-lint @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: + # This is actually a Python file + - _pillar/known_hosts_salt_ssh.sls + # Violation: [204] Lines should be no longer that 160 chars + - test/salt/pillar/default.sls +skip_list: + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 diff --git a/ssf/files/tofs_php-formula/.salt-lint b/ssf/files/tofs_php-formula/.salt-lint new file mode 100644 index 00000000..5bfd5472 --- /dev/null +++ b/ssf/files/tofs_php-formula/.salt-lint @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: + # Save time spent checking files by avoiding the deprecated `ng/` directory + - php/ng/ +skip_list: + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 diff --git a/ssf/files/tofs_postfix-formula/.salt-lint b/ssf/files/tofs_postfix-formula/.salt-lint new file mode 100644 index 00000000..0f14c361 --- /dev/null +++ b/ssf/files/tofs_postfix-formula/.salt-lint @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: + # https://github.com/saltstack-formulas/postfix-formula/issues/101 + # Violation: [203] Most files should not contain tabs + - postfix/files/mapping.j2 +skip_list: + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 From c3acbd103e62b4a5213e730f369c93084eda4140 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 10 Oct 2019 03:37:13 +0100 Subject: [PATCH 11/13] feat(ufw): add specific `pip3` customisations to `.travis.yml` * `ufw` is still stuck on `trusty` on Travis - This doesn't work with when `salt` is installed during the `salt-lint` installation process (issue with `tornado`) - Installing via. Python 3 works, albeit much slower --- ssf/files/default/.travis.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ssf/files/default/.travis.yml b/ssf/files/default/.travis.yml index 8e306f37..d69f47dc 100644 --- a/ssf/files/default/.travis.yml +++ b/ssf/files/default/.travis.yml @@ -76,13 +76,21 @@ jobs: name: '{{ name_linters }}' before_install: skip script: + {%- set pip_cmd = 'pip' %} + {%- set pkgs_for_salt_lint = 'salt-lint' %} + {%- if semrel_formula == 'ufw' %} + {%- set pip_cmd = 'pip3' %} + {%- set pkgs_for_salt_lint = pkgs_for_salt_lint ~ ' PyYAML==4.2b4' %} + # Need to use `pip3` due to using `{{ travis.dist }}` on Travis + - sudo apt-get install python3-pip python3-setuptools python3-wheel -y + {%- endif %} # Install and run `salt-lint` - - pip install --user salt-lint + - {{ pip_cmd }} install --user {{ pkgs_for_salt_lint }} - git ls-files | grep '\.sls$\|\.jinja$\|\.j2$\|\.tmpl$' | xargs -I {} salt-lint {} # Install and run `yamllint` # Need at least `v1.17.0` for the `yaml-files` setting - - pip install --user yamllint>=1.17.0 + - {{ pip_cmd }} install --user yamllint>=1.17.0 - yamllint -s . {%- if travis.use_single_job_for_linters %} {{- format_rubocop_linter() }} From 2dac9b0864831d5dc961293aaa2cccb5cc18cf98 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 9 Oct 2019 19:41:25 +0100 Subject: [PATCH 12/13] ci: merge travis matrix, add `salt-lint` & `rubocop` to `lint` job * Automated using https://github.com/myii/ssf-formula/pull/60 --- .rubocop.yml | 16 ++++++++++++++++ .salt-lint | 13 +++++++++++++ .travis.yml | 27 +++++++++++++++++++++------ .yamllint | 2 ++ Gemfile | 7 ++++--- 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .salt-lint diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..3069bb7e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# General overrides used across formulas in the org +Metrics/LineLength: + # Increase from default of `80` + # Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`) + Max: 88 + +# General settings across all cops in this formula +AllCops: + # Files to ignore completely + Exclude: + - ssf/files/**/* + +# Any offenses that should be fixed, e.g. collected via. `rubocop --auto-gen-config` diff --git a/.salt-lint b/.salt-lint new file mode 100644 index 00000000..a539954b --- /dev/null +++ b/.salt-lint @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: [] +skip_list: + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 diff --git a/.travis.yml b/.travis.yml index 9d8fa0c0..fdcbbdc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,47 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- +## Machine config dist: bionic + +## Stages and jobs matrix stages: - - lint + - test - name: release if: branch = master AND type != pull_request - jobs: include: - # Define the `lint` stage (runs `yamllint` and `commitlint`) - - stage: lint - language: node_js + ## Define the test stage that runs the linters (and testing matrix, if applicable) + + # Run all of the linters in a single job + - language: node_js node_js: lts/* + env: Lint + name: 'Lint: salt-lint, yamllint, rubocop & commitlint' before_install: skip script: + # Install and run `salt-lint` + - pip install --user salt-lint + - git ls-files | grep '\.sls$\|\.jinja$\|\.j2$\|\.tmpl$' + | xargs -I {} salt-lint {} # Install and run `yamllint` # Need at least `v1.17.0` for the `yaml-files` setting - pip install --user yamllint>=1.17.0 - yamllint -s . + # Install and run `rubocop` + - gem install rubocop + - rubocop -d # Install and run `commitlint` - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D - commitlint-travis - # Define the release stage that runs `semantic-release` + + ## Define the release stage that runs `semantic-release` - stage: release language: node_js node_js: lts/* + env: Release + name: 'Run semantic-release inc. file updates to AUTHORS, CHANGELOG & FORMULA' before_install: skip script: # Update `AUTHORS.md` diff --git a/.yamllint b/.yamllint index 845783cc..c37dc7f1 100644 --- a/.yamllint +++ b/.yamllint @@ -16,6 +16,7 @@ ignore: | .kitchen/ ssf/files/default/.cirrus.yml ssf/files/default/.rubocop.yml + ssf/files/default/.salt-lint ssf/files/default/.travis.yml ssf/files/default/.yamllint ssf/files/default/kitchen.yml @@ -25,6 +26,7 @@ yaml-files: # Default settings - '*.yaml' - '*.yml' + - .salt-lint - .yamllint # SaltStack Formulas additional settings - '*.example' diff --git a/Gemfile b/Gemfile index 3b36de32..5a232b61 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' gem 'kitchen-docker', '>= 2.9' -gem 'kitchen-salt', '>= 0.6.0' gem 'kitchen-inspec', '>= 1.1' - +gem 'kitchen-salt', '>= 0.6.0' From 5890b8ac08d6c65bc8b742aa7fa694c817c4d1a5 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 9 Oct 2019 20:14:24 +0100 Subject: [PATCH 13/13] fix(salt-lint): fix errors ```bash Examining ssf/libcimatrix.jinja of type state [204] Lines should be no longer that 160 chars ssf/libcimatrix.jinja:4 {%- macro format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=4, use_new_travis_format=False ) %} [203] Most files should not contain tabs ssf/libcimatrix.jinja:28 {#- | # | inc | exc | result | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:30 {#- | 1 | y | [] | TRUE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:31 {#- | 2 | y | n | TRUE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:32 {#- | 3 | y | y | TRUE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:33 {#- | 4 | [] | [] | TRUE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:34 {#- | 5 | [] | n | TRUE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:35 {#- | 6 | [] | y | FALSE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:36 {#- | 7 | n | [] | FALSE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:37 {#- | 8 | n | n | FALSE | #} [203] Most files should not contain tabs ssf/libcimatrix.jinja:38 {#- | 9 | n | y | FALSE | #} [206] Jinja variables should have spaces before and after: {{ var_name }} ssf/libcimatrix.jinja:70 {{ comment }}- {{instance_and_env }}{{ instance }} ... Examining ssf/map.jinja of type state [209] Jinja comment should have spaces before and after: {# comment #} ssf/map.jinja:10 {## Merge the formulas ##} ``` --- ssf/libcimatrix.jinja | 33 +++++++++++++++++++++------------ ssf/map.jinja | 2 +- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ssf/libcimatrix.jinja b/ssf/libcimatrix.jinja index 50c4fef2..1b8d7348 100644 --- a/ssf/libcimatrix.jinja +++ b/ssf/libcimatrix.jinja @@ -1,7 +1,16 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{%- macro format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=4, use_new_travis_format=False ) %} +{%- macro format_ci_matrix( + platforms, + inspec_suites_kitchen, + inspec_suites_matrix, + platforms_matrix, + platforms_matrix_commented_includes, + semrel_formula, + width=4, + use_new_travis_format=False + ) %} {%- filter indent(width) %} {#- Centralise duplication from here and `kitchen.yml` #} {%- set platform_and_suite_names_done = [] %} @@ -25,17 +34,17 @@ {%- do platform_and_suite_names_done.append(platform_and_suite_name) %} {#- Only continue depending on an appropriate combination of `includes` and `excludes`: #} {#- |---|-----|-----|--------| #} -{#- | # | inc | exc | result | #} +{#- | # | inc | exc | result | #} {#- |---|-----|-----|--------| #} -{#- | 1 | y | [] | TRUE | #} -{#- | 2 | y | n | TRUE | #} -{#- | 3 | y | y | TRUE | #} -{#- | 4 | [] | [] | TRUE | #} -{#- | 5 | [] | n | TRUE | #} -{#- | 6 | [] | y | FALSE | #} -{#- | 7 | n | [] | FALSE | #} -{#- | 8 | n | n | FALSE | #} -{#- | 9 | n | y | FALSE | #} +{#- | 1 | y | [] | TRUE | #} +{#- | 2 | y | n | TRUE | #} +{#- | 3 | y | y | TRUE | #} +{#- | 4 | [] | [] | TRUE | #} +{#- | 5 | [] | n | TRUE | #} +{#- | 6 | [] | y | FALSE | #} +{#- | 7 | n | [] | FALSE | #} +{#- | 8 | n | n | FALSE | #} +{#- | 9 | n | y | FALSE | #} {#- |---|-----|-----|--------| #} {%- if (platform in includes) or (not includes and platform not in excludes) %} {%- set include_instance = True %} @@ -67,7 +76,7 @@ salt_ver | replace('.', '-'), py_ver, ) %} -{{ comment }}- {{instance_and_env }}{{ instance }} +{{ comment }}- {{ instance_and_env }}{{ instance }} {%- endif %} {%- endif %} {%- endif %} diff --git a/ssf/map.jinja b/ssf/map.jinja index 318b2624..174204b0 100644 --- a/ssf/map.jinja +++ b/ssf/map.jinja @@ -7,7 +7,7 @@ {%- import_yaml tplroot ~ "/defaults.yaml" as defaults %} {%- import_yaml tplroot ~ "/formulas.yaml" as formulas %} -{## Merge the formulas ##} +{#- Merge the formulas #} {%- do salt['defaults.merge'](defaults, formulas) %} {#- Merge the ssf config (e.g. from pillar) #}