|
| 1 | +name: Coverage |
| 2 | +on: |
| 3 | + pull_request: {} |
| 4 | + workflow_dispatch: {} |
| 5 | +env: |
| 6 | + UV_PYTHON_PREFERENCE: only-system |
| 7 | + UV_NO_SYNC: "1" |
| 8 | + PKCS11_TOKEN_LABEL: "TEST" |
| 9 | + PKCS11_TOKEN_PIN: "1234" |
| 10 | + PKCS11_TOKEN_SO_PIN: "5678" |
| 11 | +jobs: |
| 12 | + # For now, we run the coverage as a separate job. |
| 13 | + # At the time of writing, the latest version of Cython's line tracing |
| 14 | + # seems to lead to segfaults in Python 3.13 -> TODO: investigate |
| 15 | + pytest-coverage: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + pkcs11-platform: |
| 20 | + - softhsm |
| 21 | + - opencryptoki |
| 22 | + steps: |
| 23 | + - name: Acquire sources |
| 24 | + uses: actions/checkout@v4 |
| 25 | + - name: Arm coverage-only compiler directives |
| 26 | + # Unfortunately, it doesn't seem to be possible to pass directives |
| 27 | + # to Cython through environment variables: https://github.com/cython/cython/issues/3930 |
| 28 | + # Doing it here is still better than introducing a non-declarative setup.py into the |
| 29 | + # build again. |
| 30 | + run: sed -i 's/#coverage#cython/#cython/g' pkcs11/*.pyx |
| 31 | + - uses: ./.github/actions/test-setup |
| 32 | + id: setup |
| 33 | + with: |
| 34 | + os: ubuntu-latest |
| 35 | + python-version: "3.12" |
| 36 | + dependency-group: coverage |
| 37 | + token-label: ${{ env.PKCS11_TOKEN_LABEL }} |
| 38 | + token-so-pin: ${{ env.PKCS11_TOKEN_SO_PIN }} |
| 39 | + token-user-pin: ${{ env.PKCS11_TOKEN_PIN }} |
| 40 | + pkcs11-platform: ${{ matrix.pkcs11-platform }} |
| 41 | + env: |
| 42 | + CFLAGS: "-DCYTHON_TRACE_NOGIL=1" |
| 43 | + EXT_BUILD_DEBUG: "1" |
| 44 | + - name: Run tests |
| 45 | + run: uv run pytest -v --cov=pkcs11 --cov-branch --cov-report=xml:${{ matrix.pkcs11-platform }}-coverage.xml |
| 46 | + env: |
| 47 | + PKCS11_MODULE: ${{ steps.setup.outputs.module }} |
| 48 | + - name: Stash coverage report |
| 49 | + uses: actions/upload-artifact@v4 |
| 50 | + with: |
| 51 | + name: coverage-${{ strategy.job-index }} |
| 52 | + path: "*-coverage.xml" |
| 53 | + pytest-coverage-multilib: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - name: Acquire sources |
| 57 | + uses: actions/checkout@v4 |
| 58 | + - uses: ./.github/actions/test-setup |
| 59 | + id: setup |
| 60 | + with: |
| 61 | + os: ubuntu-latest |
| 62 | + pkcs11-platform: multi |
| 63 | + token-label: ${{ env.PKCS11_TOKEN_LABEL }} |
| 64 | + token-so-pin: ${{ env.PKCS11_TOKEN_SO_PIN }} |
| 65 | + token-user-pin: ${{ env.PKCS11_TOKEN_PIN }} |
| 66 | + python-version: "3.12" |
| 67 | + dependency-group: coverage |
| 68 | + - name: Run tests |
| 69 | + run: uv run pytest -v --cov=pkcs11 --cov-branch --cov-report=xml:multilib-coverage.xml tests/test_multilib.py |
| 70 | + env: |
| 71 | + PKCS11_MODULE: ${{ steps.setup.outputs.module }} |
| 72 | + PKCS11_MODULE2: ${{ steps.setup.outputs.module2 }} |
| 73 | + - name: Stash coverage report |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: coverage-multilib |
| 77 | + path: "*-coverage.xml" |
| 78 | + codecov-upload: |
| 79 | + permissions: |
| 80 | + actions: write |
| 81 | + contents: read |
| 82 | + runs-on: ubuntu-latest |
| 83 | + needs: [pytest-coverage] |
| 84 | + steps: |
| 85 | + # checkout necessary to ensure the uploaded report contains the correct paths |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + - name: Retrieve coverage reports |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + pattern: coverage-* |
| 91 | + path: ./reports/ |
| 92 | + - name: Upload all coverage reports to Codecov |
| 93 | + uses: codecov/codecov-action@v5 |
| 94 | + with: |
| 95 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 96 | + directory: ./reports/ |
| 97 | + flags: unittests |
| 98 | + env_vars: OS,PYTHON |
| 99 | + name: codecov-umbrella |
0 commit comments