|
| 1 | +name: CI test C++ coverage |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + build-command: |
| 7 | + description: Shell commands that build the C++ code with coverage instrumentation, for example "make -C src coverage". |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + filters: |
| 11 | + description: gcovr filters, one regular expression per line, selecting the source files to report. |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + flag-name: |
| 15 | + description: Name for this coverage report in Coveralls. The caller closes the parallel build with ci-coveralls-finish. |
| 16 | + type: string |
| 17 | + default: cpp |
| 18 | + python-version: |
| 19 | + description: Python version used to install the package and run the tests. |
| 20 | + type: string |
| 21 | + default: "3.14" |
| 22 | + conda-packages: |
| 23 | + description: >- |
| 24 | + Space-separated conda package specs to install, for example programs |
| 25 | + the tests call that pip cannot install. Leave empty to skip conda. |
| 26 | + type: string |
| 27 | + default: "" |
| 28 | + channels: |
| 29 | + description: Comma-separated conda channels, in priority order. |
| 30 | + type: string |
| 31 | + default: conda-forge |
| 32 | + extras: |
| 33 | + description: Optional-dependency group installed with the package. Leave empty to install the package alone. |
| 34 | + type: string |
| 35 | + default: testing |
| 36 | + pre-test-command: |
| 37 | + description: Shell commands run in the same step as pytest, for example exporting the paths of the instrumented binaries. |
| 38 | + type: string |
| 39 | + default: "" |
| 40 | + pytest-args: |
| 41 | + description: Extra arguments passed to pytest. |
| 42 | + type: string |
| 43 | + default: "" |
| 44 | + test-path: |
| 45 | + description: Path passed to pytest. |
| 46 | + type: string |
| 47 | + default: tests |
| 48 | + gcovr-root: |
| 49 | + description: gcovr root directory. |
| 50 | + type: string |
| 51 | + default: "." |
| 52 | + gcovr-args: |
| 53 | + description: Extra arguments passed to gcovr. |
| 54 | + type: string |
| 55 | + default: "" |
| 56 | + timeout-minutes: |
| 57 | + description: Timeout for the job. |
| 58 | + type: number |
| 59 | + default: 30 |
| 60 | + |
| 61 | +permissions: |
| 62 | + contents: read |
| 63 | + |
| 64 | +jobs: |
| 65 | + cpp-coverage: |
| 66 | + name: Test |
| 67 | + runs-on: ubuntu-26.04 |
| 68 | + timeout-minutes: ${{ inputs.timeout-minutes }} |
| 69 | + permissions: |
| 70 | + contents: read |
| 71 | + checks: write |
| 72 | + statuses: write |
| 73 | + defaults: |
| 74 | + run: |
| 75 | + shell: bash -el {0} |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Checkout |
| 79 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 80 | + with: |
| 81 | + persist-credentials: false |
| 82 | + |
| 83 | + - name: Set up Python ${{ inputs.python-version }} |
| 84 | + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 |
| 85 | + with: |
| 86 | + python-version: ${{ inputs.python-version }} |
| 87 | + |
| 88 | + - name: Set up conda |
| 89 | + if: inputs.conda-packages != '' |
| 90 | + uses: conda-incubator/setup-miniconda@be893c923ea9cf1cf7cd510fbdde27c7e18cbdcb # v4.1.0 |
| 91 | + with: |
| 92 | + miniforge-variant: Miniforge3 |
| 93 | + python-version: ${{ inputs.python-version }} |
| 94 | + activate-environment: testing |
| 95 | + channels: ${{ inputs.channels }} |
| 96 | + auto-activate: false |
| 97 | + |
| 98 | + - name: Install conda packages |
| 99 | + if: inputs.conda-packages != '' |
| 100 | + env: |
| 101 | + PYTHON_VERSION: ${{ inputs.python-version }} |
| 102 | + PACKAGES: ${{ inputs.conda-packages }} |
| 103 | + CHANNELS: ${{ inputs.channels }} |
| 104 | + run: | |
| 105 | + channel_args=() |
| 106 | + IFS=',' read -ra channel_list <<< "${CHANNELS}" |
| 107 | + for channel in "${channel_list[@]}"; do |
| 108 | + channel_args+=(-c "${channel}") |
| 109 | + done |
| 110 | +
|
| 111 | + read -r -a package_list <<< "${PACKAGES}" |
| 112 | + conda install -y "${channel_args[@]}" "python=${PYTHON_VERSION}" "${package_list[@]}" |
| 113 | +
|
| 114 | + - name: Install the package |
| 115 | + env: |
| 116 | + EXTRAS: ${{ inputs.extras }} |
| 117 | + run: | |
| 118 | + python -m pip install --upgrade pip |
| 119 | + if [ -n "${EXTRAS}" ]; then |
| 120 | + python -m pip install -e ".[${EXTRAS}]" |
| 121 | + else |
| 122 | + python -m pip install -e . |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Build with coverage instrumentation |
| 126 | + env: |
| 127 | + BUILD_COMMAND: ${{ inputs.build-command }} |
| 128 | + run: eval "${BUILD_COMMAND}" |
| 129 | + |
| 130 | + - name: Run tests |
| 131 | + env: |
| 132 | + TEST_PATH: ${{ inputs.test-path }} |
| 133 | + PYTEST_ARGS: ${{ inputs.pytest-args }} |
| 134 | + PRE_TEST_COMMAND: ${{ inputs.pre-test-command }} |
| 135 | + run: | |
| 136 | + if [ -n "${PRE_TEST_COMMAND}" ]; then |
| 137 | + eval "${PRE_TEST_COMMAND}" |
| 138 | + fi |
| 139 | +
|
| 140 | + read -r -a extra_args <<< "${PYTEST_ARGS}" |
| 141 | + python -m pytest "${extra_args[@]}" "${TEST_PATH}" |
| 142 | +
|
| 143 | + - name: Upload coverage to Coveralls |
| 144 | + uses: CCPBioSim/.github/actions/cpp-coverage-upload@edc3732fa8d31a58312ca784e65cad9bdfba9347 # 0.13.0 |
| 145 | + with: |
| 146 | + filters: ${{ inputs.filters }} |
| 147 | + flag-name: ${{ inputs.flag-name }} |
| 148 | + root: ${{ inputs.gcovr-root }} |
| 149 | + gcovr-args: ${{ inputs.gcovr-args }} |
0 commit comments