From ba62727cc2d6f0c02a7c4e15cec5c783af090aba Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 5 Aug 2024 11:00:30 +0100 Subject: [PATCH] Unify testing jobs into a single workflows Related: #219 --- .github/workflows/integration-tests.yml | 46 ---------------- .github/workflows/tests.yml | 47 ---------------- .github/workflows/tox.yml | 73 ++++++++++++++++++++++++- CONTRIBUTING.md | 35 ++++++------ test_requirements.txt | 2 + tox.ini | 20 +++++-- 6 files changed, 105 insertions(+), 118 deletions(-) delete mode 100644 .github/workflows/integration-tests.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml deleted file mode 100644 index 05053994..00000000 --- a/.github/workflows/integration-tests.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Run integration tests -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - # Run the integration tests every 8 hours. - # This will help to identify faster if - # there is a CI failure related to a - # change in any dependency. - schedule: - - cron: '0 */8 * * *' -jobs: - 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 - pip install wheel - pip install -r test_requirements.txt - - - name: Install collection - run: ansible-galaxy collection install . - - - name: run integration tests - run: pytest tests/integration -vvv -s diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 40d34876..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Run Ansible tests -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - # Run the unit tests every 8 hours. - # This will help to identify faster if - # there is a CI failure related to a - # change in any dependency. - schedule: - - cron: '0 */8 * * *' -jobs: - 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: ansible-test units --venv -v --num-workers 1 - working-directory: ansible_collections/ansible/eda diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 4bf8fa01..05040955 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -14,7 +14,7 @@ on: # Run on demand workflow_dispatch: jobs: - tox: + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6501a8c0..0d719aa2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: @@ -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 ``` @@ -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 ``` diff --git a/test_requirements.txt b/test_requirements.txt index 2f3d8daf..0970a0ad 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -7,3 +7,5 @@ ansible requests ansible-rulebook tox +docker-compose +ansible-core diff --git a/tox.ini b/tox.ini index d129be9a..712a5ed5 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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