Skip to content

Commit

Permalink
feat(travis): use conditional to provide one or two lint jobs
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
myii committed Oct 10, 2019
1 parent 212edf0 commit 5c2f134
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
1 change: 1 addition & 0 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 42 additions & 5 deletions ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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`
Expand All @@ -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 %}

Expand Down
Loading

0 comments on commit 5c2f134

Please sign in to comment.