Tempcal plugin #1741
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: Pytest | |
| # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#packaging-workflow-data-as-artifacts | |
| on: | |
| pull_request: | |
| paths: | |
| - '**/*.py' # Watch for changes in any Python files | |
| - 'pyproject.toml' # Watch for changes in the pyproject.toml file | |
| - '.github/workflows/pytest.yml' | |
| push: | |
| branches: | |
| - master # Only run on push to master branch | |
| paths: | |
| - '**/*.py' # Watch for changes in any Python files | |
| - 'pyproject.toml' # Watch for changes in the pyproject.toml file | |
| - '.github/workflows/pytest.yml' | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: read | |
| jobs: | |
| pytest: | |
| if: github.event_name == 'pull_request' || (github.event_name == 'push' && !github.event.pull_request) || github.event_name == 'workflow_dispatch' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # os: [ubuntu-latest, macos-latest, windows-latest] | |
| # python-version: ["3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"] | |
| os: [ubuntu-latest] | |
| python-version: ["3.9", "3.14", "3.14t"] | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| # https://docs.astral.sh/uv/guides/integration/github/ | |
| - name: Install uv and set the Python version | |
| uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| activate-environment: true | |
| - name: Install system dependencies for GUI testing | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y python3-tk scrot xdotool x11-utils gnome-screenshot | |
| - name: Install dependencies and application | |
| # without --editable, the coverage report is not generated correctly | |
| run: | | |
| uv pip install --editable .[dev,ci_headless_tests] | |
| - name: Test with pytest | |
| id: pytest | |
| continue-on-error: false | |
| run: | | |
| export LIBGL_ALWAYS_SOFTWARE=1 | |
| export DISPLAY=:99 | |
| # disable X authentication | |
| export XAUTHORITY=/dev/null | |
| # disable access control restrictions | |
| Xvfb :99 -screen 0 1024x768x16 -ac & | |
| # ensure Xvfb is fully started before running tests | |
| sleep 2 | |
| uv run pytest --cov=ardupilot_methodic_configurator --cov-report=xml:tests/coverage.xml --md=tests/results-${{ matrix.python-version }}.md --junit-xml=tests/results-junit.xml | |
| - name: Fix coverage paths | |
| run: | | |
| sed -i 's|<package name="." |<package name="ardupilot_methodic_configurator" |' tests/coverage.xml | |
| sed -i 's|<source>.*</source>|<source>.</source>|' tests/coverage.xml | |
| sed -i 's|filename="|filename="ardupilot_methodic_configurator/|g' tests/coverage.xml | |
| shell: bash | |
| - name: Display test results as GitHub job summary | |
| run: cat tests/results-${{ matrix.python-version }}.md >> $GITHUB_STEP_SUMMARY | |
| # Use always() to always run this step to publish test results when there are test failures | |
| if: ${{ always() }} | |
| - name: Upload coverage xml report | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: coverage-${{ matrix.python-version }}-xml | |
| path: tests/*.xml | |
| retention-days: 1 | |
| # Use always() to always run this step to publish test results when there are test failures | |
| if: ${{ always() }} | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: coverage-${{ matrix.python-version }} | |
| path: .coverage | |
| include-hidden-files: true | |
| retention-days: 1 | |
| # Use always() to always run this step to publish test results when there are test failures | |
| if: ${{ always() }} | |
| upload_coverage_to_coveralls: | |
| if: (github.event_name == 'push' && github.ref == 'refs/heads/master') && (success() || failure()) | |
| runs-on: ubuntu-latest | |
| needs: pytest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Download coverage xml report | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: coverage-3.9-xml | |
| - name: Upload coverage xml report to coveralls.io | |
| uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| files: coverage.xml | |
| # TODO: create a badge that presents the result of the Upload coverage xml report step | |
| check_coverage: | |
| if: success() || failure() | |
| runs-on: ubuntu-latest | |
| needs: pytest # This will ensure this job runs after 'pytest' | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Download coverage report | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: coverage-3.9 | |
| # https://docs.astral.sh/uv/guides/integration/github/ | |
| - name: Install uv and set the Python version | |
| uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 | |
| with: | |
| python-version: '3.9' # Match with the coverage report Python version | |
| activate-environment: true | |
| - name: Install dependencies | |
| run: | | |
| uv pip install .[dev] | |
| - name: Check coverage | |
| run: | | |
| # Check if pytest job failed | |
| if [ "${{ needs.pytest.result }}" == "failure" ]; then | |
| echo "Pytest failed - failing coverage check" | |
| exit 1 | |
| fi | |
| coverage report --fail-under=80 | |
| publish-test-results: | |
| if: always() | |
| name: "Publish Tests Results" | |
| runs-on: ubuntu-latest | |
| needs: pytest # This will ensure this job runs after 'pytest' | |
| permissions: | |
| checks: write | |
| # only needed unless run with comment_mode: off | |
| pull-requests: write | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Download Artifacts | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| path: artifacts | |
| - name: Publish Test Results | |
| uses: EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2.21.0 | |
| id: test-results | |
| with: | |
| files: "artifacts/**/results-junit.xml" | |
| - name: Set badge color | |
| shell: bash | |
| run: | | |
| case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in | |
| success) | |
| echo "BADGE_COLOR=31c653" >> $GITHUB_ENV | |
| ;; | |
| failure) | |
| echo "BADGE_COLOR=800000" >> $GITHUB_ENV | |
| ;; | |
| neutral) | |
| echo "BADGE_COLOR=696969" >> $GITHUB_ENV | |
| ;; | |
| esac | |
| - name: Create badge | |
| uses: emibcn/badge-action@808173dd03e2f30c980d03ee49e181626088eee8 | |
| with: | |
| label: Tests | |
| status: '${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests }} tests, ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.runs }} runs: ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}' | |
| color: ${{ env.BADGE_COLOR }} | |
| path: badge.svg | |
| - name: Upload badge to Gist | |
| # Upload only for master branch | |
| if: > | |
| github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'master' || | |
| github.event_name != 'workflow_run' && github.ref == 'refs/heads/master' | |
| uses: andymckay/append-gist-action@ab30bf28df67017c7ad696500b218558c7c04db3 | |
| with: | |
| token: ${{ secrets.GIST_TOKEN }} | |
| gistURL: https://gist.githubusercontent.com/amilcarlucas/81b511dc0ff92b8072613d1cd100832e | |
| file: badge.svg | |
| add_coverage_to_pullrequest: | |
| if: github.event_name == 'pull_request' && (success() || failure()) | |
| runs-on: ubuntu-latest | |
| needs: pytest # This will ensure this job runs after 'pytest' | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Download coverage xml report | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: coverage-3.9-xml | |
| - name: Get Cover | |
| uses: orgoro/coverage@3f13a558c5af7376496aa4848bf0224aead366ac # v3.2 | |
| with: | |
| coverageFile: coverage.xml | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| thresholdAll: 0.80 |