|
| 1 | +name: tox |
| 2 | + |
| 3 | +on: |
| 4 | + create: # is used for publishing to TestPyPI |
| 5 | + tags: # any tag regardless of its name, no branches |
| 6 | + - "**" |
| 7 | + push: # only publishes pushes to the main branch to TestPyPI |
| 8 | + branches: # any integration branch but not tag |
| 9 | + - "master" |
| 10 | + pull_request: |
| 11 | + release: |
| 12 | + types: |
| 13 | + - published # It seems that you can publish directly without creating |
| 14 | + schedule: |
| 15 | + - cron: 1 0 * * * # Run daily at 0:01 UTC |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + name: ${{ matrix.tox_env }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - tox_env: lint |
| 26 | + - tox_env: docs |
| 27 | + - tox_env: py36 |
| 28 | + - tox_env: py37 |
| 29 | + - tox_env: py38 |
| 30 | + - tox_env: packaging |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v1 |
| 34 | + # Login needed to increase rate-limits |
| 35 | + - name: Login to DockerHub |
| 36 | + uses: docker/login-action@v1 |
| 37 | + with: |
| 38 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 39 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 40 | + - name: Find python version |
| 41 | + id: py_ver |
| 42 | + shell: python |
| 43 | + if: ${{ contains(matrix.tox_env, 'py') }} |
| 44 | + run: | |
| 45 | + v = '${{ matrix.tox_env }}'.split('-')[0].lstrip('py') |
| 46 | + print('::set-output name=version::{0}.{1}'.format(v[0],v[1:])) |
| 47 | + # Even our lint and other envs need access to tox |
| 48 | + - name: Install a default Python |
| 49 | + uses: actions/setup-python@v2 |
| 50 | + if: ${{ ! contains(matrix.tox_env, 'py') }} |
| 51 | + # Be sure to install the version of python needed by a specific test, if necessary |
| 52 | + - name: Set up Python version |
| 53 | + uses: actions/setup-python@v2 |
| 54 | + if: ${{ contains(matrix.tox_env, 'py') }} |
| 55 | + with: |
| 56 | + python-version: ${{ steps.py_ver.outputs.version }} |
| 57 | + - name: Install dependencies |
| 58 | + run: | |
| 59 | + docker version |
| 60 | + docker info |
| 61 | + python -m pip install -U pip |
| 62 | + pip install tox |
| 63 | + - name: Run tox -e ${{ matrix.tox_env }} |
| 64 | + run: | |
| 65 | + echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}" |
| 66 | + ${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }} |
| 67 | +
|
| 68 | + publish: |
| 69 | + name: Publish to PyPI registry |
| 70 | + needs: |
| 71 | + - build |
| 72 | + runs-on: ubuntu-latest |
| 73 | + |
| 74 | + env: |
| 75 | + PY_COLORS: 1 |
| 76 | + TOXENV: packaging |
| 77 | + |
| 78 | + steps: |
| 79 | + - name: Switch to using Python 3.6 by default |
| 80 | + uses: actions/setup-python@v2 |
| 81 | + with: |
| 82 | + python-version: 3.6 |
| 83 | + - name: Install tox |
| 84 | + run: python -m pip install --user tox |
| 85 | + - name: Check out src from Git |
| 86 | + uses: actions/checkout@v2 |
| 87 | + with: |
| 88 | + # Get shallow Git history (default) for release events |
| 89 | + # but have a complete clone for any other workflows. |
| 90 | + # Both options fetch tags but since we're going to remove |
| 91 | + # one from HEAD in non-create-tag workflows, we need full |
| 92 | + # history for them. |
| 93 | + fetch-depth: >- |
| 94 | + ${{ |
| 95 | + ( |
| 96 | + ( |
| 97 | + github.event_name == 'create' && |
| 98 | + github.event.ref_type == 'tag' |
| 99 | + ) || |
| 100 | + github.event_name == 'release' |
| 101 | + ) && |
| 102 | + 1 || 0 |
| 103 | + }} |
| 104 | + - name: Drop Git tags from HEAD for non-tag-create and non-release events |
| 105 | + if: >- |
| 106 | + ( |
| 107 | + github.event_name != 'create' || |
| 108 | + github.event.ref_type != 'tag' |
| 109 | + ) && |
| 110 | + github.event_name != 'release' |
| 111 | + run: >- |
| 112 | + git tag --points-at HEAD |
| 113 | + | |
| 114 | + xargs git tag --delete |
| 115 | + - name: Build dists |
| 116 | + run: python -m tox |
| 117 | + - name: Publish to test.pypi.org |
| 118 | + if: >- |
| 119 | + ( |
| 120 | + github.event_name == 'push' && |
| 121 | + github.ref == format( |
| 122 | + 'refs/heads/{0}', github.event.repository.default_branch |
| 123 | + ) |
| 124 | + ) || |
| 125 | + ( |
| 126 | + github.event_name == 'create' && |
| 127 | + github.event.ref_type == 'tag' |
| 128 | + ) |
| 129 | + uses: pypa/gh-action-pypi-publish@master |
| 130 | + with: |
| 131 | + password: ${{ secrets.testpypi_password }} |
| 132 | + repository_url: https://test.pypi.org/legacy/ |
| 133 | + - name: Publish to pypi.org |
| 134 | + if: >- # "create" workflows run separately from "push" & "pull_request" |
| 135 | + github.event_name == 'release' |
| 136 | + uses: pypa/gh-action-pypi-publish@master |
| 137 | + with: |
| 138 | + password: ${{ secrets.pypi_password }} |
0 commit comments