summaryrefslogtreecommitdiff
path: root/.github/workflows/deploy.yml
blob: 8bdb89f7a99bfbf539db4f272c9b2dc8e329e9f2 (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
# 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: ''

env:
  LATEST_PY_VERSION: 3.9

jobs:
  # Run tests for all supported requests versions
  test:
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        python-version: [3.7]
        requests-version: [2.22, 2.23, 2.24, 2.25, latest]
      fail-fast: false
    services:
      nginx:
        image: kennethreitz/httpbin
        ports:
          - 80:80

    steps:
      # Set up python + poetry
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - uses: snok/install-poetry@v1.1.7
        with:
          version: 1.2.0a2
          virtualenvs-in-project: true

      # 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 lockfile changes
      - name: Cache python packages
        id: cache
        uses: actions/cache@v2
        with:
          path: .venv
          key: venv-${{ 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 unit + integration tests, with additional stress tests
      - name: Run tests
        run: |
          source $VENV
          pytest --numprocesses=auto tests/unit
          pytest tests/integration
          STRESS_TEST_MULTIPLIER=5 pytest tests/integration/ -k 'multithreaded'

  # Deploy stable builds on tags only, and pre-release builds from manual trigger ("workflow_dispatch")
  release:
    needs: [test]
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: ${{ env.LATEST_PY_VERSION }}
      - uses: snok/install-poetry@v1.1.7
        with:
          version: 1.2.0a2
          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 }}