]> git.phdru.name Git - cookiecutter.git/blob - project_template/.github/workflows/test-publish.yaml
Feat: Migrate to Github Actions
[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.
5
6 on: [push, pull_request]
7
8 jobs:
9   run-tests:
10
11     strategy:
12       matrix:
13         os: [ubuntu-latest, macos-11, windows-latest]
14         python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy-2.7", "pypy-3.7"]
15         include:
16         - os: ubuntu-latest
17           os-name: Linux
18           pip-cache-path: ~/.cache/pip
19         - os: macos-11
20           os-name: MacOS
21           pip-cache-path: ~/Library/Caches/pip
22         - os: windows-latest
23           os-name: w32
24           pip-cache-path: ~\AppData\Local\pip\Cache
25
26     name: Python ${{ matrix.python-version }} @ ${{ matrix.os-name }}
27     runs-on: ${{ matrix.os }}
28
29     steps:
30
31       # Setup Python/pip
32       - uses: actions/setup-python@v4
33         with:
34           python-version: ${{ matrix.python-version }}
35       - name: Cache pip
36         uses: actions/cache@v3
37         with:
38           path: ${{ matrix.pip-cache-path }}
39           key: ${{ runner.os }}-pip
40
41       # Setup tox
42       - name: Install dependencies
43         run: |
44           python --version
45           python -m pip install --upgrade pip setuptools wheel
46           pip --version
47           pip install --upgrade virtualenv tox
48       - name: Set TOXENV
49         run: |
50           import os, sys
51           if hasattr(sys, 'pypy_version_info'):
52             toxenv = 'pypy'
53           else:
54             pyver = '%d%d' % tuple(sys.version_info[:2])
55             toxenv = 'py%s' % pyver
56             if os.name == 'posix':
57               toxenv += ',py%s-flake8' % pyver
58           with open(os.environ['GITHUB_ENV'], 'a') as f:
59             f.write('TOXENV=' + toxenv + '\n')
60           print(toxenv)
61         shell: python
62
63       - name: Run tox
64         run: |
65           python -c "import os; print(os.environ['TOXENV'])"
66           tox --version
67           tox
68
69       - name: Build and publish wheel
70         run: |
71           pip install -U pip setuptools twine wheel
72           python setup.py bdist_wheel
73           twine upload --disable-progress-bar --skip-existing dist\*
74         if: ${{ startsWith(github.ref, 'refs/tags/') }}
75         env:
76           TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
77           TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}