Address PR review comments: fix type hints and remove unused variables #3036
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
| # This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
| # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
| name: Run tests | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| workflow_call: | |
| inputs: | |
| PERIODIC_CHECKS: | |
| description: "Boolean flag to diferentiate periodic checks" | |
| required: true | |
| type: string | |
| CLARIFAI_ENV: | |
| description: "Set the environment to run the tests" | |
| required: true | |
| type: string | |
| CLARIFAI_GRPC_BASE: | |
| description: "gRPC Base URL" | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 20 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| python-version: | |
| - '3.12' | |
| - '3.11' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install uv | |
| uv venv | |
| uv pip install -r requirements.txt -r tests/requirements.txt genbadge[coverage] | |
| - name: Run static analysis lint | |
| uses: pre-commit/[email protected] | |
| - name: Check if Dockerfile.template changed | |
| id: check_dockerfile_change | |
| shell: bash | |
| run: | | |
| # We compare the files changed between the previous commit SHA (github.event.before) | |
| # and the current commit SHA (github.event.after). | |
| # If Dockerfile.template is in that list, we set changed=true | |
| if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -q 'clarifai/runners/dockerfile_template/Dockerfile.template'; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Prepare the API keys & Run pytest | |
| env: | |
| CLARIFAI_USER_EMAIL_SECURE_HOSTING: ${{ secrets.CLARIFAI_USER_EMAIL_SECURE_HOSTING }} | |
| CLARIFAI_USER_EMAIL: ${{ secrets.INTERNAL_USER_EMAIL }} | |
| CLARIFAI_USER_PASSWORD: ${{ secrets.INTERNAL_USER_PASSWORD }} | |
| shell: bash | |
| run: | | |
| if [ "${{ inputs.PERIODIC_CHECKS }}" = "true" ]; then | |
| export CLARIFAI_ENV="${{ inputs.CLARIFAI_ENV }}" | |
| export CLARIFAI_GRPC_BASE="${{ inputs.CLARIFAI_GRPC_BASE }}" | |
| export CLARIFAI_API_BASE="https://${{ inputs.CLARIFAI_GRPC_BASE }}" # CLARIFAI_GRPC_BASE is used by the gRPC channel | |
| else | |
| export CLARIFAI_ENV="prod" | |
| export CLARIFAI_GRPC_BASE="api.clarifai.com" | |
| export CLARIFAI_API_BASE="https://api.clarifai.com" # CLARIFAI_GRPC_BASE is used by the gRPC channel | |
| fi | |
| export PYTHONPATH=. | |
| export CLARIFAI_USER_ID="$(uv run python scripts/key_for_tests.py --get-userid)" | |
| export CLARIFAI_PAT="$(uv run python scripts/key_for_tests.py --create-pat)" | |
| if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then | |
| # Run coverage for all but the container test | |
| uv run pytest --cov=. --cov-report=xml:coverage/coverage.cobertura.xml --ignore=tests/runners/test_model_run_locally-container.py | |
| # Conditionally run the container test | |
| if [ "${{ steps.check_dockerfile_change.outputs.changed }}" = "true" ]; then | |
| uv run pytest --cov=. --cov-append --cov-report=xml:coverage/coverage.cobertura.xml tests/runners/test_model_run_locally-container.py | |
| fi | |
| elif [ "${{ inputs.PERIODIC_CHECKS }}" = "true" ]; then | |
| uv run pytest -m "not coverage_only" --cov=. --cov-report=xml:coverage/coverage.cobertura.xml --ignore=tests/runners/test_model_run_locally-container.py | |
| if [ "${{ steps.check_dockerfile_change.outputs.changed }}" = "true" ]; then | |
| uv run pytest -m "not coverage_only" --cov=. --cov-append --cov-report=xml:coverage/coverage.cobertura.xml tests/runners/test_model_run_locally-container.py | |
| fi | |
| else | |
| uv run pytest -m "not requires_secrets" --cov=. --cov-report=xml:coverage/coverage.cobertura.xml --ignore=tests/runners/test_model_run_locally-container.py | |
| if [ "${{ steps.check_dockerfile_change.outputs.changed }}" = "true" ]; then | |
| uv run pytest -m "not requires_secrets" --cov=. --cov-append --cov-report=xml:coverage/coverage.cobertura.xml tests/runners/test_model_run_locally-container.py | |
| fi | |
| fi | |
| - name: Code Coverage Report | |
| if: runner.os == 'Linux' && matrix.python-version == '3.11' | |
| uses: irongut/[email protected] | |
| with: | |
| filename: coverage/**/coverage.cobertura.xml | |
| badge: true | |
| fail_below_min: true | |
| format: markdown | |
| hide_branch_rate: false | |
| hide_complexity: true | |
| indicators: true | |
| output: both | |
| thresholds: '50 80' | |
| - name: Add Coverage PR Comment | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: github.event_name == 'pull_request' && runner.os == 'Linux' && matrix.python-version == '3.11' | |
| with: | |
| recreate: true | |
| path: code-coverage-results.md |