]> git.phdru.name Git - cookiecutter.git/blob - project_template/.github/workflows/test-publish.yaml
Fix(mk-project): `sed` requires `s` for substitute
[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           ld_library_path = None
59           if hasattr(sys, 'pypy_version_info'):
60             toxenv = 'pypy3'
61           else:
62             pyver = '%d%d' % tuple(sys.version_info[:2])
63             if os.name == 'posix':
64               if pyver == '27':  # Python 2.7 on Linux requires `$LD_LIBRARY_PATH`
65                 ld_library_path = os.path.join(
66                   os.path.dirname(os.path.dirname(sys.executable)), 'lib')
67             toxenv = 'py%s' % pyver
68             if os.name == 'posix':
69               toxenv += ',py%s-flake8' % pyver
70           with open(os.environ['GITHUB_ENV'], 'a') as f:
71             if ld_library_path:
72               f.write('LD_LIBRARY_PATH=' + ld_library_path + '\n')
73             f.write('TOXENV=' + toxenv + '\n')
74           print(toxenv)
75         shell: python
76
77       - name: Run tox
78         run: |
79           python -c "import os; print(os.environ['TOXENV'])"
80           tox --version
81           tox
82
83       - name: Build and publish wheel
84         run: |
85           pip install -U pip setuptools twine wheel
86           python setup.py bdist_wheel
87           twine upload --disable-progress-bar --skip-existing dist\*
88         if: ${{ startsWith(github.ref, 'refs/tags/') }}
89         env:
90           TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
91           TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
92       - name: Publish wheel to Releases
93         uses: ncipollo/release-action@v1
94         with:
95           artifacts: "dist/*"
96           allowUpdates: true
97           bodyFile: "LATEST-CHANGES.rst"
98           omitBodyDuringUpdate: true
99           omitNameDuringUpdate: true
100           omitPrereleaseDuringUpdate: true
101           prerelease: false
102           replacesArtifacts: false
103           skipIfReleaseExists: false
104           updateOnlyUnreleased: false
105         if: ${{ startsWith(github.ref, 'refs/tags/') }}