|
1 | | -# This workflow will upload a Python Package using Twine when a release is created |
2 | | -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries |
3 | | - |
4 | | -# This workflow uses actions that are not certified by GitHub. |
5 | | -# They are provided by a third-party and are governed by |
6 | | -# separate terms of service, privacy policy, and support |
7 | | -# documentation. |
8 | | - |
9 | | -name: Upload Python Package |
| 1 | +name: Publish to PyPI |
10 | 2 |
|
11 | 3 | on: |
12 | 4 | push: |
13 | 5 | tags: |
14 | | - - "[0-9]+.[0-9]+.[0-9]+" |
| 6 | + - '[0-9]+\.[0-9]+\.[0-9+]+' |
15 | 7 |
|
16 | 8 | permissions: |
17 | | - contents: write |
| 9 | + contents: read |
18 | 10 |
|
19 | 11 | jobs: |
20 | | - deploy: |
21 | | - |
| 12 | + test: |
22 | 13 | runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] |
23 | 18 |
|
24 | 19 | steps: |
25 | 20 | - uses: actions/checkout@v4 |
26 | | - - name: Set up Python |
| 21 | + - name: Set up Python ${{ matrix.python-version }} |
27 | 22 | uses: actions/setup-python@v5 |
28 | 23 | with: |
29 | | - python-version: '3.x' |
| 24 | + python-version: ${{ matrix.python-version }} |
30 | 25 | - name: Install dependencies |
31 | 26 | run: | |
32 | 27 | python -m pip install --upgrade pip |
33 | | - pip install setuptools |
34 | | - pip install -r requirements.txt |
35 | | - - name: Test code |
36 | | - run: pytest |
37 | | - - name: Bumpversion |
38 | | - run: bumpversion --new-version=${{ github.ref_name }} minor |
39 | | - - name: Fail if bumpversion changed files |
| 28 | + python -m pip install flake8 pytest |
| 29 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 30 | + - name: Lint with flake8 |
40 | 31 | run: | |
41 | | - if [ -n "$(git status --porcelain)" ]; then |
42 | | - echo "bumpversion modified files; failing the job." |
43 | | - git status --porcelain |
44 | | - exit 1 |
45 | | - else |
46 | | - echo "No changes after bumpversion." |
47 | | - fi |
48 | | - - name: Clean dist/ |
49 | | - run: rm dist/* -f |
50 | | - - name: Build package |
51 | | - run: python setup.py sdist bdist_wheel |
52 | | - - name: Check package |
53 | | - run: python -m twine check dist/* |
54 | | - - name: Publish package |
55 | | - uses: pypa/gh-action-pypi-publish@0ab0b79471669eb3a4d647e625009c62f9f3b241 |
56 | | - with: |
57 | | - user: __token__ |
58 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
59 | | - - name: Create GitHub Release |
60 | | - uses: actions/create-release@v1 |
61 | | - env: |
62 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
63 | | - with: |
64 | | - tag_name: ${{ github.ref_name }} |
65 | | - release_name: ${{ github.ref_name }} |
66 | | - draft: false |
67 | | - prerelease: false |
| 32 | + # stop the build if there are Python syntax errors or undefined names |
| 33 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 34 | + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
| 35 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 36 | + - name: Test with pytest |
| 37 | + run: | |
| 38 | + pytest |
| 39 | +
|
| 40 | + deploy: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + needs: test |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v5 |
| 48 | + with: |
| 49 | + python-version: '3.x' |
| 50 | + |
| 51 | + - name: Install build tools |
| 52 | + run: | |
| 53 | + python -m pip install --upgrade pip |
| 54 | + python -m pip install build |
| 55 | +
|
| 56 | + - name: Verify tag matches package version |
| 57 | + run: | |
| 58 | + python - << 'PY' |
| 59 | + import re, pathlib |
| 60 | + init = pathlib.Path('gcodeparser/__init__.py').read_text(encoding='utf-8') |
| 61 | + m = re.search(r"__version__\s*=\s*['\"]([^'\"]+)['\"]", init) |
| 62 | + if not m: |
| 63 | + raise SystemExit('Version not found in gcodeparser/__init__.py') |
| 64 | + pkg_version = m.group(1) |
| 65 | + tag = '${{ github.ref_name }}' |
| 66 | + if pkg_version != tag: |
| 67 | + raise SystemExit(f'Tag ({tag}) does not match package version ({pkg_version})') |
| 68 | + print(f'Version check passed: {pkg_version}') |
| 69 | + PY |
| 70 | +
|
| 71 | + - name: Build distributions |
| 72 | + run: python -m build |
| 73 | + |
| 74 | + - name: Publish to PyPI |
| 75 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 76 | + with: |
| 77 | + user: __token__ |
| 78 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 79 | + - name: Create GitHub Release |
| 80 | + uses: actions/create-release@v1 |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + with: |
| 84 | + tag_name: ${{ github.ref_name }} |
| 85 | + release_name: ${{ github.ref_name }} |
| 86 | + draft: false |
| 87 | + prerelease: false |
0 commit comments