|
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: Build and publish to PyPI |
10 | 2 |
|
11 | 3 | on: |
12 | 4 | release: |
13 | 5 | types: [published] |
14 | | - |
15 | | -permissions: |
16 | | - contents: read |
| 6 | + workflow_dispatch: |
17 | 7 |
|
18 | 8 | jobs: |
19 | | - deploy: |
20 | | - |
| 9 | + build: |
| 10 | + name: Build distributions |
21 | 11 | runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: "3.11" |
| 19 | + cache: 'pip' |
| 20 | + |
| 21 | + - name: Install build tools |
| 22 | + run: python -m pip install --upgrade pip build twine |
| 23 | + |
| 24 | + - name: Install project dependencies |
| 25 | + run: python -m pip install . |
22 | 26 |
|
| 27 | + - name: Read package version |
| 28 | + id: version |
| 29 | + run: | |
| 30 | + python - <<'PY' |
| 31 | + import os |
| 32 | + import pathlib |
| 33 | + import tomllib |
| 34 | + version = tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"][ |
| 35 | + "version" |
| 36 | + ] |
| 37 | + print(version) |
| 38 | + with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f: |
| 39 | + f.write(f"version={version}\n") |
| 40 | + PY |
| 41 | +
|
| 42 | + - name: Validate release tag matches version |
| 43 | + if: github.event_name == 'release' |
| 44 | + env: |
| 45 | + TAG_NAME: ${{ github.event.release.tag_name }} |
| 46 | + run: | |
| 47 | + python - <<'PY' |
| 48 | + import os |
| 49 | + tag = os.environ["TAG_NAME"] |
| 50 | + if tag.startswith("v"): |
| 51 | + tag = tag[1:] |
| 52 | + # `steps.version.outputs.version` is available via GHA expressions only, so re-read here. |
| 53 | + import pathlib, tomllib |
| 54 | + version = tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"]["version"] |
| 55 | + if tag != version: |
| 56 | + raise SystemExit(f"Release tag ({tag}) does not match pyproject.toml version ({version})") |
| 57 | + print("Tag matches version:", tag) |
| 58 | + PY |
| 59 | +
|
| 60 | + - name: Build sdist and wheel |
| 61 | + run: python -m build --sdist --wheel --outdir dist/ |
| 62 | + |
| 63 | + - name: Python compile check |
| 64 | + run: python -m py_compile tpcav/*.py scripts/*.py test/*.py |
| 65 | + |
| 66 | + - name: Twine check |
| 67 | + run: python -m twine check --strict dist/* |
| 68 | + |
| 69 | + - uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: dist |
| 72 | + path: dist/ |
| 73 | + |
| 74 | + publish: |
| 75 | + name: Publish to PyPI |
| 76 | + needs: build |
| 77 | + runs-on: ubuntu-latest |
| 78 | + if: github.event_name == 'release' |
| 79 | + environment: |
| 80 | + name: pypi |
| 81 | + url: https://pypi.org/project/seqchromloader/ |
| 82 | + permissions: |
| 83 | + id-token: write |
| 84 | + contents: read |
23 | 85 | steps: |
24 | | - - uses: actions/checkout@v3 |
25 | | - - name: Set up Python |
26 | | - uses: actions/setup-python@v3 |
27 | | - with: |
28 | | - python-version: '3.x' |
29 | | - - name: Install dependencies |
30 | | - run: | |
31 | | - python -m pip install --upgrade pip |
32 | | - pip install build |
33 | | - - name: Build package |
34 | | - run: python -m build |
35 | | - - name: Publish package |
36 | | - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 |
37 | | - with: |
38 | | - user: yztxwd |
39 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 86 | + - uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + name: dist |
| 89 | + path: dist/ |
| 90 | + |
| 91 | + - name: Publish |
| 92 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 93 | + with: |
| 94 | + packages-dir: dist/ |
0 commit comments