Skip to content

CI

CI #969

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 0 * * 1/2'
env:
LINES: 120
COLUMNS: 120
BENTOML_DO_NOT_TRACK: True
PYTEST_PLUGINS: bentoml.testing.pytest.plugin
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun
defaults:
run:
shell: bash --noprofile --norc -exo pipefail {0}
jobs:
diff:
runs-on: ubuntu-latest
outputs:
related: ${{ steps.filter.outputs.related }}
bentoml: ${{ steps.filter.outputs.bentoml }}
docs: ${{ steps.filter.outputs.docs }}
protos: ${{ steps.filter.outputs.protos }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: filter
with:
base: 'main'
filters: |
related: &related
- .github/workflows/ci.yml
- codecov.yml
- pyproject.toml
- requirements/tests-requirements.txt
protos: &protos
- "src/bentoml/grpc/**/*.proto"
bentoml:
- *protos
- *related
- "src/bentoml/**"
- "src/bentoml_cli/**"
- "tests/**"
- "examples/**"
docs:
- *related
- requirements/docs-requirements.txt
- "docs/**"
codestyle_check:
runs-on: ubuntu-latest
needs:
- diff
if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.bentoml == 'true') || github.event_name == 'push' }}
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.10.6'
architecture: x64
- name: Get pip cache dir
id: cache-dir
run: |
echo ::set-output name=dir::$(pip cache dir)
- name: Fetch origin
run: git fetch origin "$GITHUB_BASE_REF"
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '17'
- name: Install pyright
run: |
npm install -g npm@^7 pyright
- name: Setup bufbuild/buf
uses: bufbuild/buf-setup-action@v1.19.0
with:
github_token: ${{ github.token }}
- name: Cache pip dependencies
uses: actions/cache@v3
id: cache-pip
with:
path: ${{ steps.cache-dir.outputs.dir }}
key: codestyle-${{ hashFiles('requirements/dev-requirements.txt') }}
- name: Install dependencies
run: |
pip install .
pip install pre-commit
- name: Format and lint check
run: pre-commit run --all-files
- name: Type check
if: ${{ github.event_name == 'pull_request' }}
run: git diff --name-only --diff-filter=AM "origin/$GITHUB_BASE_REF" -z -- '*.py{,i}' | xargs -0 --no-run-if-empty pyright
- name: Proto check
if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.protos == 'true') || github.event_name == 'push' }}
run: |
buf lint --config "src/bentoml/grpc/buf.yaml" --error-format msvs src
documentation_spelling_check:
runs-on: ubuntu-latest
needs:
- diff
if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.docs == 'true') || github.event_name == 'push' }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all tags and branches
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Get pip cache dir
id: cache-dir
run: |
echo ::set-output name=dir::$(pip cache dir)
- name: Cache pip dependencies
uses: actions/cache@v3
id: cache-pip
with:
path: ${{ steps.cache-dir.outputs.dir }}
key: ${{ runner.os }}-docs-${{ hashFiles('requirements/docs-requirements.txt') }}
- name: Install dependencies
run: |
pip install .
pip install -r requirements/docs-requirements.txt
- name: Install libenchant
run: |
sudo apt-get update && sudo apt-get install -y libenchant-2-dev
- name: Run spellcheck script
run: make spellcheck-docs
unit_tests:
needs:
- diff
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.bentoml == 'true') || github.event_name == 'push' }}
name: python${{ matrix.python-version }}_unit_tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all tags and branches
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Get pip cache dir
id: cache-dir
run: |
echo ::set-output name=dir::$(pip cache dir)
- name: Cache pip dependencies
uses: actions/cache@v3
id: cache-pip
with:
path: ${{ steps.cache-dir.outputs.dir }}
key: ${{ runner.os }}-tests-${{ hashFiles('requirements/tests-requirements.txt') }}
- name: Install dependencies
run: |
pip install ".[grpc]"
pip install -r requirements/tests-requirements.txt
- name: Run unit tests
run: |
OPTS=(--cov-config pyproject.toml --cov=src/bentoml --cov-append)
if [ "${{ matrix.os }}" != 'windows-latest' ]; then
# we will use pytest-xdist to improve tests run-time.
OPTS=(${OPTS[@]} --dist loadfile -n auto --run-grpc-tests)
fi
# Now run the unit tests
coverage run -m pytest tests/unit "${OPTS[@]}"
bento_server_e2e_tests:
needs:
- diff
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
server_type: ['http', 'grpc']
exclude:
- os: windows-latest
server_type: 'grpc'
- os: macos-latest
server_type: 'grpc'
python-version: '3.10'
- python-version: '3.11'
# NOTE: Remove tests on 3.11 for gRPC for now, as it needs more investigation
server_type: 'grpc'
if: ${{ (github.event_name == 'pull_request' && needs.diff.outputs.bentoml == 'true') || github.event_name == 'push' }}
name: python${{ matrix.python-version }}_${{ matrix.server_type }}_e2e_tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 20
env:
SETUPTOOLS_USE_DISTUTILS: stdlib
BENTOML_BUNDLE_LOCAL_BUILD: True
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all tags and branches
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Set up Docker Buildx
if: ${{ matrix.os == 'ubuntu-latest' }}
id: buildx
uses: docker/setup-buildx-action@v2
- name: Get pip cache dir
id: cache-dir
run: |
echo ::set-output name=dir::$(pip cache dir)
- name: Cache pip dependencies
uses: actions/cache@v3
id: cache-pip
with:
path: ${{ steps.cache-dir.outputs.dir }}
key: ${{ runner.os }}-tests-${{ hashFiles('requirements/tests-requirements.txt') }}
- name: Install dependencies for ${{ matrix.server_type }}-based tests.
run: |
pip install -r requirements/tests-requirements.txt
if [ "${{ matrix.server_type }}" == 'grpc' ]; then
pip install -e ".[grpc]"
else
pip install -e .
fi
if [ -f "tests/e2e/bento_server_${{ matrix.server_type }}/requirements.txt" ]; then
pip install -r tests/e2e/bento_server_${{ matrix.server_type }}/requirements.txt
fi
- name: Run ${{ matrix.server_type }} tests and generate coverage report
run: |
OPTS=(--cov-config pyproject.toml --cov=src/bentoml --cov-append)
coverage run -m pytest tests/e2e/bento_server_${{ matrix.server_type }} "${OPTS[@]}"
concurrency:
group: ci-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true