|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + build: |
| 7 | + name: Python ${{ matrix.python-version }} |
| 8 | + runs-on: ${{ matrix.os }} |
| 9 | + strategy: |
| 10 | + fail-fast: false |
| 11 | + matrix: |
| 12 | + python-version: |
| 13 | + - '2.7' |
| 14 | + - '3.5' |
| 15 | + - '3.6' |
| 16 | + - '3.7' |
| 17 | + - '3.8' |
| 18 | + - '3.9' |
| 19 | + - '3.10.0-alpha - 3.10' |
| 20 | + os: [ubuntu-latest] |
| 21 | + include: |
| 22 | + # is not on ubuntu-latest |
| 23 | + - python-version: '3.4' |
| 24 | + os: ubuntu-18.04 |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Set up Python ${{ matrix.python-version }} |
| 30 | + uses: actions/setup-python@v2 |
| 31 | + with: |
| 32 | + python-version: ${{ matrix.python-version }} |
| 33 | + |
| 34 | + - uses: actions/cache@v2 |
| 35 | + with: |
| 36 | + path: ~/.cache/pip |
| 37 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-pip- |
| 40 | +
|
| 41 | + - name: Install dependencies |
| 42 | + id: install |
| 43 | + run: | |
| 44 | + set -x |
| 45 | + pip install -r requirements.txt |
| 46 | +
|
| 47 | + # install mypy on Python 3.6+ |
| 48 | + if python -c \ |
| 49 | + 'import sys; sys.exit(0 if sys.version_info >= (3, 6) else 1)'; then |
| 50 | + pip install -U mypy |
| 51 | + echo "::set-output name=mypy::true" |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Run pytest |
| 55 | + run: | |
| 56 | + pytest |
| 57 | +
|
| 58 | + - name: Run mypy |
| 59 | + if: ${{ steps.install.outputs.mypy }} |
| 60 | + run: | |
| 61 | + mypy pyannotate_* |
| 62 | +
|
| 63 | + # This can be removed if Python 3.5.1 is supported by GitHub actions |
| 64 | + # setup-python or if Python 3.5.1 support is dropped. |
| 65 | + # |
| 66 | + # see: https://github.com/actions/setup-python/issues/187 |
| 67 | + docker: |
| 68 | + name: Docker Python |
| 69 | + runs-on: ubuntu-latest |
| 70 | + strategy: |
| 71 | + fail-fast: false |
| 72 | + matrix: |
| 73 | + include: |
| 74 | + # does not have typing.Text |
| 75 | + - python-version: '3.5.1' |
| 76 | + |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v2 |
| 79 | + |
| 80 | + # The system Python does not have lib2to3 tests so install a Python |
| 81 | + # version with it. |
| 82 | + - name: Set up Python 3.5 |
| 83 | + uses: actions/setup-python@v2 |
| 84 | + with: |
| 85 | + python-version: 3.5 |
| 86 | + |
| 87 | + - uses: actions/cache@v2 |
| 88 | + with: |
| 89 | + path: ~/.cache/pip |
| 90 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} |
| 91 | + restore-keys: | |
| 92 | + ${{ runner.os }}-pip- |
| 93 | +
|
| 94 | + - name: Test on Docker |
| 95 | + run: | |
| 96 | + set -x |
| 97 | + # Docker containers don't usually ship with tests and the tests |
| 98 | + # rely on lib2to3.tests |
| 99 | + IMAGE=python:${{ matrix.python-version }} |
| 100 | + HOST_LIB2TO3_TEST_DIR=$(python -c \ |
| 101 | + 'import os, lib2to3.tests; print(os.path.dirname(lib2to3.tests.__file__))') |
| 102 | + DOCKER_LIB2TO3_TEST_DIR=$(docker run --rm "$IMAGE" python -c \ |
| 103 | + 'import os, lib2to3; print(os.path.dirname(lib2to3.__file__))')/tests |
| 104 | +
|
| 105 | + # and lib2to3.tests rely on test |
| 106 | + HOST_TEST_DIR=$(dirname $(dirname "$HOST_LIB2TO3_TEST_DIR"))/test |
| 107 | + DOCKER_TEST_DIR=$(dirname $(dirname "$DOCKER_LIB2TO3_TEST_DIR"))/test |
| 108 | +
|
| 109 | + # remove any optimized files so they can be regenerated correctly if needed |
| 110 | + find "$HOST_TEST_DIR" "$HOST_LIB2TO3_TEST_DIR" -name '*.py[cod]' -delete |
| 111 | +
|
| 112 | + # pip will not use the cache if it's owned by someone else |
| 113 | + sudo chown -R 0:0 "$HOME/.cache/pip" |
| 114 | +
|
| 115 | + docker run \ |
| 116 | + --user 0:0 \ |
| 117 | + --volume "$HOST_TEST_DIR":"$DOCKER_TEST_DIR" \ |
| 118 | + --volume "$HOST_LIB2TO3_TEST_DIR":"$DOCKER_LIB2TO3_TEST_DIR" \ |
| 119 | + --volume "$HOME/.cache/pip:/root/.cache/pip" \ |
| 120 | + --volume "$PWD:$PWD" \ |
| 121 | + --workdir "$PWD" \ |
| 122 | + --rm "$IMAGE" bash -ex -c ' |
| 123 | + pip install -r requirements.txt |
| 124 | + pytest |
| 125 | + ' |
| 126 | +
|
| 127 | + # return the cache back to this user in case that affects the cache action |
| 128 | + sudo chown -R $(id -u):$(id -g) "$HOME/.cache/pip" |
0 commit comments