|
| 1 | +name: "CI" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ci-${{ github.head_ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + commits: |
| 14 | + name: "Commits" |
| 15 | + if: ${{ github.event_name == 'pull_request' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: "Checkout code" |
| 19 | + uses: actions/checkout@v2 |
| 20 | + with: |
| 21 | + ref: ${{ github.event.pull_request.head.sha }} |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: "Check commits of the PR branch" |
| 25 | + run: ./.github/check_commits.sh |
| 26 | + |
| 27 | + linters: |
| 28 | + name: "Linters" |
| 29 | + needs: commits |
| 30 | + if: ${{ !failure() }} |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: "Checkout code" |
| 34 | + uses: actions/checkout@v2 |
| 35 | + |
| 36 | + - name: "Set up Python" |
| 37 | + id: setup-python |
| 38 | + uses: actions/setup-python@v2 |
| 39 | + with: |
| 40 | + python-version: '3.7' |
| 41 | + |
| 42 | + - name: "Install Poetry" |
| 43 | + uses: snok/install-poetry@5e4414407e59f94f2148bcb253917dfc22dee7d9 # v1.3.0 |
| 44 | + with: |
| 45 | + virtualenvs-create: true |
| 46 | + virtualenvs-in-project: true |
| 47 | + |
| 48 | + - name: "Load cached venv" |
| 49 | + id: cached-poetry-dependencies |
| 50 | + uses: actions/cache@v2 |
| 51 | + with: |
| 52 | + path: .venv |
| 53 | + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 54 | + |
| 55 | + - name: "Install dependencies" |
| 56 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 57 | + run: poetry install --no-root |
| 58 | + |
| 59 | + - name: "Run linters" |
| 60 | + run: | |
| 61 | + source "$VENV" |
| 62 | + isort --check-only --diff . |
| 63 | + flake8 . |
| 64 | + black --check --diff . |
| 65 | +
|
| 66 | + build: |
| 67 | + name: "Build" |
| 68 | + needs: commits |
| 69 | + if: ${{ !failure() }} |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - name: "Checkout code" |
| 73 | + uses: actions/checkout@v2 |
| 74 | + |
| 75 | + - name: "Set up Python" |
| 76 | + id: setup-python |
| 77 | + uses: actions/setup-python@v2 |
| 78 | + with: |
| 79 | + python-version: '3.7' |
| 80 | + |
| 81 | + - name: "Install Poetry" |
| 82 | + uses: snok/install-poetry@5e4414407e59f94f2148bcb253917dfc22dee7d9 # v1.3.0 |
| 83 | + with: |
| 84 | + virtualenvs-create: true |
| 85 | + virtualenvs-in-project: true |
| 86 | + |
| 87 | + - name: "Build the wheel" |
| 88 | + run: poetry build |
| 89 | + |
| 90 | + - name: "Install from the wheel" |
| 91 | + run: pip install dist/*.whl |
| 92 | + |
| 93 | + tests: |
| 94 | + name: "Tests" |
| 95 | + needs: [linters, build] |
| 96 | + strategy: |
| 97 | + fail-fast: true |
| 98 | + matrix: |
| 99 | + python-version: ['3.7', '3.8', '3.9', '3.10'] |
| 100 | + |
| 101 | + runs-on: ubuntu-latest |
| 102 | + steps: |
| 103 | + - name: "Checkout code" |
| 104 | + uses: actions/checkout@v2 |
| 105 | + |
| 106 | + - name: "Set up Python ${{ matrix.python-version }}" |
| 107 | + id: setup-python |
| 108 | + uses: actions/setup-python@v2 |
| 109 | + with: |
| 110 | + python-version: ${{ matrix.python-version }} |
| 111 | + |
| 112 | + - name: "Install Poetry" |
| 113 | + uses: snok/install-poetry@5e4414407e59f94f2148bcb253917dfc22dee7d9 # v1.3.0 |
| 114 | + with: |
| 115 | + virtualenvs-create: true |
| 116 | + virtualenvs-in-project: true |
| 117 | + |
| 118 | + - name: "Load cached venv" |
| 119 | + id: cached-poetry-dependencies |
| 120 | + uses: actions/cache@v2 |
| 121 | + with: |
| 122 | + path: .venv |
| 123 | + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 124 | + |
| 125 | + - name: "Install dependencies" |
| 126 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 127 | + run: poetry install --no-root |
| 128 | + |
| 129 | + - name: "Install the package" |
| 130 | + run: poetry install |
| 131 | + |
| 132 | + - name: "Run type-checking" |
| 133 | + run: | |
| 134 | + source "$VENV" |
| 135 | + mypy . |
| 136 | +
|
| 137 | + - name: "Run tests" |
| 138 | + run: | |
| 139 | + source "$VENV" |
| 140 | + pytest --verbose --cov=. --cov-report=xml . |
| 141 | +
|
| 142 | + - name: "Upload coverage" |
| 143 | + if: matrix.python-version == '3.7' |
| 144 | + uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 |
| 145 | + with: |
| 146 | + files: coverage.xml |
0 commit comments