Skip to content

Commit e1dbc4a

Browse files
Donienwidhalmt
andauthored
Fix/lint workflow 192 (#199)
Fix #192. This PR introduces a reusable workflow. This general workflow handles the job necessary to run both `ansible-lint` and `yamllint` on **either** all roles or one specific role. All roles are linted when: - linting rules are changed - the linting workflow is changed Specific roles are linted when: - a role specific workflow is triggered (linting as first job) - the `full_stack` workflow is triggered (linting as first job) The workflow for the specific role now uses a call to the general linting workflow, while providing it with its own role name. This approach does not completely remove linting from single workflows, but it makes those linting jobs much more readable and reduces redundant code, while also allowing for a bit more flexibility. --------- Co-authored-by: Thomas Widhalm <[email protected]>
1 parent 958efa4 commit e1dbc4a

File tree

8 files changed

+89
-155
lines changed

8 files changed

+89
-155
lines changed

.github/workflows/test_full_stack.yml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,10 @@ on:
1616
- cron: "0 4 * * *"
1717

1818
jobs:
19-
2019
lint_full:
21-
runs-on: ubuntu-latest
22-
steps:
23-
- name: Check out the codebase.
24-
uses: actions/checkout@v3
25-
26-
- name: Set up Python 3.
27-
uses: actions/setup-python@v4
28-
with:
29-
python-version: '3.x'
30-
31-
- name: Install test dependencies.
32-
run: |
33-
python3 -m pip install --upgrade pip
34-
python3 -m pip install -r requirements-test.txt
35-
36-
- name: Lint code.
37-
run: |
38-
yamllint .
39-
ansible-lint roles/
20+
uses: ./.github/workflows/test_linting.yml
21+
with:
22+
rolename: ''
4023

4124
molecule_full_stack_every_os:
4225
runs-on: ubuntu-latest

.github/workflows/test_linting.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
name: Test Linting
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
logLevel:
7+
description: 'Log level'
8+
required: true
9+
default: 'warning'
10+
type: choice
11+
options:
12+
- info
13+
- warning
14+
- debug
15+
workflow_call:
16+
inputs:
17+
rolename:
18+
required: true
19+
type: string
20+
push:
21+
branches:
22+
- 'feature/**'
23+
- 'fix/**'
24+
- '!doc/**'
25+
paths:
26+
- '.github/workflows/test_linting.yml'
27+
- '.config/ansible-lint.yml'
28+
- '.yamllint'
29+
pull_request:
30+
branches:
31+
- 'feature/**'
32+
- 'fix/**'
33+
- '!doc/**'
34+
paths:
35+
- '.github/workflows/test_linting.yml'
36+
- '.config/ansible-lint.yml'
37+
- '.yamllint'
38+
39+
jobs:
40+
lint:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Check out the codebase.
44+
uses: actions/checkout@v3
45+
46+
- name: Set up Python 3.
47+
uses: actions/setup-python@v4
48+
with:
49+
python-version: '3.x'
50+
51+
- name: Install test dependencies.
52+
run: |
53+
python3 -m pip install --upgrade pip
54+
python3 -m pip install -r requirements-test.txt
55+
56+
- name: Lint code (yamllint).
57+
run: |
58+
yamllint .
59+
if: ${{ inputs.rolename == '' }}
60+
61+
- name: Lint Role (yamllint).
62+
run: |
63+
ansible-lint roles/${{ inputs.rolename }}
64+
if: ${{ inputs.rolename != '' }}
65+
66+
- name: Lint Role (ansible-lint).
67+
run: |
68+
ansible-lint roles/${{ inputs.rolename }}

.github/workflows/test_role_beats.yml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ on:
2121
- 'roles/beats/**'
2222
- '.github/workflows/test_role_beats.yml'
2323
- 'molecule/beats_**'
24-
- '.config/ansible-lint.yml'
25-
- '.yamllint'
2624
pull_request:
2725
branches:
2826
- 'feature/**'
@@ -32,30 +30,12 @@ on:
3230
- 'roles/beats/**'
3331
- '.github/workflows/test_role_beats.yml'
3432
- 'molecule/beats_**'
35-
- '.config/ansible-lint.yml'
36-
- '.yamllint'
3733

3834
jobs:
3935
lint_beats:
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Check out the codebase.
43-
uses: actions/checkout@v3
44-
45-
- name: Set up Python 3.
46-
uses: actions/setup-python@v4
47-
with:
48-
python-version: '3.x'
49-
50-
- name: Install test dependencies.
51-
run: |
52-
python3 -m pip install --upgrade pip
53-
python3 -m pip install -r requirements-test.txt
54-
55-
- name: Lint code.
56-
run: |
57-
yamllint roles/beats/
58-
ansible-lint roles/beats/
36+
uses: ./.github/workflows/test_linting.yml
37+
with:
38+
rolename: beats
5939

6040
molecule_beats:
6141
needs: lint_beats

.github/workflows/test_role_elasticsearch.yml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ on:
2121
- 'roles/elasticsearch/**'
2222
- '.github/workflows/test_role_elasticsearch.yml'
2323
- 'molecule/elasticsearch_**'
24-
- '.config/ansible-lint.yml'
25-
- '.yamllint'
2624
pull_request:
2725
branches:
2826
- 'feature/**'
@@ -32,30 +30,12 @@ on:
3230
- 'roles/elasticsearch/**'
3331
- '.github/workflows/test_role_elasticsearch.yml'
3432
- 'molecule/elasticsearch_**'
35-
- '.config/ansible-lint.yml'
36-
- '.yamllint'
3733

3834
jobs:
3935
lint_elasticsearch:
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Check out the codebase.
43-
uses: actions/checkout@v3
44-
45-
- name: Set up Python 3.
46-
uses: actions/setup-python@v4
47-
with:
48-
python-version: '3.x'
49-
50-
- name: Install test dependencies.
51-
run: |
52-
python3 -m pip install --upgrade pip
53-
python3 -m pip install -r requirements-test.txt
54-
55-
- name: Lint code.
56-
run: |
57-
yamllint roles/elasticsearch/
58-
ansible-lint roles/elasticsearch/
36+
uses: ./.github/workflows/test_linting.yml
37+
with:
38+
rolename: elasticsearch
5939

6040
molecule_elasticsearch:
6141
needs: lint_elasticsearch

.github/workflows/test_role_kibana.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ on:
2121
- 'roles/kibana/**'
2222
- '.github/workflows/test_role_kibana.yml'
2323
- 'molecule/kibana_**'
24-
- '.config/ansible-lint.yml'
25-
- '.yamllint'
2624
pull_request:
2725
branches:
2826
- 'feature/**'
@@ -32,30 +30,13 @@ on:
3230
- 'roles/kibana/**'
3331
- '.github/workflows/test_role_kibana.yml'
3432
- 'molecule/kibana_**'
35-
- '.config/ansible-lint.yml'
36-
- '.yamllint'
3733

3834
jobs:
3935
lint_kibana:
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Check out the codebase.
43-
uses: actions/checkout@v3
44-
45-
- name: Set up Python 3.
46-
uses: actions/setup-python@v4
47-
with:
48-
python-version: '3.x'
36+
uses: ./.github/workflows/test_linting.yml
37+
with:
38+
rolename: kibana
4939

50-
- name: Install test dependencies.
51-
run: |
52-
python3 -m pip install --upgrade pip
53-
python3 -m pip install -r requirements-test.txt
54-
55-
- name: Lint code.
56-
run: |
57-
yamllint roles/kibana/
58-
ansible-lint roles/kibana/
5940

6041
molecule_kibana:
6142
needs: lint_kibana

.github/workflows/test_role_logstash.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ on:
2121
- 'roles/logstash/**'
2222
- '.github/workflows/test_role_logstash.yml'
2323
- 'molecule/logstash_**'
24-
- '.config/ansible-lint.yml'
25-
- '.yamllint'
2624
pull_request:
2725
branches:
2826
- 'feature/**'
@@ -32,30 +30,13 @@ on:
3230
- 'roles/logstash/**'
3331
- '.github/workflows/test_role_logstash.yml'
3432
- 'molecule/logstash_**'
35-
- '.config/ansible-lint.yml'
36-
- '.yamllint'
3733

3834
jobs:
3935
lint_logstash:
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Check out the codebase.
43-
uses: actions/checkout@v3
44-
45-
- name: Set up Python 3.
46-
uses: actions/setup-python@v4
47-
with:
48-
python-version: '3.x'
36+
uses: ./.github/workflows/test_linting.yml
37+
with:
38+
rolename: logstash
4939

50-
- name: Install test dependencies.
51-
run: |
52-
python3 -m pip install --upgrade pip
53-
python3 -m pip install -r requirements-test.txt
54-
55-
- name: Lint code.
56-
run: |
57-
yamllint roles/logstash/
58-
ansible-lint roles/logstash/
5940

6041
molecule_logstash_extended:
6142
runs-on: ubuntu-latest

.github/workflows/test_role_repos.yml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ on:
2020
- 'roles/repos/**'
2121
- '.github/workflows/test_role_repos.yml'
2222
- 'molecule/repos_**'
23-
- '.config/ansible-lint.yml'
24-
- '.yamllint'
2523
pull_request:
2624
branches:
2725
- 'feature/**'
@@ -31,30 +29,12 @@ on:
3129
- 'roles/repos/**'
3230
- '.github/workflows/test_role_repos.yml'
3331
- 'molecule/repos_**'
34-
- '.config/ansible-lint.yml'
35-
- '.yamllint'
3632

3733
jobs:
3834
lint_repos:
39-
runs-on: ubuntu-latest
40-
steps:
41-
- name: Check out the codebase.
42-
uses: actions/checkout@v3
43-
44-
- name: Set up Python 3.
45-
uses: actions/setup-python@v4
46-
with:
47-
python-version: '3.x'
48-
49-
- name: Install test dependencies.
50-
run: |
51-
python3 -m pip install --upgrade pip
52-
python3 -m pip install -r requirements-test.txt
53-
54-
- name: Lint code.
55-
run: |
56-
yamllint roles/repos/
57-
ansible-lint roles/repos/
35+
uses: ./.github/workflows/test_linting.yml
36+
with:
37+
rolename: repos
5838

5939
molecule_repos:
6040
needs: lint_repos

.github/workflows/test_roles_pr.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ on:
2121
- 'roles/**'
2222
- '.github/workflows/test_roles_pr.yml'
2323
- 'molecule/elasticstack_default/**'
24-
- '.config/ansible-lint.yml'
25-
- '.yamllint'
2624
push:
2725
branches:
2826
- 'feature/**'
@@ -32,30 +30,13 @@ on:
3230
- 'roles/**'
3331
- '.github/workflows/test_roles_pr.yml'
3432
- 'molecule/elasticstack_default/**'
35-
- '.config/ansible-lint.yml'
36-
- '.yamllint'
3733

3834
jobs:
3935
lint_full:
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Check out the codebase.
43-
uses: actions/checkout@v3
44-
45-
- name: Set up Python 3.
46-
uses: actions/setup-python@v4
47-
with:
48-
python-version: '3.x'
36+
uses: ./.github/workflows/test_linting.yml
37+
with:
38+
rolename: ''
4939

50-
- name: Install test dependencies.
51-
run: |
52-
python3 -m pip install --upgrade pip
53-
python3 -m pip install -r requirements-test.txt
54-
55-
- name: Lint code.
56-
run: |
57-
yamllint .
58-
ansible-lint roles/
5940
molecule_full_stack:
6041
runs-on: ubuntu-latest
6142
needs: lint_full

0 commit comments

Comments
 (0)