move the coverage to python-tests and use secret token as the trigger #1
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
| name: Python Tests | ||
|
Check failure on line 1 in .github/workflows/python-tests.yml
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| python-version: | ||
| required: false | ||
| type: string | ||
| default: "3.12" | ||
| os: | ||
| required: false | ||
| type: string | ||
| default: "ubuntu-latest" | ||
| pytest-args: | ||
| required: false | ||
| type: string | ||
| default: "-v -ra -W error" | ||
| codecov-flags: | ||
| required: false | ||
| type: string | ||
| default: "" | ||
| jupyter-platform-dirs: | ||
| required: false | ||
| type: string | ||
| default: "1" | ||
| qt-qpa-platform: | ||
| required: false | ||
| type: string | ||
| default: "offscreen" | ||
| qt-api: | ||
| required: false | ||
| type: string | ||
| default: "" | ||
| qt-binding: | ||
| required: false | ||
| type: string | ||
| default: "" | ||
| display: | ||
| required: false | ||
| type: string | ||
| default: "0" | ||
| secrets: | ||
| codecov_token: | ||
| required: false | ||
| jobs: | ||
| test: | ||
| runs-on: ${{ inputs.os }} | ||
| steps: | ||
| - uses: ewoks-kit/.github/.github/actions/setup-python-package@main | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| install-extras: "test" | ||
| - name: Install Qt runtime libraries | ||
| if: startsWith(inputs.os, 'ubuntu') && (inputs.qt-api != '' || inputs.qt-binding != '') | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y libegl1 | ||
| - name: Configure test environment | ||
| shell: bash | ||
| run: | | ||
| if [ -n "${{ inputs.jupyter-platform-dirs }}" ]; then | ||
| echo "JUPYTER_PLATFORM_DIRS=${{ inputs.jupyter-platform-dirs }}" >> "$GITHUB_ENV" | ||
| fi | ||
| if [ -n "${{ inputs.qt-qpa-platform }}" ]; then | ||
| echo "QT_QPA_PLATFORM=${{ inputs.qt-qpa-platform }}" >> "$GITHUB_ENV" | ||
| fi | ||
| if [ -n "${{ inputs.qt-api }}" ]; then | ||
| echo "QT_API=${{ inputs.qt-api }}" >> "$GITHUB_ENV" | ||
| fi | ||
| if [ -n "${{ inputs.display }}" ]; then | ||
| echo "DISPLAY=${{ inputs.display }}" >> "$GITHUB_ENV" | ||
| fi | ||
| if [ -n "${{ inputs.qt-binding }}" ]; then | ||
| echo "QT_BINDING=${{ inputs.qt-binding }}" >> "$GITHUB_ENV" | ||
| fi | ||
| - name: Resolve distribution name | ||
| shell: bash | ||
| env: | ||
| REPO_NAME: ${{ github.event.repository.name }} | ||
| run: | | ||
| DISTRO_NAME="${REPO_NAME//-/_}" | ||
| echo "DISTRO_NAME=$DISTRO_NAME" >> "$GITHUB_ENV" | ||
| - name: Install coverage tooling | ||
| if: ${{ secrets.codecov_token != '' }} | ||
| run: pip install pytest-cov "coverage[toml]" | ||
| - name: Run pytest | ||
| if: ${{ secrets.codecov_token == '' }} | ||
| run: pytest ${{ inputs.pytest-args }} --pyargs "$DISTRO_NAME" | ||
| - name: Run pytest with coverage | ||
| if: ${{ secrets.codecov_token != '' }} | ||
| run: | | ||
| pytest ${{ inputs.pytest-args }} \ | ||
| --cov="$DISTRO_NAME" \ | ||
| --cov-report=term \ | ||
| --cov-report=xml \ | ||
| --pyargs "$DISTRO_NAME" | ||
| - name: Upload coverage artifact | ||
| if: ${{ secrets.codecov_token != '' }} | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-xml | ||
| path: coverage.xml | ||
| - name: Upload coverage to Codecov | ||
| if: ${{ secrets.codecov_token != '' }} | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| files: coverage.xml | ||
| flags: ${{ inputs.codecov-flags }} | ||
| token: ${{ secrets.codecov_token }} | ||
| fail_ci_if_error: false | ||