Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tox for linting and testing #117

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
skip_list:
- '106' # Role name {} does not match \^[a-z][a-z0-9_]+$\ pattern'
exclude_paths:
- .tox/
- .venv/
28 changes: 28 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "ansible_role_minikube",
"image": "ghcr.io/gantsign/devcontainer-python3.9:latest",
"customizations": {
"vscode": {
"extensions": [
"DavidAnson.vscode-markdownlint",
"donjayamanne.githistory",
"EditorConfig.EditorConfig",
"github.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"ldez.ignore-files",
"me-dutour-mathieu.vscode-github-actions",
"mhutchie.git-graph",
"oderwat.indent-rainbow",
"redhat.ansible",
"streetsidesoftware.code-spell-checker",
"wholroyd.jinja"
]
}
},
"remoteEnv": {
"PATH": "/home/vscode/.local/bin:${containerEnv:PATH}"
},
"postCreateCommand": "pip3 install --user -r requirements/dev.txt"
}
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ charset = utf-8
indent_style = space
indent_size = 4

# Ansible Lint
[.ansible-lint]
indent_size = 2

# Jinja2 template files
[*.j2]
end_of_line = lf

# Devcontainer config
[devcontainer.json]
indent_style = tab
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ LICENSE text
.editorconfig text
.gitattributes text
.gitignore text
.python-version text
.yamllint text
*.cfg text
*.css text
*.htm text
*.html text
*.in text
*.ini text
*.js text
*.json text
*.less text
Expand Down
104 changes: 77 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,61 @@ on:
pull_request: {}

env:
MOLECULEW_USE_SYSTEM: 'true'
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'

- name: Tox cache
id: tox-cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: tox-${{ hashFiles('requirements/tox.txt') }}-py${{ steps.setup-python.outputs.python-version}}

- name: Lint cache
id: lint-cache
uses: actions/cache@v4
with:
path: .tox
key: lint-${{ hashFiles('requirements/lint.txt') }}-py${{ steps.setup-python.outputs.python-version}}

- name: Install tox
run: pip3 install --no-compile -r requirements/tox.txt

- name: Lint
run: tox --colored=yes run -e lint

- name: Compact lint cache
if: steps.lint-cache.outputs.cache-hit != 'true'
run: find .tox -name '__pycache__' -exec rm -rf {} +

- name: Compact tox cache
if: steps.tox-cache.outputs.cache-hit != 'true'
run: find ~/.cache/pip -name '__pycache__' -exec rm -rf {} +

test:
name: Molecule test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

strategy:
max-parallel: 3

matrix:
ansible-version:
- '7.3.0' # max-ansible-test-version
- max
molecule-scenario:
- rocky
- debian_max
Expand All @@ -28,53 +70,61 @@ jobs:
- opensuse
- fedora
include:
- ansible-version: '5.10.0' # min-ansible-test-version
- ansible-version: min
molecule-scenario: ubuntu_min
env:
MOLECULEW_ANSIBLE: ${{ matrix.ansible-version }}

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version-file: '.python-version'

- name: Cache Molecule
id: molecule-cache
uses: actions/cache@v3
- name: Tox cache
id: tox-cache
uses: actions/cache@v4
with:
path: ~/.moleculew
key: Ansible-${{ matrix.ansible-version }}-${{ hashFiles('.moleculew/**') }}
path: ~/.cache/pip
key: tox-${{ hashFiles('requirements/tox.txt') }}-py${{ steps.setup-python.outputs.python-version}}

- name: Install dependencies
if: steps.molecule-cache.outputs.cache-hit != 'true'
run: ./moleculew wrapper-install

- name: Dependency versions
run: ./moleculew wrapper-versions
- name: Molecule cache
id: molecule-cache
uses: actions/cache@v4
with:
path: .tox
key: molecule-${{ hashFiles(format('requirements/ansible-{0}.txt', matrix.ansible-version)) }}-py${{ steps.setup-python.outputs.python-version}}

- name: Login to Docker Hub
if: '!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository'
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Install tox
run: pip3 install --no-compile -r requirements/tox.txt

- name: Molecule test
run: ./moleculew test --scenario-name=${{ matrix.molecule-scenario }}
run: tox --colored=yes run -e ansible-${{ matrix.ansible-version }} -- --scenario-name=${{ matrix.molecule-scenario }}

- name: Compact cache
- name: Compact Molecule cache
if: steps.molecule-cache.outputs.cache-hit != 'true'
run: find ~/.moleculew -name '__pycache__' -exec rm -rf {} +
run: find .tox -name '__pycache__' -exec rm -rf {} +

- name: Compact tox cache
if: steps.tox-cache.outputs.cache-hit != 'true'
run: find ~/.cache/pip -name '__pycache__' -exec rm -rf {} +

test-all:
if: ${{ always() }}
name: Test (matrix)
runs-on: ubuntu-20.04
needs: test
runs-on: ubuntu-22.04
needs:
- lint
- test
steps:
- name: Check test matrix status
run: "[[ '${{ needs.test.result }}' == 'success' ]] || exit 1"
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fabric.properties

# *.iml
# modules.xml
# .idea/misc.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
Expand Down Expand Up @@ -295,3 +295,9 @@ $RECYCLE.BIN/
__pycache__
.cache
.molecule

### Tox ###
.tox

### For development ###
.venv
1 change: 0 additions & 1 deletion .moleculew/ansible_lint_version

This file was deleted.

1 change: 0 additions & 1 deletion .moleculew/ansible_version

This file was deleted.

1 change: 0 additions & 1 deletion .moleculew/flake8_version

This file was deleted.

1 change: 0 additions & 1 deletion .moleculew/molecule_version

This file was deleted.

1 change: 0 additions & 1 deletion .moleculew/python_version

This file was deleted.

1 change: 0 additions & 1 deletion .moleculew/testinfra_version

This file was deleted.

1 change: 0 additions & 1 deletion .moleculew/yamllint_version

This file was deleted.

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
4 changes: 4 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ rules:
trailing-spaces: disable
truthy:
allowed-values: ['true', 'false', 'on']

ignore: |
.tox/
.venv/
40 changes: 13 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the tool for running Kubernetes locally.
Requirements
------------

* Ansible >= 5 (Ansible Core >= 2.12)
* Ansible Core >= 2.12

* Linux Distribution

Expand Down Expand Up @@ -122,32 +122,18 @@ You can find more roles from GantSign on
Development & Testing
---------------------

This project uses [Molecule](http://molecule.readthedocs.io/) to aid in the
development and testing; the role is unit tested using
[Testinfra](http://testinfra.readthedocs.io/) and
[pytest](http://docs.pytest.org/).

To develop or test you'll need to have installed the following:

* Linux (e.g. [Ubuntu](http://www.ubuntu.com/))
* [Docker](https://www.docker.com/)
* [Python](https://www.python.org/) (including python-pip)
* [Ansible](https://www.ansible.com/)
* [Molecule](http://molecule.readthedocs.io/)

Because the above can be tricky to install, this project includes
[Molecule Wrapper](https://github.com/gantsign/molecule-wrapper). Molecule
Wrapper is a shell script that installs Molecule and it's dependencies (apart
from Linux) and then executes Molecule with the command you pass it.

To test this role using Molecule Wrapper run the following command from the
project root:

```bash
./moleculew test
```

Note: some of the dependencies need `sudo` permission to install.
This project uses the following tooling:
* [Molecule](http://molecule.readthedocs.io/) for orchestrating test scenarios
* [Testinfra](http://testinfra.readthedocs.io/) for testing the changes on the
remote
* [pytest](http://docs.pytest.org/) the testing framework
* [Tox](https://tox.wiki/en/latest/) manages Python virtual
environments for linting and testing
* [pip-tools](https://github.com/jazzband/pip-tools) for managing dependencies

A Visual Studio Code
[Dev Container](https://code.visualstudio.com/docs/devcontainers/containers) is
provided for developing and testing this role.

License
-------
Expand Down
Binary file removed minikube-linux-amd64
Binary file not shown.
3 changes: 3 additions & 0 deletions molecule/opensuse/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
collections:
- community.general
Loading
Loading