name: Build on: push: branches: [master, dev] tags: ['v*'] pull_request: branches: [master, dev] workflow_dispatch: env: LATEST_PY_VERSION: '3.9' COVERAGE_ARGS: '--cov --cov-report=term --cov-report=html' jobs: # Run unit tests for each supported python version test: runs-on: ubuntu-18.04 strategy: matrix: python-version: [3.6, 3.7, 3.8, 3.9] services: nginx: image: kennethreitz/httpbin ports: - 80:80 steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} # Start integration test databases - uses: supercharge/mongodb-github-action@1.3.0 with: mongodb-version: 4.4 - uses: supercharge/redis-github-action@1.2.0 with: redis-version: 6 - uses: rrainn/dynamodb-action@v2.0.0 # Cache packages per python version, and reuse until setup.py changes - name: Cache pip packages uses: actions/cache@v2 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} restore-keys: ${{ runner.os }}-pip-${{ matrix.python-version }} - name: Install dependencies run: pip install ".[dev]" # Latest python version: Run tests with coverage and send to coveralls - name: Run tests with code coverage report if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} # Run unit tests first (and with multiprocessing) to fail quickly if there are issues run: | pytest tests/unit --numprocesses=auto ${{ env.COVERAGE_ARGS }} pytest tests/integration --cov-append ${{ env.COVERAGE_ARGS }} - name: Send code coverage report to Coveralls if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: coveralls --service=github # All other python versions: just run tests - name: Run tests if: ${{ matrix.python-version != env.LATEST_PY_VERSION }} run: | pytest --numprocesses=auto tests/unit pytest tests/integration # Run longer stress tests if this is a release or merge to master - name: Run stress tests if: startsWith(github.ref, 'refs/tags/v') || endsWith(github.ref, '/master') run: STRESS_TEST_MULTIPLIER=5 pytest tests/integration/ -k 'multithreaded' # Run code analysis checks analyze: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ env.LATEST_PY_VERSION }} # Cache packages for latest python version, and reuse until setup.py changes - name: Cache pip packages uses: actions/cache@v2 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ env.LATEST_PY_VERSION }}-${{ hashFiles('setup.py') }} restore-keys: ${{ runner.os }}-pip-${{ env.LATEST_PY_VERSION }} - name: Install dependencies run: pip install ".[dev]" - name: Run linter run: flake8 . - name: Run code style checks run: | black --check --diff . isort --check --diff . - name: Run cyclomatic complexity check run: radon cc --show-complexity --average --order SCORE requests_cache # Deploy pre-release builds from dev branch, and stable builds on tags only release: needs: [test, analyze] if: startsWith(github.ref, 'refs/tags/v') || endsWith(github.ref, '/dev') runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ env.LATEST_PY_VERSION }} - name: Install dependencies run: pip install -U ".[build]" - name: Build wheel run: python setup.py sdist bdist_wheel - name: Deploy to pypi env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} run: twine upload dist/*