summaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: 3e7079ad931f4f1363d922d8e5268d8027710b79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Build

on:
  push:
    branches: [main]
    tags: ['v*']
  pull_request:
    branches: [main]
  workflow_dispatch:
env:
  LATEST_PY_VERSION: '3.11'
  PYTEST_VERBOSE: 'true'

jobs:
  # Run tests for each supported python version
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
      fail-fast: false
    services:
      nginx:
        image: kennethreitz/httpbin
        ports:
          - 80:80

    steps:
      # Set up python + poetry
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: snok/install-poetry@v1.3
        with:
          virtualenvs-in-project: true

      # Start integration test databases
      - uses: supercharge/mongodb-github-action@1.8.0
        with:
          mongodb-version: 5.0
      - uses: supercharge/redis-github-action@1.4.0
        with:
          redis-version: 6
      - uses: rrainn/dynamodb-action@v2.0.1

      # Cache packages per python version, and reuse until lockfile changes
      - name: Cache python packages
        id: cache
        uses: actions/cache@v3
        with:
          path: .venv
          key: venv-${{ matrix.python-version }}-latest-${{ hashFiles('poetry.lock') }}
      - name: Install dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: poetry install -v -E all

      # Run tests with coverage report
      - name: Run tests
        run: |
          source $VENV
          nox -e cov -- xml

      # Latest python version: send coverage report to codecov
      - name: "Upload coverage report to Codecov"
        if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
        uses: codecov/codecov-action@v3

  # Run code analysis checks via pre-commit hooks
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ env.LATEST_PY_VERSION }}
      - name: Run style checks & linting
        uses: pre-commit/action@v3.0.0