|
1 | 1 | name: PyPI 📦 Distribution |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +permissions: |
| 6 | + contents: read |
4 | 7 |
|
5 | 8 | jobs: |
6 | 9 | build: |
7 | 10 | runs-on: ubuntu-latest |
8 | 11 | steps: |
9 | | - - uses: actions/checkout@v2 |
| 12 | + - uses: actions/checkout@v6 |
10 | 13 | - name: Set up Python |
11 | | - uses: actions/setup-python@v4 |
| 14 | + uses: actions/setup-python@v6 |
12 | 15 | with: |
13 | | - python-version: "^3.8" |
| 16 | + python-version: "3.13" |
14 | 17 | - name: Install dependencies |
15 | | - run: pipx install poetry |
| 18 | + run: python -m pip install "poetry>=2,<3" build twine |
| 19 | + - name: Check package metadata |
| 20 | + run: poetry check --lock |
| 21 | + - name: Check release tag matches package version |
| 22 | + if: startsWith(github.ref, 'refs/tags/') |
| 23 | + env: |
| 24 | + RELEASE_TAG: ${{ github.ref_name }} |
| 25 | + run: | |
| 26 | + python - <<'PY' |
| 27 | + import os |
| 28 | + import tomllib |
| 29 | + from pathlib import Path |
| 30 | + from packaging.version import Version |
| 31 | +
|
| 32 | + tag = os.environ['RELEASE_TAG'].removeprefix('v') |
| 33 | + version = tomllib.loads(Path('pyproject.toml').read_text())['tool']['poetry']['version'] |
| 34 | + if Version(tag) != Version(version): |
| 35 | + raise SystemExit(f'Release tag {tag!r} does not match package version {version!r}') |
| 36 | + PY |
16 | 37 | - name: Build distribution 📦 |
17 | | - run: poetry build -n |
| 38 | + run: python -m build |
| 39 | + - name: Check distribution metadata |
| 40 | + run: python -m twine check --strict dist/* |
| 41 | + - name: Test installed wheel |
| 42 | + run: | |
| 43 | + python -m pip install dist/*.whl |
| 44 | + python -I tests/test_qltool.py InstalledQltool_Test -v |
18 | 45 | - uses: actions/upload-artifact@v4 |
19 | 46 | with: |
| 47 | + name: distributions |
20 | 48 | path: ${{ github.workspace }}/dist/* |
| 49 | + if-no-files-found: error |
21 | 50 |
|
22 | 51 | publish: |
23 | 52 | needs: [build] |
24 | 53 | runs-on: ubuntu-latest |
25 | | - if: startsWith(github.ref, 'refs/tags') |
| 54 | + if: startsWith(github.ref, 'refs/tags/') |
26 | 55 | steps: |
27 | 56 | - uses: actions/download-artifact@v4 |
28 | 57 | with: |
29 | | - name: artifact |
| 58 | + name: distributions |
30 | 59 | path: dist |
31 | 60 |
|
32 | 61 | - name: Publish distribution 📦 to test PyPI |
33 | | - uses: pypa/gh-action-pypi-publish@master |
| 62 | + uses: pypa/gh-action-pypi-publish@release/v1 |
34 | 63 | with: |
35 | 64 | user: __token__ |
36 | 65 | password: ${{ secrets.testpypi_pass }} |
37 | | - repository_url: https://test.pypi.org/legacy/ |
| 66 | + repository-url: https://test.pypi.org/legacy/ |
| 67 | + skip-existing: true |
38 | 68 |
|
39 | 69 | - name: Publish distribution 📦 to PyPI |
40 | | - if: ${{ success() }} |
41 | | - uses: pypa/gh-action-pypi-publish@master |
| 70 | + uses: pypa/gh-action-pypi-publish@release/v1 |
42 | 71 | with: |
43 | 72 | user: __token__ |
44 | 73 | password: ${{ secrets.pypi_pass }} |
0 commit comments