Skip to content

Commit

Permalink
feat(travis): update for new structure of merging the lint stage
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Oct 10, 2019
1 parent ac9b7a5 commit dbee3f7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 43 deletions.
93 changes: 52 additions & 41 deletions ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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/*
Expand Down
9 changes: 7 additions & 2 deletions ssf/libcimatrix.jinja
Original file line number Diff line number Diff line change
@@ -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 = [] %}
Expand Down Expand Up @@ -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 = '' %}
Expand All @@ -62,7 +67,7 @@
salt_ver | replace('.', '-'),
py_ver,
) %}
{{ comment }}- INSTANCE: {{ instance }}
{{ comment }}- {{instance_and_env }}{{ instance }}
{%- endif %}
{%- endif %}
{%- endif %}
Expand Down

0 comments on commit dbee3f7

Please sign in to comment.