use logger.exception more, but disable rule forcing it over logger.error #1643
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
| name: "Pytest tests" | |
| on: | |
| push: | |
| branches: ["devel"] | |
| pull_request: | |
| branches: ["devel"] | |
| # Explicitly set read-only permissions for security | |
| permissions: | |
| contents: read | |
| jobs: | |
| pytest: | |
| runs-on: ubuntu-latest | |
| env: | |
| HAS_SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT != '' }} | |
| HAS_CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN != '' }} | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_DB: metrics_service | |
| POSTGRES_USER: metrics_service | |
| POSTGRES_PASSWORD: metrics_service | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - name: "Checkout repository" | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| # Explicitly checkout the PR HEAD (not the GitHub-created merge commit) so that | |
| # coverage.xml line numbers match exactly what sonar_checks.yml checks out via | |
| # `gh pr checkout`. Without this, files modified in devel after the PR was branched | |
| # will have different line counts between the coverage and the sonar scan. | |
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | |
| fetch-depth: 0 | |
| - name: "Install uv" | |
| uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 | |
| - name: "Set up Python" | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | |
| with: | |
| python-version-file: "pyproject.toml" | |
| - name: "Remove stale coverage report" | |
| run: rm -f coverage.xml .coverage | |
| - name: "Run pytest" | |
| env: | |
| METRICS_SERVICE_DATABASES__default__HOST: localhost | |
| METRICS_SERVICE_DATABASES__default__PORT: 5432 | |
| METRICS_SERVICE_DATABASES__default__USER: metrics_service | |
| METRICS_SERVICE_DATABASES__default__PASSWORD: metrics_service | |
| METRICS_SERVICE_DATABASES__default__NAME: metrics_service | |
| METRICS_SERVICE_DATABASES__default__OPTIONS__sslmode: disable | |
| METRICS_SERVICE_DATABASES__awx__HOST: "127.0.0.1" | |
| METRICS_SERVICE_DATABASES__awx__PASSWORD: mypassword | |
| DJANGO_SETTINGS_MODULE: metrics_service.settings | |
| METRICS_SERVICE_MODE: test | |
| run: | | |
| uv run pytest -s -v --cov --cov-branch --cov-report=xml | |
| - name: "Upload code coverage report" | |
| if: github.event_name == 'pull_request' && env.HAS_SONAR_TOKEN == 'true' | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: coverage-report | |
| path: coverage.xml | |
| - name: "Save off PR number" | |
| if: github.event_name == 'pull_request' && env.HAS_SONAR_TOKEN == 'true' | |
| env: | |
| PR_NUM: ${{ github.event.pull_request.number }} | |
| run: echo "PR $PR_NUM" > pr_number.txt | |
| - name: "Upload PR number" | |
| if: github.event_name == 'pull_request' && env.HAS_SONAR_TOKEN == 'true' | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: pr_number | |
| path: pr_number.txt | |
| - name: "Send code coverage report to SonarCloud (on push)" | |
| if: github.event_name == 'push' && env.HAS_SONAR_TOKEN == 'true' | |
| uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0 | |
| env: | |
| SONAR_HOST_URL: https://sonarcloud.io | |
| SONAR_ORGANIZATION: ansible | |
| SONAR_PROJECT_KEY: ansible_metrics-service | |
| SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }} | |
| with: | |
| projectBaseDir: . | |
| args: > | |
| -Dsonar.python.coverage.reportPaths=coverage.xml | |
| - name: Upload coverage reports to Codecov | |
| if: env.HAS_CODECOV_TOKEN == 'true' | |
| uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: coverage.xml | |
| flags: unit-tests | |
| fail_ci_if_error: false | |
| verbose: true |