Skip to content

Commit

Permalink
feat(role): add Ansible linting to build workflow
Browse files Browse the repository at this point in the history
* Make each job dependent on the previous one.
* Use specific Ubuntu version, the same as in development.
* Install Python packages from requirements.txt, so that the build
   environment matches development.
* Remove unnecessary (?) working-directory variable.
* Disable YAML lint rule for "on" keyword of GitHub Actions.

Issues: #3
  • Loading branch information
geoffreyvanwyk committed Jan 8, 2024
1 parent 705a6f4 commit 044193e
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions {{ cookiecutter.role_name }}/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,57 @@
##

name: Build
"on":
pull_request:
on: # yamllint disable-line rule:truty
pull_request: {}
push:
branches:
- master

defaults:
run:
working-directory: "{{ cookiecutter.namespace }}.{{ cookiecutter.role_name }}"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
yamllint:
name: YAML Lint
runs-on: ubuntu-22.04

steps:
- name: Check out the codebase.
- name: Check out the codebase
uses: actions/checkout@v2

- name: Set up Python 3
uses: actions/setup-python@v2
with:
path: "{{ cookiecutter.namespace }}.{{ cookiecutter.role_name }}"
python-version: "3.x"

- name: Install test dependencies
run: pip3 install --requirement requirements.txt

- name: Lint code
run: yamllint .

- name: Set up Python 3.
ansiblelint:
name: Ansible Lint
needs: yamllint
runs-on: ubuntu-22.04

steps:
- name: Check out the codebase
uses: actions/checkout@v2

- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install test dependencies.
run: pip3 install yamllint
- name: Install test dependencies
run: pip3 install --requirement requirements.txt

- name: Lint code.
run: |
yamllint .
- name: Lint code
run: ansible-lint .

molecule:
name: Molecule
name: Molecule Test
needs: ansiblelint
runs-on: ubuntu-22.04

strategy:
max-parallel: 4
matrix:
Expand All @@ -71,20 +87,18 @@ jobs:
- ubuntu2204

steps:
- name: Check out the codebase.
- name: Check out the codebase
uses: actions/checkout@v2
with:
path: "{{ cookiecutter.namespace }}.{{ cookiecutter.role_name }}"

- name: Set up Python 3.
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install test dependencies.
run: pip3 install ansible molecule molecule-plugins[docker] docker
- name: Install test dependencies
run: pip3 install --requirement requirements.txt

- name: Run Molecule tests.
- name: Run Molecule tests
run: molecule test --scenario-name {% raw %}${{ matrix.molecule-scenario }}{% endraw %}
env:
PY_COLORS: "1"
Expand Down

0 comments on commit 044193e

Please sign in to comment.