Skip to content

Commit

Permalink
Unify testing jobs into a single workflows
Browse files Browse the repository at this point in the history
Related: #219
  • Loading branch information
ssbarnea committed Aug 5, 2024
1 parent 1021e53 commit ba62727
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 118 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/integration-tests.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/workflows/tests.yml

This file was deleted.

73 changes: 71 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
# Run on demand
workflow_dispatch:
jobs:
tox:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -29,4 +29,73 @@ jobs:

- name: Run tox
run: |
python -m tox
python -m tox -e lint,darglint
tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- "3.10"
- "3.9"

defaults:
run:
working-directory: ansible_collections/

steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: ansible_collections/ansible/eda

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# - name: Install ansible
# run: python -m pip install ansible

# - name: Run sanity tests
# run: ansible-test sanity
# working-directory: ansible_collections/ansible/eda

- name: Run unit tests
run: tox -e py
# ansible-test units --venv -v --num-workers 1
working-directory: ansible_collections/ansible/eda
integration:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Java
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install package dependencies
run: |
sudo apt-get update
sudo apt-get --assume-yes --no-install-recommends install libsystemd0 libsystemd-dev pkg-config
- name: Install test requirements
run: |
pip install -U pip tox
# pip install wheel
# pip install -r test_requirements.txt

# - name: Install collection
# run: ansible-galaxy collection install .

- name: run integration tests
run: tox -e integration
# pytest tests/integration -vvv -s
35 changes: 16 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Contributions are welcome, and they are greatly appreciated! Every little bit he
Every new feature should be tested and documented.
New source plugins or source filters will be evaluated for inclusion in the collection and might be rejected. Please consider the option of creating a new collection for your plugins if it is not a good fit for this collection.

## Cloning

Due to ansible-test own requirements, you must clone the repository into
a directory structure such `ansible_collections/ansible/eda`. This will allow
ansible-test to test your code without having to install the collection.

## Pre-commit

We recommend running pre-commit prior to submitting pull requests. A [pre-commit config](.pre-commit-config.yaml) file is included in this repository and the following steps will get you up and running with pre-commit quickly:
Expand All @@ -18,7 +24,7 @@ We recommend running pre-commit prior to submitting pull requests. A [pre-commit

Pre-commit is now set up to run each time you create a new commit. If you wish to run pre-commit against all tracked files in the repository without performing a commit, you can run:

```
```shell
pre-commit run --all
```

Expand All @@ -41,30 +47,21 @@ We recommend setting up a Python virtual environment to install the test depende

pip install -r test_requirements.txt

### Integration tests
### Sanity and Unit tests

Integration tests require the addition of [docker](https://docs.docker.com/engine/install/) or [podman](https://podman.io/getting-started/installation) and [docker-compose](https://docs.docker.com/compose/install/).
We recommend installing the Python implementation of `docker-compose` via pip:
Sanity and unity tests can easily be run via tox:

```shell
tox -e py
```
pip install docker-compose
```

Then install the collection directly from your local repo and execute the tests:

```
ansible-galaxy collection install .
pytest tests/integration
```
### Integration tests

### Sanity tests
Integration tests require the addition of [docker](https://docs.docker.com/engine/install/) or [podman](https://podman.io/getting-started/installation) and [docker-compose](https://docs.docker.com/compose/install/).

```sh
ansible-test sanity
```

### Units tests
Then install the collection directly from your local repo and execute the tests:

```sh
ansible-test units
```shell
tox -e integration
```
2 changes: 2 additions & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ ansible
requests
ansible-rulebook
tox
docker-compose
ansible-core
20 changes: 16 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
# {posargs} in this case would be the path to collection root relative from the .github/workflows dir (`../..`)

[tox]
envlist = lint
requires =
lint
darglint
envlist = lint, darglint, py, integration
skipsdist = true # this repo is not a python package

[testenv]
description = Run sanity and unit tests
basepython = python3.9, python3.10
deps = -r test_requirements.txt
commands_pre =
sh -c '[[ $(basename $(cd $PWD/../.. && pwd)) == ansible_collections ]] || { echo "Repository must be cloned inside a directory structure like ansible_collections/ansible/eda in order allow ansible-test to run."; exit 3;}'
commands =
ansible-test sanity
ansible-test units --venv -v --num-workers 1
allowlist_externals =
sh

[testenv:lint]
deps = pre-commit
Expand All @@ -20,3 +26,9 @@ commands = pre-commit run -a
[testenv:darglint]
deps = darglint
commands = darglint -s numpy -z full extensions/eda/plugins

[testenv:integration]
deps = -r test_requirements.txt
description = Run integration tests
commands =
pytest tests/integration -vvv -s

0 comments on commit ba62727

Please sign in to comment.