MAKENTNU/web

View on GitHub
.github/workflows/python.yml

Summary

Maintainability
Test Coverage
name: build

on: [ push, pull_request ]

jobs:
  test:
    name: Python ${{ matrix.python-version }}
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [ "3.10", "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*.txt"

      - name: Install System Dependencies
        # Retries installing files 3 times, as the GitHub Actions CI is occasionally unreliable
        run: |
          sudo apt update
          sudo apt install python3-dev libldap2-dev libsasl2-dev libssl-dev -o Acquire::Retries=3

      - name: Install Python Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install -r requirements_codecov.txt

      - name: Run Django Tests
        run: |
          python manage.py collectstatic --no-input
          coverage run manage.py test
          coverage xml

      - name: Upload to Codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          file: ./coverage.xml

  # Based on https://github.com/orgs/community/discussions/26822#discussioncomment-5122101
  test-results:
    name: Tests passed
    runs-on: ubuntu-latest
    needs: [test]
    if: ${{ always() }}

    steps:
      - if: >- # Starts a multiline string (see https://stackoverflow.com/a/67532120)
          ${{
               contains(needs.*.result, 'failure')
            || contains(needs.*.result, 'cancelled')
          }}
        run: exit 1