summaryrefslogtreecommitdiff
path: root/.github/workflows/tests.yml
blob: ecbb9bbaa2ff4f6abfa982eeb40c593442cf4c9d (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: tests

on: [push, pull_request]

env:
  PYTHONHASHSEED: 1042466059
  ZOPE_INTERFACE_STRICT_IRO: 1
  PYTHONUNBUFFERED: 1
  PYTHONDONTWRITEBYTECODE: 1
  PYTHONDEVMODE: 1
  PYTHONFAULTHANDLER: 1
  PIP_UPGRADE_STRATEGY: eager
  # Don't get warnings about Python 2 support being deprecated. We
  # know. The env var works for pip 20.
  PIP_NO_PYTHON_VERSION_WARNING: 1
  PIP_NO_WARN_SCRIPT_LOCATION: 1
  # Uploading built wheels for releases.
  # TWINE_PASSWORD is encrypted and stored directly in the
  # repo settings.
  TWINE_USERNAME: __token__


jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
        os: [ubuntu-latest, macos-latest]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Pip cache
      uses: actions/cache@v2
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('setup.*') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - name: Install dependencies
      run: |
        python -m pip install -U pip setuptools wheel
        python -m pip install -U twine
        python -m pip install -q -U 'faulthandler; python_version == "2.7" and platform_python_implementation == "CPython"'
    - name: Install greenlet
      run: |
        python setup.py bdist_wheel
        python -m pip install -U -e ".[test,docs]"
      env:
        # Ensure we test with assertions enabled.
        # As opposed to the manylinux builds, which we distribute and
        # thus only use O3 (because Ofast enables fast-math, which has
        # process-wide effects), we test with Ofast here, because we
        # expect that some people will compile it themselves with that setting.
        CPPFLAGS: "-Ofast -UNDEBUG"
    - name: Check greenlet build
      run: |
        ls -l dist
        twine check dist/*
    - name: Store greenlet wheel
      uses: actions/upload-artifact@v2
      with:
        name: greenlet-${{ runner.os }}-${{ matrix.python-version }}.whl
        path: dist/*whl
    - name: Test
      run: |
        python -c 'import faulthandler; assert faulthandler.is_enabled()'
        python -c 'import greenlet._greenlet as G; assert G.GREENLET_USE_STANDARD_THREADING'
        python -m unittest discover -v greenlet.tests
    - name: Doctest
      run: |
        sphinx-build -b doctest -d docs/_build/doctrees2 docs docs/_build/doctest2
    - name: Publish package to PyPI (mac)
      # We cannot 'uses: pypa/gh-action-pypi-publish@v1.4.1' because
      # that's apparently a container action, and those don't run on
      # the Mac.
      if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && startsWith(runner.os, 'Mac')
      env:
        TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
      run: |
        twine upload --skip-existing dist/*

  test_non_standard_thread:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version: [2.7, 3.5, "3.10"]
        os: [ubuntu-latest, macos-latest]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Pip cache
      uses: actions/cache@v2
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-ns-${{ hashFiles('setup.*') }}
        restore-keys: |
          ${{ runner.os }}-pip-ns-
    - name: Install dependencies
      run: |
        python -m pip install -U pip setuptools wheel
        python -m pip install -U twine
        python -m pip install -q -U 'faulthandler; python_version == "2.7" and platform_python_implementation == "CPython"'
    - name: Install greenlet
      env:
        CPPFLAGS: "-DG_USE_STANDARD_THREADING=0 -UNDEBUG -Ofast"
      run: |
        python setup.py bdist_wheel
        python -m pip install -U -v -e ".[test,docs]"
    - name: Test
      run: |
        python -c 'import faulthandler; assert faulthandler.is_enabled()'
        python -c 'import greenlet._greenlet as G; assert not G.GREENLET_USE_STANDARD_THREADING'
        python -m unittest discover -v greenlet.tests

  CodeQL:
    runs-on: ubuntu-latest
    permissions:
      # required for all workflows
      security-events: write
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: "3.10"
      - name: Pip cache
        uses: actions/cache@v2
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-ql-${{ hashFiles('setup.*') }}
          restore-keys: |
            ${{ runner.os }}-pip-ql-
      - name: Install dependencies
        run: |
          python -m pip install -U pip
          python -m pip install -U setuptools wheel
          # Set the `CODEQL-PYTHON` environment variable to the Python executable
          # that includes the dependencies
          echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV
      # Initializes the CodeQL tools for scanning.
      - name: Initialize CodeQL
        uses: github/codeql-action/init@v1
        with:
          languages: python, cpp
          # Override the default behavior so that the action doesn't attempt
          # to auto-install Python dependencies
          setup-python-dependencies: false
      - name: Install greenlet
        run: |
          python setup.py build
      # - name: Autobuild
      #   uses: github/codeql-action/autobuild@v1
      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v1

  manylinux:

    runs-on: ubuntu-latest
    # We use a regular Python matrix entry to share as much code as possible.
    strategy:
      matrix:
        python-version: [3.9]
        image:
          - manylinux2010_x86_64
          - manylinux2014_aarch64
          - manylinux2014_ppc64le
          - manylinux2014_x86_64
          - musllinux_1_1_x86_64
    name: ${{ matrix.image }}

    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: Enable emulation
        run: |
          docker run --rm --privileged hypriot/qemu-register
        # This one was seen in pyca/bcrypt. What's the difference?
        # (Other than this one not working.)
        #run: |
        #  docker run --rm --privileged multiarch/qemu-user-static:register --reset
      - name: Build and test greenlet
        if: matrix.image == 'manylinux2010_x86_64'
        # An alternate way to do this is to run the container directly with a uses:
        # and then the script runs inside it. That may work better with caching.
        # See https://github.com/pyca/bcrypt/blob/f6b5ee2eda76d077c531362ac65e16f045cf1f29/.github/workflows/wheel-builder.yml
        # The 2010 image is the last one that comes with Python 2.7,
        # and only up through the tag 2021-02-06-3d322a5
        env:
          DOCKER_IMAGE: quay.io/pypa/${{ matrix.image }}:2021-02-06-3d322a5
        run: bash ./make-manylinux
      - name: Build and test greenlet (other)
        if: matrix.image != 'manylinux2010_x86_64'
        env:
          DOCKER_IMAGE: quay.io/pypa/${{ matrix.image }}
        run: bash ./make-manylinux
      - name: Store greenlet wheels
        uses: actions/upload-artifact@v2
        with:
          path: wheelhouse/*whl
          name: ${{ matrix.image }}_wheels.zip
      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@v1.4.1
        if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
        with:
          user: __token__
          password: ${{ secrets.TWINE_PASSWORD }}
          skip_existing: true
          packages_dir: wheelhouse/