| # Prior to releases, this will run additional stress tests, plus tests for all supported versions of |
| # the requests library. Expected runtime is upwards of 20mins depending on runner availability, |
| # which is why these are only run for releases. |
| name: Deploy |
| |
| on: |
| push: |
| tags: ['v*'] |
| workflow_dispatch: |
| inputs: |
| pre-release-suffix: |
| description: 'Version suffix for pre-releases ("a", "b", "rc", etc.)' |
| required: false |
| default: 'dev' |
| pre-release-version: |
| description: 'Version number for pre-releases; defaults to build number' |
| required: false |
| default: '' |
| skip-stress: |
| description: 'Set to "true" to skip stress tests' |
| required: false |
| default: 'false' |
| skip-publish: |
| description: 'Set to "true" to skip publishing to PyPI' |
| required: false |
| default: 'false' |
| |
| env: |
| LATEST_PY_VERSION: '3.11' |
| PYTEST_VERBOSE: 'true' |
| STRESS_TEST_MULTIPLIER: 7 |
| |
| jobs: |
| |
| # Run additional integration stress tests |
| test-stress: |
| if: ${{ github.event.inputs.skip-stress != 'true' }} |
| runs-on: ubuntu-latest |
| |
| 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: ${{ env.LATEST_PY_VERSION }} |
| - uses: snok/install-poetry@v1.3 |
| with: |
| virtualenvs-in-project: true |
| |
| # Start integration test databases |
| - uses: supercharge/mongodb-github-action@1.9.0 |
| with: |
| mongodb-version: 5.0 |
| - uses: supercharge/redis-github-action@1.5.0 |
| with: |
| redis-version: 6 |
| - uses: rrainn/dynamodb-action@v3.0.0 |
| |
| # 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-${{ env.LATEST_PY_VERSION }}-latest-${{ hashFiles('poetry.lock') }} |
| - name: Install dependencies |
| if: steps.cache.outputs.cache-hit != 'true' |
| run: poetry install -v -E all |
| |
| # Run tests |
| - name: Run stress tests |
| run: | |
| source $VENV |
| nox -e stress -- ${{ env.STRESS_TEST_MULTIPLIER }} |
| |
| # Run unit tests without any optional dependencies installed |
| test-minimum-deps: |
| runs-on: ubuntu-latest |
| |
| steps: |
| # Set up python + poetry |
| - uses: actions/checkout@v3 |
| - uses: actions/setup-python@v4 |
| with: |
| python-version: ${{ env.LATEST_PY_VERSION }} |
| - uses: snok/install-poetry@v1.3 |
| with: |
| virtualenvs-in-project: true |
| |
| # 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-minimum-deps-${{ hashFiles('poetry.lock') }} |
| - name: Install dependencies |
| if: steps.cache.outputs.cache-hit != 'true' |
| run: poetry install -v |
| |
| # Run tests |
| - name: Run tests with no optional dependencies |
| run: | |
| source $VENV |
| pytest -n auto tests/unit |
| |
| # Run unit tests for all supported platforms, python versions, and requests versions |
| test: |
| strategy: |
| matrix: |
| os: [ubuntu-latest, macos-latest, windows-latest] |
| python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.9'] |
| requests-version: [2.22, 2.23, 2.24, 2.25, 2.26, 2.27, latest] |
| exclude: |
| - os: windows-latest |
| python-version: 'pypy3.9' |
| fail-fast: false |
| defaults: |
| run: |
| shell: bash |
| runs-on: ${{ matrix.os }} |
| |
| 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 |
| |
| # 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.os }}-${{ matrix.python-version }}-${{ matrix.requests-version }}-${{ hashFiles('poetry.lock') }} |
| - name: Install dependencies |
| if: steps.cache.outputs.cache-hit != 'true' |
| run: | |
| poetry add requests@${{ matrix.requests-version }} --lock |
| poetry install -v -E all |
| |
| # Run tests |
| - name: Run tests |
| run: poetry run pytest -n auto tests/unit |
| |
| # Deploy stable builds on tags only, and pre-release builds from manual trigger ("workflow_dispatch") |
| release: |
| if: ${{ github.event.inputs.skip-publish != 'true' }} |
| needs: [test, test-minimum-deps] |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v3 |
| - uses: actions/setup-python@v4 |
| with: |
| python-version: ${{ env.LATEST_PY_VERSION }} |
| - uses: snok/install-poetry@v1.3 |
| with: |
| virtualenvs-in-project: true |
| |
| - name: Set pre-release version |
| if: ${{ !startsWith(github.ref, 'refs/tags/v') }} |
| env: |
| pre-release-suffix: ${{ github.event.inputs.pre-release-suffix || 'dev' }} |
| pre-release-version: ${{ github.event.inputs.pre-release-version || github.run_number }} |
| run: | |
| poetry version $(poetry version -s).${{ env.pre-release-suffix }}${{ env.pre-release-version }} |
| poetry version |
| |
| - name: Build and publish to PyPI |
| run: | |
| poetry build |
| poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }} |