|
| 1 | +# This workflow will install Python dependencies, run tests, |
| 2 | +# and report test results and code coverage as artifacts. It will |
| 3 | +# be called by the workflow that runs tests against new PRs and as |
| 4 | +# a first step in the workflow that publishes new Docker images. |
| 5 | + |
| 6 | +name: A reusable workflow to build and run the unit test suite |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_call: |
| 10 | + secrets: |
| 11 | + codecov_token: |
| 12 | + required: true |
| 13 | + EARTHDATA_USERNAME: |
| 14 | + description: 'NASA Earthdata username' |
| 15 | + required: true |
| 16 | + EARTHDATA_PASSWORD: |
| 17 | + description: 'NASA Earthdata password' |
| 18 | + required: true |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +jobs: |
| 22 | + build_and_test: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + python-version: [ '3.11', '3.12', '3.13', '3.14' ] |
| 27 | + |
| 28 | + name: Python ${{ matrix.python-version }} tests |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v6 |
| 32 | + |
| 33 | + - name: Override .python-version for matrix testing |
| 34 | + run: echo "${{ matrix.python-version }}" > .python-version |
| 35 | + |
| 36 | + - name: Set up Python |
| 37 | + uses: actions/setup-python@v6 |
| 38 | + with: |
| 39 | + python-version: ${{ matrix.python-version }} |
| 40 | + |
| 41 | + - name: Install uv |
| 42 | + uses: astral-sh/setup-uv@v7 |
| 43 | + with: |
| 44 | + enable-cache: true |
| 45 | + |
| 46 | + - name: Install package |
| 47 | + run: uv sync --frozen |
| 48 | + |
| 49 | + - name: Run linting |
| 50 | + run: uv run ruff check ncompare |
| 51 | + |
| 52 | + - name: Run unit tests with coverage |
| 53 | + run: | |
| 54 | + uv run pytest -v -m "not integration" --cov=ncompare --cov-report= |
| 55 | +
|
| 56 | + - name: Run integration tests with coverage |
| 57 | + env: |
| 58 | + EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }} |
| 59 | + EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }} |
| 60 | + run: | |
| 61 | + uv run pytest -v -m integration --cov=ncompare --cov-append --cov-report= |
| 62 | +
|
| 63 | + - name: Generate combined coverage report |
| 64 | + run: | |
| 65 | + uv run coverage xml -o build/reports/coverage${{ matrix.python-version }}.xml |
| 66 | + uv run coverage report |
| 67 | +
|
| 68 | + - name: Upload coverage reports to Codecov |
| 69 | + uses: codecov/codecov-action@v5 |
| 70 | + with: |
| 71 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 72 | + files: build/reports/coverage${{ matrix.python-version }}.xml |
| 73 | + flags: python-${{ matrix.python-version }} |
| 74 | + name: python-${{ matrix.python-version }} |
| 75 | + verbose: true |
0 commit comments