summaryrefslogtreecommitdiff
path: root/.github/workflows/deploy.yml
blob: c627762de0ce07563a69423b393122ca411d0ece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# 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.8.0
        with:
          mongodb-version: 5.0
      - uses: supercharge/redis-github-action@1.4.0
        with:
          redis-version: 6
      - uses: rrainn/dynamodb-action@v2.0.1

      # 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, test-stress]
    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 }}