From d3b93f81b14bc2e83b56aa589739147a269c0c30 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 7 Oct 2019 21:31:57 +0100 Subject: [PATCH 1/7] refactor(travis): merge `lint` stage into the `test` stage * Runs the lint concurrently, for quicker feedback and time savings * Some of the restructuring inspired from: - https://github.com/travis-ci/travis-yml/blob/5ad02354de7d4fc3e9b9f71c44902058402d45ef/spec/fixtures/configs/co/coolo:open-build-service.yml --- .travis.yml | 116 +++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5beef8ad..183ea4a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,73 +1,33 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- +## Machine config dist: bionic -stages: - - test - - lint - - name: release - if: branch = master AND type != pull_request - sudo: required -cache: bundler -language: ruby - services: - docker -# Make sure the instances listed below match up with -# the `platforms` defined in `kitchen.yml` -# 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 -env: - matrix: - - INSTANCE: default-debian-10-develop-py3 - # - INSTANCE: default-ubuntu-1804-develop-py3 - # - INSTANCE: default-centos-7-develop-py3 - # - INSTANCE: default-fedora-30-develop-py3 - # - INSTANCE: default-opensuse-leap-15-develop-py3 - # - INSTANCE: default-amazonlinux-2-develop-py2 - # - INSTANCE: default-arch-base-latest-develop-py2 - # - INSTANCE: default-debian-9-2019-2-py3 - - INSTANCE: default-ubuntu-1804-2019-2-py3 - # - INSTANCE: default-centos-7-2019-2-py3 - # - INSTANCE: default-fedora-30-2019-2-py3 - # - INSTANCE: default-opensuse-leap-15-2019-2-py3 - - INSTANCE: default-amazonlinux-2-2019-2-py2 - - INSTANCE: default-arch-base-latest-2019-2-py2 - # - INSTANCE: default-debian-9-2018-3-py2 - # - INSTANCE: default-ubuntu-1604-2018-3-py2 - # - INSTANCE: default-centos-7-2018-3-py2 - - INSTANCE: default-fedora-29-2018-3-py2 - - INSTANCE: default-opensuse-leap-15-2018-3-py2 - # - INSTANCE: default-amazonlinux-2-2018-3-py2 - # - INSTANCE: default-arch-base-latest-2018-3-py2 - # - INSTANCE: default-debian-8-2017-7-py2 - # - INSTANCE: default-ubuntu-1604-2017-7-py2 - - INSTANCE: centos6-centos-6-2017-7-py2 - # - INSTANCE: default-fedora-29-2017-7-py2 - # - INSTANCE: default-opensuse-leap-15-2017-7-py2 - # - INSTANCE: default-amazonlinux-2-2017-7-py2 - # - INSTANCE: default-arch-base-latest-2017-7-py2 +## Language and cache config +language: ruby +cache: bundler +## Script to run for the test stage script: - bin/kitchen verify ${INSTANCE} +## 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: yamllint & commitlint' before_install: skip script: # Install and run `yamllint` @@ -78,7 +38,51 @@ jobs: - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D - commitlint-travis - # Define the release stage that runs `semantic-release` + + ## 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` + # 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 + - env: INSTANCE=default-debian-10-develop-py3 + # - env: INSTANCE=default-ubuntu-1804-develop-py3 + # - env: INSTANCE=default-centos-7-develop-py3 + # - env: INSTANCE=default-fedora-30-develop-py3 + # - env: INSTANCE=default-opensuse-leap-15-develop-py3 + # - env: INSTANCE=default-amazonlinux-2-develop-py2 + # - env: INSTANCE=default-arch-base-latest-develop-py2 + # - env: INSTANCE=default-debian-9-2019-2-py3 + - env: INSTANCE=default-ubuntu-1804-2019-2-py3 + # - env: INSTANCE=default-centos-7-2019-2-py3 + # - env: INSTANCE=default-fedora-30-2019-2-py3 + # - env: INSTANCE=default-opensuse-leap-15-2019-2-py3 + - env: INSTANCE=default-amazonlinux-2-2019-2-py2 + - env: INSTANCE=default-arch-base-latest-2019-2-py2 + # - env: INSTANCE=default-debian-9-2018-3-py2 + # - env: INSTANCE=default-ubuntu-1604-2018-3-py2 + # - env: INSTANCE=default-centos-7-2018-3-py2 + - env: INSTANCE=default-fedora-29-2018-3-py2 + - env: INSTANCE=default-opensuse-leap-15-2018-3-py2 + # - env: INSTANCE=default-amazonlinux-2-2018-3-py2 + # - env: INSTANCE=default-arch-base-latest-2018-3-py2 + # - env: INSTANCE=default-debian-8-2017-7-py2 + # - env: INSTANCE=default-ubuntu-1604-2017-7-py2 + - env: INSTANCE=centos6-centos-6-2017-7-py2 + # - env: INSTANCE=default-fedora-29-2017-7-py2 + # - env: INSTANCE=default-opensuse-leap-15-2017-7-py2 + # - env: INSTANCE=default-amazonlinux-2-2017-7-py2 + # - env: INSTANCE=default-arch-base-latest-2017-7-py2 + + ## Define the release stage that runs `semantic-release` - stage: release language: node_js node_js: lts/* From 2df46466f6ed5900c0a70d877cd7afc7d484cf13 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 7 Oct 2019 23:02:21 +0100 Subject: [PATCH 2/7] ci(travis): run `salt-lint` during the `Lint` job * Automated using https://github.com/myii/ssf-formula/pull/60 * Initially mentioned on Slack (@dafyddj): - https://freenode.logbot.info/saltstack-formulas/20191004#c2723464 * Basis for the `git ls-files` invocation (@sblaisot): - https://freenode.logbot.info/saltstack-formulas/20191004#c2724272 --- .salt-lint | 13 +++++++++++++ .travis.yml | 6 +++++- .yamllint | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .salt-lint 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 183ea4a5..8b985f5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,9 +27,13 @@ jobs: # Run all of the linters in a single job - language: node_js node_js: lts/* - env: 'Lint: yamllint & commitlint' + env: 'Lint: salt-lint, yamllint & 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 diff --git a/.yamllint b/.yamllint index c16f39ba..740beca0 100644 --- a/.yamllint +++ b/.yamllint @@ -17,6 +17,7 @@ yaml-files: # Default settings - '*.yaml' - '*.yml' + - .salt-lint - .yamllint # SaltStack Formulas additional settings - '*.example' From 8d8c7666602742028c0b2999d683d83d30bb97d9 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 7 Oct 2019 23:18:11 +0100 Subject: [PATCH 3/7] ci(travis): run `rubocop` during the `Lint` job * Automated using https://github.com/myii/ssf-formula/pull/60 --- .rubocop.yml | 10 ++++++++++ .travis.yml | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..bdae9aa9 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,10 @@ +# -*- 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 + +# Any offenses that should be fixed, e.g. collected via. `rubocop --auto-gen-config` diff --git a/.travis.yml b/.travis.yml index 8b985f5c..78268e13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ jobs: # Run all of the linters in a single job - language: node_js node_js: lts/* - env: 'Lint: salt-lint, yamllint & commitlint' + env: 'Lint: salt-lint, yamllint, rubocop & commitlint' before_install: skip script: # Install and run `salt-lint` @@ -38,6 +38,9 @@ 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 # Install and run `commitlint` - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D From 484ce2459dd0a598954fc0ee2656685f134f757d Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 00:26:29 +0100 Subject: [PATCH 4/7] fix(rubocop): add fixes using `rubocop --safe-auto-correct` --- Gemfile | 7 ++++--- bin/kitchen | 14 +++++++------- test/integration/default/controls/config_spec.rb | 2 ++ test/integration/default/controls/packages_spec.rb | 6 +++--- test/integration/default/controls/services_spec.rb | 6 +++--- .../default/controls/subcomponent_config_spec.rb | 2 ++ 6 files changed, 21 insertions(+), 16 deletions(-) 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' diff --git a/bin/kitchen b/bin/kitchen index 1cd44f3a..621b13ac 100755 --- a/bin/kitchen +++ b/bin/kitchen @@ -8,11 +8,11 @@ # 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/ @@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this 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') diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb index 9c8a8ebb..2abbc708 100644 --- a/test/integration/default/controls/config_spec.rb +++ b/test/integration/default/controls/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + control 'template configuration' do title 'should match desired lines' diff --git a/test/integration/default/controls/packages_spec.rb b/test/integration/default/controls/packages_spec.rb index 1155548e..4daa41b5 100644 --- a/test/integration/default/controls/packages_spec.rb +++ b/test/integration/default/controls/packages_spec.rb @@ -1,8 +1,8 @@ +# frozen_string_literal: true + # Overide by OS package_name = 'bash' -if os[:name] == 'centos' and os[:release].start_with?('6') - package_name = 'cronie' -end +package_name = 'cronie' if (os[:name] == 'centos') && os[:release].start_with?('6') control 'template package' do title 'should be installed' diff --git a/test/integration/default/controls/services_spec.rb b/test/integration/default/controls/services_spec.rb index 960e7047..c00f75f0 100644 --- a/test/integration/default/controls/services_spec.rb +++ b/test/integration/default/controls/services_spec.rb @@ -1,8 +1,8 @@ +# frozen_string_literal: true + # Overide by OS service_name = 'systemd-udevd' -if os[:name] == 'centos' and os[:release].start_with?('6') - service_name = 'crond' -end +service_name = 'crond' if (os[:name] == 'centos') && os[:release].start_with?('6') control 'template service' do impact 0.5 diff --git a/test/integration/default/controls/subcomponent_config_spec.rb b/test/integration/default/controls/subcomponent_config_spec.rb index 8f3a5cfa..fff76870 100644 --- a/test/integration/default/controls/subcomponent_config_spec.rb +++ b/test/integration/default/controls/subcomponent_config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + control 'template subcomponent configuration' do title 'should match desired lines' From 9566b6fb6317132345a9a2f2320201d2f30128ac Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sat, 5 Oct 2019 16:15:29 +0100 Subject: [PATCH 5/7] fix(rubocop): fix remaining errors manually --- .rubocop.yml | 2 ++ bin/kitchen | 7 +++++-- test/integration/default/controls/config_spec.rb | 16 ++++++++++++++-- .../default/controls/subcomponent_config_spec.rb | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index bdae9aa9..a511077c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,3 +8,5 @@ Metrics/LineLength: Max: 88 # Any offenses that should be fixed, e.g. collected via. `rubocop --auto-gen-config` +Metrics/BlockLength: + Max: 36 diff --git a/bin/kitchen b/bin/kitchen index 621b13ac..dcfdb4ca 100755 --- a/bin/kitchen +++ b/bin/kitchen @@ -18,8 +18,11 @@ 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 diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb index 2abbc708..a6cd92d7 100644 --- a/test/integration/default/controls/config_spec.rb +++ b/test/integration/default/controls/config_spec.rb @@ -8,7 +8,11 @@ it { should be_owned_by 'root' } it { should be_grouped_into 'root' } its('mode') { should cmp '0644' } - its('content') { should include 'This is another example file from SaltStack template-formula.' } + its('content') do + should include( + 'This is another example file from SaltStack template-formula.' + ) + end its('content') { should include '"added_in_pillar": "pillar_value"' } its('content') { should include '"added_in_defaults": "defaults_value"' } its('content') { should include '"added_in_lookup": "lookup_value"' } @@ -16,7 +20,15 @@ its('content') { should include '"lookup": {"added_in_lookup": "lookup_value",' } its('content') { should include '"pkg": {"name": "' } its('content') { should include '"service": {"name": "' } - its('content') { should include '"tofs": {"files_switch": ["any/path/can/be/used/here", "id", "roles", "osfinger", "os", "os_family"], "source_files": {"template-config-file-file-managed": ["example.tmpl.jinja"], "template-subcomponent-config-file-file-managed": ["subcomponent-example.tmpl.jinja"]}' } + its('content') do + should include( + '"tofs": {"files_switch": ["any/path/can/be/used/here", "id", '\ + '"roles", "osfinger", "os", "os_family"], "source_files": '\ + '{"template-config-file-file-managed": ["example.tmpl.jinja"], '\ + '"template-subcomponent-config-file-file-managed": '\ + '["subcomponent-example.tmpl.jinja"]}' + ) + end its('content') { should include '"arch": "amd64"' } its('content') { should include '"winner": "pillar"}' } its('content') { should include 'winner of the merge: pillar' } diff --git a/test/integration/default/controls/subcomponent_config_spec.rb b/test/integration/default/controls/subcomponent_config_spec.rb index fff76870..d880cfc8 100644 --- a/test/integration/default/controls/subcomponent_config_spec.rb +++ b/test/integration/default/controls/subcomponent_config_spec.rb @@ -8,7 +8,18 @@ it { should be_owned_by 'root' } it { should be_grouped_into 'root' } its('mode') { should cmp '0644' } - its('content') { should include '# File managed by Salt at .' } - its('content') { should include 'This is another subcomponent example file from SaltStack template-formula.' } + its('content') do + should include( + '# File managed by Salt at '\ + '.' + ) + end + its('content') do + should include( + 'This is another subcomponent example file from SaltStack '\ + 'template-formula.' + ) + end end end From 00d56a4dfcacb6836790e024a024946d23efcf21 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 16:43:30 +0100 Subject: [PATCH 6/7] ci(travis): quote `${INSTANCE}` when running `kitchen verify` * https://github.com/saltstack-formulas/template-formula/pull/175#discussion_r332525964 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 78268e13..9a3c5748 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ cache: bundler ## Script to run for the test stage script: - - bin/kitchen verify ${INSTANCE} + - bin/kitchen verify "${INSTANCE}" ## Stages and jobs matrix stages: From 5f773d1a5bad9e81521bfd5546e6cc3776c8d451 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 8 Oct 2019 20:08:19 +0100 Subject: [PATCH 7/7] ci(travis): use `env` and `name` for improved display in Travis * https://github.com/saltstack-formulas/template-formula/pull/175#discussion_r332613933 --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9a3c5748..abe4daf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,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` @@ -93,6 +94,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`