]> git.phdru.name Git - cookiecutter.git/blob - project_template/.github/workflows/test-publish.yaml
b4c337a45913dba3d336897beb589234ad26355f
[cookiecutter.git] / project_template / .github / workflows / test-publish.yaml
1 name: Test, build, publish
2
3 # Run tests (all branches),
4 # for tags build wheels, publish wheels to PyPI and Github Releases.
5
6 on: [push, pull_request]
7
8 jobs:
9   run-tests:
10     env:
11       not_in_conda: "['3.11', 'pypy-3.7']"
12
13     strategy:
14       matrix:
15         os: [ubuntu-latest, macos-11, windows-latest]
16         python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy-3.7"]
17         include:
18         - os: ubuntu-latest
19           os-name: Linux
20           pip-cache-path: ~/.cache/pip
21         - os: macos-11
22           os-name: MacOS
23           pip-cache-path: ~/Library/Caches/pip
24         - os: windows-latest
25           os-name: w32
26           pip-cache-path: ~\AppData\Local\pip\Cache
27
28     name: Python ${{ matrix.python-version }} @ ${{ matrix.os-name }}
29     runs-on: ${{ matrix.os }}
30
31     steps:
32
33       # Setup Python/pip
34       - uses: s-weigand/setup-conda@v1
35         with:
36           python-version: ${{ matrix.python-version }}
37         if: ${{ runner.os == 'Linux' && !contains(fromJSON(env.not_in_conda), matrix.python-version) }}
38       - uses: actions/setup-python@v4
39         with:
40           python-version: ${{ matrix.python-version }}
41         if: ${{ runner.os != 'Linux' || contains(fromJSON(env.not_in_conda), matrix.python-version) }}
42       - name: Cache pip
43         uses: actions/cache@v3
44         with:
45           path: ${{ matrix.pip-cache-path }}
46           key: ${{ runner.os }}-pip
47
48       # Setup tox
49       - name: Install dependencies
50         run: |
51           python --version
52           python -m pip install --upgrade pip setuptools wheel
53           pip --version
54           pip install --upgrade virtualenv tox
55       - name: Set TOXENV
56         run: |
57           import os, sys
58           if hasattr(sys, 'pypy_version_info'):
59             toxenv = 'pypy3'
60           else:
61             pyver = '%d%d' % tuple(sys.version_info[:2])
62             toxenv = 'py%s' % pyver
63             if os.name == 'posix':
64               toxenv += ',py%s-flake8' % pyver
65           with open(os.environ['GITHUB_ENV'], 'a') as f:
66             f.write('TOXENV=' + toxenv + '\n')
67           print(toxenv)
68         shell: python
69
70       - name: Run tox
71         run: |
72           python -c "import os; print(os.environ['TOXENV'])"
73           tox --version
74           tox
75
76       - name: Build and publish wheel
77         run: |
78           pip install -U pip setuptools twine wheel
79           python setup.py bdist_wheel
80           twine upload --disable-progress-bar --skip-existing dist\*
81         if: ${{ startsWith(github.ref, 'refs/tags/') }}
82         env:
83           TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
84           TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
85       - name: Publish wheel to Releases
86         uses: ncipollo/release-action@v1
87         with:
88           artifacts: "dist/*"
89           allowUpdates: true
90           bodyFile: "LATEST-CHANGES.rst"
91           omitBodyDuringUpdate: true
92           omitNameDuringUpdate: true
93           omitPrereleaseDuringUpdate: true
94           prerelease: false
95           replacesArtifacts: false
96           skipIfReleaseExists: false
97           updateOnlyUnreleased: false
98         if: ${{ startsWith(github.ref, 'refs/tags/') }}