Skip to content

Commit

Permalink
feat(ssf): add TOFS overrides to ensure quoted-strings rule fulfilled
Browse files Browse the repository at this point in the history
* Completes #71
  • Loading branch information
myii committed Oct 15, 2019
1 parent 1024cc3 commit a021f56
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ ignore: |
ssf/files/default/.yamllint
ssf/files/default/kitchen.yml
ssf/files/default/inspec/inspec.yml
ssf/files/tofs_ssf-formula/.travis.yml
ssf/files/tofs_ssf-formula/.yamllint
yaml-files:
# Default settings
Expand Down
163 changes: 163 additions & 0 deletions ssf/files/tofs_ssf-formula/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-
# 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 %}
sudo: required
services:
- docker
{%- set travis_addons = travis.addons %}
{%- if travis_addons %}

# yamllint disable rule:indentation
addons:
{%- filter indent(2) %}
{{ travis_addons | yaml(False) }}
{%- endfilter %}
# yamllint enable rule:indentation
{%- endif %}

## 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}"
{%- 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:
{{- format_allow_failures(travis.use_single_job_for_linters) }}
include:
## Define the test stage that runs the linters (and testing matrix, if applicable)

{{ comment_linters }}
- language: 'node_js'
node_js: 'lts/*'
env: 'Lint'
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_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_cmd }} install --user yamllint>=1.17.0
- yamllint -s .
{%- 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 %}

## 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/*'
env: 'Release'
name: 'Run semantic-release inc. file updates to AUTHORS, CHANGELOG & FORMULA'
before_install: 'skip'
script:
# Update `AUTHORS.md`
- export MAINTAINER_TOKEN=${GH_TOKEN}
- go get github.com/myii/maintainer
- maintainer contributor

# Install all dependencies required for `semantic-release`
- npm install @semantic-release/changelog@3 -D
- npm install @semantic-release/exec@3 -D
- npm install @semantic-release/git@7 -D
deploy:
provider: 'script'
skip_cleanup: true
script:
# Run `semantic-release`
- npx semantic-release@15
96 changes: 96 additions & 0 deletions ssf/files/tofs_ssf-formula/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
{%- macro format_ignore(ignore_parent, width=4) %}
{%- filter indent(width) %}
{%- if ignore_parent.ignore is defined %}
ignore: |
{%- for file in ignore_parent.ignore %}
{{ file }}
{%- endfor %}
{%- endif %}
{%- endfilter %}
{%- endmacro %}
# Extend the `{{ yamllint.extends }}` configuration provided by `yamllint`
extends: '{{ yamllint.extends }}'

# Files to ignore completely
# 1. All YAML files under directory `node_modules/`, introduced during the Travis run
# 2. Any SLS files under directory `test/`, which are actually state files
# 3. Any YAML files under directory `.kitchen/`, introduced during local testing
{%- if semrel_formula == 'ssf' %}
# 4. All Jinja templates under `ssf/files/` (result in `yamllint` syntax errors)
# Not disabling via. `*.yml` since we may end up with non-Jinja YAML files here
{%- elif semrel_formula == 'mysql' %}
# 4. Any YAML files using Jinja (result in `yamllint` syntax errors)
{%- elif semrel_formula in ['postgres', 'salt'] %}
# 4. All YAML files heavily reliant on Jinja; these can be tackled in a subsequent PR
{%- endif %}
{%- set yl_ignores = {'ignore':
yamllint.ignore.default +
yamllint.ignore.additional_ssf +
yamllint.ignore.additional
} %}
{{- format_ignore(yl_ignores, width=0) }}

yaml-files:
{%- set yl_yf = yamllint.get('yaml-files') %}
{%- filter indent(2) %}
# Default settings
{{ yl_yf.default | yaml(False) }}
# SaltStack Formulas additional settings
{{ yl_yf.additional_ssf | yaml(False) }}
{%- if yl_yf.additional %}
# Formula-specific additional settings
{{ yl_yf.additional | yaml(False) }}
{%- endif %}
{%- endfilter %}

rules:
{%- if yamllint.rules.get('commas') %}
commas:
{%- set yl_cm = yamllint.rules.get('commas') %}
{%- if semrel_formula == 'ssf' %}
# Allow separation between commas to achieve tabular layout under `platforms`
{%- endif %}
{{- format_ignore(yl_cm) }}
{%- endif %}

{%- if yamllint.rules.get('comments-indentation') %}
comments-indentation:
{%- set yl_ci = yamllint.rules.get('comments-indentation') %}
{{- format_ignore(yl_ci) }}
{%- endif %}

{#- Don't need the `if` here since we're always providing a `empty-values` setting #}
empty-values:
{%- set yl_ev = yamllint.rules.get('empty-values') %}
{{- format_ignore(yl_ev) }}
forbid-in-block-mappings: {{ yl_ev.get('forbid-in-block-mappings') }}
forbid-in-flow-mappings: {{ yl_ev.get('forbid-in-flow-mappings') }}

{%- if yamllint.rules.get('key-duplicates') %}
key-duplicates:
{%- set yl_kd = yamllint.rules.get('key-duplicates') %}
{{- format_ignore(yl_kd) }}
{%- endif %}

{#- Don't need the `if` here since we're always providing a `line-length` setting #}
line-length:
{%- set yl_ll = yamllint.rules.get('line-length') %}
{{- format_ignore(yl_ll) }}
{%- if yl_ll.max == yl_ll.bugbear %}
# Increase from default of `{{ yl_ll.default }}`
# Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`)
{%- endif %}
max: {{ yl_ll.max }}

{#- Don't need the `if` here since we're always providing a `octal-values` setting #}
octal-values:
{%- set yl_ov = yamllint.rules.get('octal-values') %}
{{- format_ignore(yl_ov) }}
forbid-implicit-octal: {{ yl_ov.get('forbid-implicit-octal') }}
forbid-explicit-octal: {{ yl_ov.get('forbid-explicit-octal') }}
{#- TODO: When centralising, arrange this section as all of the others above #}
quoted-strings:
quote-type: 'single'
2 changes: 2 additions & 0 deletions ssf/formulas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,8 @@ ssf:
- ssf/files/default/.yamllint
- ssf/files/default/kitchen.yml
- ssf/files/default/inspec/inspec.yml
- ssf/files/tofs_ssf-formula/.travis.yml
- ssf/files/tofs_ssf-formula/.yamllint
rules:
commas:
ignore:
Expand Down

0 comments on commit a021f56

Please sign in to comment.