|
1 | 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
|
2 | 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
3 |
| - |
4 |
| -name: Tests |
| 3 | +name: CI |
5 | 4 |
|
6 | 5 | on:
|
| 6 | + # run tests on any push to any branch, version tags, and on pull requests |
7 | 7 | push:
|
| 8 | + branches: ['**'] |
| 9 | + tags: ['v*'] |
8 | 10 | pull_request:
|
9 | 11 |
|
10 | 12 | jobs:
|
11 |
| - build: |
12 |
| - |
| 13 | + # TEST JOB (multi-Python matrix) |
| 14 | + test: |
13 | 15 | runs-on: ubuntu-latest
|
14 | 16 | strategy:
|
15 | 17 | fail-fast: false
|
|
44 | 46 | pip install json-stream-rs-tokenizer
|
45 | 47 | rm -f src/json_stream_rs_tokenizer.py
|
46 | 48 | pytest
|
| 49 | +
|
| 50 | + # PUBLISH JOB (only on tag push) |
| 51 | + publish: |
| 52 | + # This job will only run if the "test" job succeeds |
| 53 | + needs: test |
| 54 | + runs-on: ubuntu-latest |
| 55 | + |
| 56 | + # Only run if event is a tag push matching "v*" |
| 57 | + # e.g. refs/tags/v1.2.3 |
| 58 | + if: startsWith(github.ref, 'refs/tags/v') |
| 59 | + |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v3 |
| 62 | + |
| 63 | + - name: Set up Python |
| 64 | + uses: actions/setup-python@v3 |
| 65 | + with: |
| 66 | + python-version: "3.13" |
| 67 | + |
| 68 | + - name: Verify tag matches pyproject.toml |
| 69 | + id: check_version |
| 70 | + run: | |
| 71 | + python <<EOF |
| 72 | + import os, sys, tomllib |
| 73 | + from pathlib import Path |
| 74 | + |
| 75 | + data = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8")) |
| 76 | + version = data["project"]["version"] |
| 77 | + |
| 78 | + tag = os.environ.get("GITHUB_REF", "").split("/")[-1] |
| 79 | + |
| 80 | + if tag.lstrip("v") != version: |
| 81 | + print(f"ERROR: Tag {tag} does not match pyproject.toml version {version}.") |
| 82 | + sys.exit(1) |
| 83 | + |
| 84 | + print(f"Version check passed: tag {tag} matches pyproject.toml version {version}.") |
| 85 | + with open(os.environ["GITHUB_OUTPUT"], "a") as gh_out: |
| 86 | + gh_out.write(f"version={version}\n") |
| 87 | + EOF |
| 88 | + - name: Build and publish to PyPI (using OIDC) |
| 89 | + if: ${{ success() }} |
| 90 | + env: |
| 91 | + # Tell Twine to use OIDC for authentication |
| 92 | + TWINE_ID_TOKEN_AUTH: 1 |
| 93 | + TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ |
| 94 | + run: | |
| 95 | + python -m pip install --upgrade pip |
| 96 | + python -m pip install build twine |
| 97 | + python -m build |
| 98 | + python -m twine upload dist/* |
| 99 | + echo "Published ${{ steps.check_version.outputs.version }} to PyPI!" |
0 commit comments