Skip to content

Commit 096a795

Browse files
committed
automated publishing?
1 parent fc13e2f commit 096a795

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

.github/workflows/tests.yml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# 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
54

65
on:
6+
# run tests on any push to any branch, version tags, and on pull requests
77
push:
8+
branches: ['**']
9+
tags: ['v*']
810
pull_request:
911

1012
jobs:
11-
build:
12-
13+
# TEST JOB (multi-Python matrix)
14+
test:
1315
runs-on: ubuntu-latest
1416
strategy:
1517
fail-fast: false
@@ -44,3 +46,54 @@ jobs:
4446
pip install json-stream-rs-tokenizer
4547
rm -f src/json_stream_rs_tokenizer.py
4648
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

Comments
 (0)