byceps/byceps

View on GitHub
.github/workflows/test.yml

Summary

Maintainability
Test Coverage
name: Test

on:
  push:
    branches: [ main ]
    paths-ignore:
      - 'docs/**'
      - '*.rst'
  pull_request:
    branches: [ main ]
    paths-ignore:
      - 'docs/**'
      - '*.rst'
  # Allow manual workflow triggering from the "Actions" tab.
  workflow_dispatch:

jobs:
  test:

    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres
        env:
          POSTGRES_USER: byceps_test
          POSTGRES_PASSWORD: test
          POSTGRES_DB: byceps_test
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Make accessible on localhost.
          - 5432:5432

      redis:
        image: redis
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Make accessible on localhost.
          - 6379:6379

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11"]

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'
        cache-dependency-path: 'requirements/core.txt'

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip wheel
        python -m pip install -r requirements/core.txt -r requirements/test.txt

    - name: Install BYCEPS
      run: |
        python -m pip install -e .

    - name: Download binary for test coverage reporting to Code Climate
      if: github.repository == 'byceps/byceps' && github.ref_name == 'main'
      run: |
        curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
        chmod +x ./cc-test-reporter

    - name: Notify Code Climate of a pending test coverage report
      if: github.repository == 'byceps/byceps' && github.ref_name == 'main'
      run: |
        ./cc-test-reporter before-build

    - name: Test with pytest and coverage
      run: |
        coverage run --source=byceps -m pytest tests

    - name: Generate XML output from test coverage
      if: github.repository == 'byceps/byceps' && github.ref_name == 'main'
      run: |
        coverage xml

    - name: Notify Code Climate of a completed test run
      if: github.repository == 'byceps/byceps' && github.ref_name == 'main'
      env:
        CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
      run: |
        ./cc-test-reporter after-build

    - name: Post result to Discord
      # Run job even if build is cancelled.
      if: always() && github.repository == 'byceps/byceps' && github.ref_name == 'main'
      env:
        JOB_RESULT: ${{ job.status }}
        DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
      run: python ./.github/workflows/send-workflow-result-to-discord.py $JOB_RESULT $DISCORD_WEBHOOK_URL