|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +env: |
| 10 | + LINES: 120 |
| 11 | + COLUMNS: 120 |
| 12 | + |
| 13 | +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun |
| 14 | +defaults: |
| 15 | + run: |
| 16 | + shell: bash --noprofile --norc -exo pipefail {0} |
| 17 | + |
| 18 | +jobs: |
| 19 | + diff: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + related: ${{ steps.filter.outputs.related }} |
| 23 | + belar: ${{ steps.filter.outputs.belar }} |
| 24 | + docs: ${{ steps.filter.outputs.docs }} |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v3 |
| 27 | + - uses: dorny/paths-filter@v2 |
| 28 | + id: filter |
| 29 | + with: |
| 30 | + base: "main" |
| 31 | + token: ${{ github.token }} |
| 32 | + filters: | |
| 33 | + related: &related |
| 34 | + - .github/workflows/ci.yml |
| 35 | + - codecov.yml |
| 36 | + - pyproject.toml |
| 37 | + - requirements/test.txt |
| 38 | + belar: |
| 39 | + - "belar/**" |
| 40 | + - "tests/**" |
| 41 | + - "examples/**" |
| 42 | + docs: |
| 43 | + - *related |
| 44 | + - requirements/docs-requirements.txt |
| 45 | + - "docs/**" |
| 46 | +
|
| 47 | + unit_tests: |
| 48 | + needs: |
| 49 | + - diff |
| 50 | + |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 55 | + python-version: ["3.7", "3.8", "3.9", "3.10"] |
| 56 | + |
| 57 | + if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.belar == 'true') || github.event_name == 'push' }} |
| 58 | + name: python${{ matrix.python-version }}_unit_tests (${{ matrix.os }}) |
| 59 | + runs-on: ${{ matrix.os }} |
| 60 | + |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v3 |
| 63 | + with: |
| 64 | + fetch-depth: 0 # fetch all tags and branches |
| 65 | + |
| 66 | + - name: Setup python |
| 67 | + uses: actions/setup-python@v4 |
| 68 | + with: |
| 69 | + python-version: ${{ matrix.python-version }} |
| 70 | + architecture: x64 |
| 71 | + |
| 72 | + - name: Get pip cache dir |
| 73 | + id: cache-dir |
| 74 | + run: | |
| 75 | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + - name: Cache pip dependencies |
| 78 | + uses: actions/cache@v3 |
| 79 | + id: cache-pip |
| 80 | + with: |
| 81 | + path: ${{ steps.cache-dir.outputs.dir }} |
| 82 | + key: ${{ runner.os }}-tests-${{ hashFiles('requirements/test.txt') }} |
| 83 | + |
| 84 | + - name: Install dependencies |
| 85 | + run: | |
| 86 | + pip install "." |
| 87 | + pip install -r requirements/test.txt |
| 88 | +
|
| 89 | + - name: Run unit tests |
| 90 | + run: | |
| 91 | + # OPTS=(--cov-config pyproject.toml --cov=src/bentoml --cov-append) |
| 92 | + if [ "${{ matrix.os }}" != 'windows-latest' ]; then |
| 93 | + # we will use pytest-xdist to improve tests run-time. |
| 94 | + OPTS=(--dist loadfile -n auto) |
| 95 | + fi |
| 96 | + # Now run the unit tests |
| 97 | + pytest tests/unit "${OPTS[@]}" |
| 98 | +
|
| 99 | + codestyle_check: |
| 100 | + runs-on: ubuntu-latest |
| 101 | + needs: |
| 102 | + - diff |
| 103 | + |
| 104 | + if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.belar == 'true') || github.event_name == 'push' }} |
| 105 | + |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v3 |
| 108 | + |
| 109 | + - name: Setup python |
| 110 | + uses: actions/setup-python@v4 |
| 111 | + with: |
| 112 | + python-version: "3.10.6" |
| 113 | + architecture: x64 |
| 114 | + |
| 115 | + - name: Get pip cache dir |
| 116 | + id: cache-dir |
| 117 | + run: | |
| 118 | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT |
| 119 | +
|
| 120 | + - name: Fetch origin |
| 121 | + run: git fetch origin "$GITHUB_BASE_REF" |
| 122 | + |
| 123 | + - name: Setup node |
| 124 | + uses: actions/setup-node@v3 |
| 125 | + with: |
| 126 | + node-version: "17" |
| 127 | + |
| 128 | + - name: Cache pip dependencies |
| 129 | + uses: actions/cache@v3 |
| 130 | + id: cache-pip |
| 131 | + with: |
| 132 | + path: ${{ steps.cache-dir.outputs.dir }} |
| 133 | + key: codestyle-${{ hashFiles('requirements/dev.txt') }} |
| 134 | + |
| 135 | + - name: Install dependencies |
| 136 | + run: | |
| 137 | + pip install . |
| 138 | + pip install -r requirements/dev.txt |
| 139 | +
|
| 140 | + - name: Format check |
| 141 | + run: | |
| 142 | + make format |
| 143 | + - name: Lint check |
| 144 | + run: make lint |
| 145 | + - name: Type check |
| 146 | + if: ${{ github.event_name == 'pull_request' }} |
| 147 | + run: git diff --name-only --diff-filter=AM "origin/$GITHUB_BASE_REF" -z -- '**/*.py' '**/*.pyi' | xargs -0 --no-run-if-empty pyright |
0 commit comments