From f27bcea6467ec02b743185278e7af21978853e9d Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Fri, 19 Jul 2024 13:55:11 -0600 Subject: [PATCH] DAS-2180: Adds matrix of library tests to CI renames run_tests -> run_service_tests Adds run_lib_tests and runs the unit tests against a python matrix. --- .github/workflows/publish_release.yml | 11 +++-- .github/workflows/run_lib_tests.yml | 43 +++++++++++++++++++ .../{run_tests.yml => run_service_tests.yml} | 4 +- .../workflows/run_tests_on_pull_requests.yml | 9 ++-- README.md | 13 +++--- pyproject.toml | 2 +- 6 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/run_lib_tests.yml rename .github/workflows/{run_tests.yml => run_service_tests.yml} (95%) diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index 2175689..16901f1 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -1,7 +1,7 @@ # This workflow will run when changes are detected in the `main` branch, which # must include an update to the `docker/service_version.txt` file. The workflow # can also be manually triggered by a repository maintainer. This workflow will -# first trigger the reusable workflow in `.github/workflows/run_tests.yml`, +# first trigger the reusable workflow in `.github/workflows/run_service_tests.yml`, # which runs the `unittest` suite. If that workflow is successful, the latest # version of the service Docker image is pushed to ghcr.io, a library package # is built and published to PyPI, a tag is added to the latest git commit, and @@ -20,11 +20,14 @@ env: REGISTRY: ghcr.io jobs: - run_tests: - uses: ./.github/workflows/run_tests.yml + run_service_tests: + uses: ./.github/workflows/run_service_tests.yml + + run_lib_tests: + uses: ./.github/workflows/run_lib_tests.yml build_and_publish: - needs: run_tests + needs: [run_service_tests, run_lib_tests] runs-on: ubuntu-latest environment: release permissions: diff --git a/.github/workflows/run_lib_tests.yml b/.github/workflows/run_lib_tests.yml new file mode 100644 index 0000000..c38b8bd --- /dev/null +++ b/.github/workflows/run_lib_tests.yml @@ -0,0 +1,43 @@ +# This workflow will run the appropriate library tests across a python matrix of versions. +name: Run Python library tests + +on: + workflow_call + +jobs: + build_and_test_lib: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ['3.10', '3.11'] + + steps: + - name: Checkout harmony-browse-image-generator repository + uses: actions/checkout@v4 + with: + lfs: true + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install GDAL + run: | + # Install packaged version of GDAL. + sudo apt-get update + sudo apt-get install -y libgdal-dev + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install -r pip_requirements.txt + # Use the gdal version that was installed + pip install GDAL==$(gdal-config --version) + pip install -r tests/pip_test_requirements.txt + + - name: Run tests without the adapters. + run: | + pytest $(find tests -name "test_*.py" ! -name "*adapter*") diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_service_tests.yml similarity index 95% rename from .github/workflows/run_tests.yml rename to .github/workflows/run_service_tests.yml index 0afce2f..1568825 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_service_tests.yml @@ -3,13 +3,13 @@ # test results and code coverage as artefacts. It will be called by the # workflow that run tests against new PRs and as a first step in the workflow # that publishes new Docker images. -name: Run Python unit tests +name: Run Python tests on: workflow_call jobs: - build_and_test: + build_and_test_service: runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/.github/workflows/run_tests_on_pull_requests.yml b/.github/workflows/run_tests_on_pull_requests.yml index a948fd1..279a41e 100644 --- a/.github/workflows/run_tests_on_pull_requests.yml +++ b/.github/workflows/run_tests_on_pull_requests.yml @@ -1,5 +1,5 @@ # This workflow will run when a PR is opened against the `main` branch. It will -# trigger the reusable workflow in `.github/workflows/run_tests.yml`, which +# trigger the reusable workflow in `.github/workflows/run_service_tests.yml`, which # builds the service and test Docker images, and runs the `unittest` suite in a # Docker container built from the test image. name: Run Python unit tests for pull requests against main @@ -9,5 +9,8 @@ on: branches: [ main ] jobs: - build_and_test: - uses: ./.github/workflows/run_tests.yml + build_and_test_service: + uses: ./.github/workflows/run_service_tests.yml + + run_lib_tests: + uses: ./.github/workflows/run_lib_tests.yml diff --git a/README.md b/README.md index af67e69..4a7bf52 100644 --- a/README.md +++ b/README.md @@ -364,15 +364,16 @@ When publishing a new release, two files must be updated: The CI/CD for HyBIG is contained in GitHub workflows in the `.github/workflows` directory: -* `run_tests.yml` - A reusable workflow that builds the service and test Docker - images, then runs the Python unit test suite in an instance of the test - Docker container. +* `run_lib_tests.yml` - A reusable workflow that tests the library functions + against the supported python versions. +* `run_service_tests.yml` - A reusable workflow that builds the service and + test Docker images, then runs the Python unit test suite in an instance of + the test Docker container. * `run_tests_on_pull_requests.yml` - Triggered for all PRs against the `main` - branch. It runs the workflow in `run_tests.yml` to ensure all tests pass for - the new code. + branch. It runs the workflow in `run_service_tests.yml` and + `run_lib_tests.yml` to ensure all tests pass for the new code. * `publish_docker_image.yml` - Triggered either manually or for commits to the `main` branch that contain changes to the `docker/service_version.txt` file. - * `publish_to_pypi.yml` - Triggered either manually or for commits to the `main` branch that contain changes to the `docker/service_version.txt`file. diff --git a/pyproject.toml b/pyproject.toml index f22682a..71ab6e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ maintainers = [ description = "Python package designed to produce browse imagery compatible with NASA's Global Image Browse Services (GIBS)." readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.10" classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License",