Repository navigation
tests: add a unit test suite and measure coverage #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright (C) 2025, RTE (http://www.rte-france.com) | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| name: Test (python ${{ matrix.python-version }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install the package and its test dependencies | |
| run: python -m pip install --upgrade pip && python -m pip install -e ".[test]" | |
| - name: Run the test suite | |
| run: python -m pytest --cov=setup_ovs --cov-report=xml --cov-report=term-missing | |
| - name: Keep the coverage report for the Sonar job | |
| if: matrix.python-version == '3.12' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage | |
| path: coverage.xml | |
| reproducible-build: | |
| name: Reproducible build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - run: python -m pip install --upgrade pip build | |
| # Without SOURCE_DATE_EPOCH setuptools stamps the wheel with the file | |
| # mtimes, which differ on every checkout. Pinning it to the commit date | |
| # makes the build a pure function of the source tree. | |
| - name: Build the wheel twice and compare | |
| run: | | |
| SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) | |
| export SOURCE_DATE_EPOCH | |
| echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" | |
| python -m build --wheel --outdir first | |
| python -m build --wheel --outdir second | |
| first_hash=$(sha256sum first/*.whl | cut -d' ' -f1) | |
| second_hash=$(sha256sum second/*.whl | cut -d' ' -f1) | |
| echo "first $first_hash" | |
| echo "second $second_hash" | |
| test "$first_hash" = "$second_hash" | |
| sonar: | |
| name: SonarCloud | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: ${{ !github.event.pull_request.head.repo.fork }} | |
| # Declared at job level so the step below can test it in its `if`. | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Sonar needs the full history to assign blame, and therefore to | |
| # tell new code from old code. | |
| fetch-depth: 0 | |
| - name: Download the coverage report | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage | |
| # The scanner needs a token. Until SONAR_TOKEN is configured on the | |
| # repository this step is skipped rather than failing the workflow. | |
| - name: Run the scanner | |
| if: env.SONAR_TOKEN != '' | |
| uses: SonarSource/sonarqube-scan-action@v5 |