Skip to content

Commit

Permalink
feat(yamllint): configure for all semrel_formulas
Browse files Browse the repository at this point in the history
* Prepare this alongside submitting all of the PRs
* Main `template-formula` PR with links to all of the other PRs:
  - saltstack-formulas/template-formula#159
  • Loading branch information
myii committed Aug 17, 2019
1 parent ac88c9e commit bfad41d
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 16 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
# vim: ft=yaml
---
stages:
- commitlint
- lint
- name: release
if: branch = master AND type != pull_request

jobs:
include:
# Define the `commitlint` stage (runs `yamlllint` as well)
- stage: commitlint
# Define the `lint` stage (runs `yamllint` and `commitlint`)
- stage: lint
language: node_js
node_js: lts/*
before_install: skip
script:
# Install and run `yamllint`
- pip install --user yamllint
- yamllint . .yamllint pillar.example
# yamllint disable-line rule:line-length
- yamllint -s . .yamllint pillar.example
# Install and run `commitlint`
- npm install @commitlint/config-conventional -D
- npm install @commitlint/travis-cli -D
Expand Down
6 changes: 4 additions & 2 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# Extend the `default` configuration
# Extend the `default` configuration provided by `yamllint`
extends: default

# Files to ignore completely
# 1. All YAML files under directory `node_modules/`, introduced during the Travis run
# 2. All Jinja templates under `ssf/files/`
# 2. 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
ignore: |
node_modules/
ssf/files/default/.cirrus.yml
ssf/files/default/.travis.yml
ssf/files/default/.yamllint
ssf/files/default/kitchen.yml
ssf/files/default/inspec/inspec.yml
Expand Down
1 change: 1 addition & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ ssf:
- .gitignore
- .cirrus.yml
- .travis.yml
- .yamllint
- commitlint.config.js
- Gemfile
- kitchen.yml
Expand Down
1 change: 1 addition & 0 deletions ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ prepare-git-branch-for-{{ formula }}:
suite: {{ suite | yaml }}
travis: {{ context.travis | yaml }}
use_cirrus_ci: {{ use_cirrus_ci }}
yamllint: {{ context.yamllint | yaml }}
{%- endif %}
{%- if ssf.git.states.prepare.active %}
- require:
Expand Down
51 changes: 48 additions & 3 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ssf_node_anchors:
# release phase via. `pre-commit_semantic-release.sh`
# An alternative method could be to use:
# `git describe --abbrev=0 --tags`
title: 'chore: use `semantic-release` cross-formula standard structure'
body: '* Automated using `ssf-formula` (v0.4.1)'
title: 'feat(yamllint): include for this repo and apply rules throughout'
body: '* Semi-automated using `ssf-formula` (v0.5.0)'
github:
owner: saltstack-formulas
repo: ''
Expand Down Expand Up @@ -112,6 +112,43 @@ ssf_node_anchors:
dist: xenial
use_cirrus_ci: false
use_tofs: false
yamllint:
check_files:
default:
- .
- .yamllint
- pillar.example
additional: []
extends: default
ignore: []
rules:
# yamllint disable rule:comments-indentation
# Commenting out all of the rules that haven't been implemented yet
# braces: {}
# brackets: {}
# colons: {}
commas: {}
# comments: {}
comments-indentation: {}
# document-end: {}
# document-start: {}
# empty-lines: {}
# empty-values: {}
# hyphens: {}
# indentation: {}
key-duplicates: {}
# key-ordering: {}
line-length:
bugbear: 88
default: 80
max: 88
# new-line-at-end-of-file: {}
# new-lines: {}
# octal-values: {}
# quoted-strings: {}
# trailing-spaces: {}
# truthy: {}
# yamllint enable rule:comments-indentation

ssf:
active:
Expand Down Expand Up @@ -248,7 +285,15 @@ ssf:
syslog-ng: *formula_default
sysstat: *formula_default
systemd: *formula_default
template: *formula_default
template:
<<: *formula_default
context:
<<: *context_default
inspec_suites_kitchen:
<<: *isk_default
1:
<<: *isk_suite_default
name: centos6
ufw: *formula_default
users: *formula_default
vault:
Expand Down
29 changes: 25 additions & 4 deletions ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stages:
{%- if platforms and not use_cirrus_ci %}
- test
{%- endif %}
- commitlint
- lint
- name: release
if: branch = master AND type != pull_request
{%- if platforms and not use_cirrus_ci %}
Expand All @@ -21,10 +21,12 @@ services:
{%- 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 %}

# Make sure the instances listed below match up with
Expand Down Expand Up @@ -56,18 +58,37 @@ script:
{%- endfor %}
{%- endif %}

{%- set yamllint_files = yamllint.check_files.default + yamllint.check_files.additional %}
{#- Don't need to do this in index order but maintaining consistency with `kitchen.yml` #}
{%- for index in range(0, inspec_suites_kitchen | length) %}
{%- set suite = inspec_suites_kitchen[index] %}
{%- set pillars_from_files = suite.provisioner.pillars_from_files %}
{%- for pff in pillars_from_files %}
{%- for k, v in pff.items() %}
{%- if v not in yamllint_files %}
{%- do yamllint_files.append(v) %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endfor %}

jobs:
include:
# Define the commitlint stage
- stage: commitlint
# Define the `lint` stage (runs `yamllint` and `commitlint`)
- stage: lint
language: node_js
node_js: lts/*
before_install: skip
script:
# Install and run `yamllint`
- pip install --user yamllint
# yamllint disable-line rule:line-length
- yamllint -s {{ yamllint_files | join(' ') }}
# 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/*
Expand Down
62 changes: 62 additions & 0 deletions ssf/files/default/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
{%- macro format_ignore(ignore_parent, first_ignores=[], width=4) %}
{%- filter indent(width) %}
{%- if ignore_parent.ignore is defined %}
ignore: |
{%- for first_ignore in first_ignores %}
{{ first_ignore }}
{%- endfor %}
{%- 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
{%- if semrel_formula == 'ssf' %}
# 2. 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' %}
# 2. Any YAML files using Jinja (result in `yamllint` syntax errors)
{%- elif semrel_formula == 'postgres' %}
# 2. All YAML files heavily reliant on Jinja; these can be tackled in a subsequent PR
{%- endif %}
{{- format_ignore(yamllint, first_ignores=['node_modules/'], width=0) }}

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 %}

{%- 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 yamllint.rules.get('line-length').max == yamllint.rules.get('line-length').bugbear %}
# Increase from default of `{{ yamllint.rules.get('line-length').default }}`
# Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`)
{%- endif %}
max: {{ yamllint.rules.get('line-length').max }}
7 changes: 6 additions & 1 deletion ssf/files/default/inspec/inspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ name: {{ suite.name }}
title: {{ semrel_formula }} formula
maintainer: SaltStack Formulas
license: Apache-2.0
summary: {{ suite.inspec_yml.summary }}
{%- set summary_heading = 'summary: ' %}
{%- set summary_chars = summary_heading | length + suite.inspec_yml.summary | length %}
{%- if summary_chars > yamllint.rules.get('line-length').max %}
# yamllint disable-line rule:line-length
{%- endif %}
{{ summary_heading }}{{ suite.inspec_yml.summary }}
supports:
{%- for platform in suite.inspec_yml.supports %}
- platform-name: {{ platform }}
Expand Down
3 changes: 2 additions & 1 deletion ssf/files/default/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ platforms:
platform: rhel
run_command: /sbin/init
provision_command:
- curl -L https://bootstrap.saltstack.com | sh -s -- -X # install latest stable Salt
# install latest stable Salt
- curl -L https://bootstrap.saltstack.com | sh -s -- -X
{%- endif %}
{#- Centralise duplication from here and `libcimatrix.jinja` #}
{%- set prev_comment = '' %}
Expand Down
Loading

0 comments on commit bfad41d

Please sign in to comment.