Skip to content

Commit 9361f62

Browse files
committed
fix publishing logic and restrict PyPI to main branch only
1 parent af4f9e6 commit 9361f62

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.github/workflows/publish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Publishing
33
on:
44
push:
55
branches:
6-
- main
6+
- '*'
77
tags:
88
- '*'
99
workflow_dispatch:
@@ -64,7 +64,8 @@ jobs:
6464
path: dist/*
6565

6666
- name: Publish to PyPI
67-
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true'
67+
# Only publish to PyPI on the main branch
68+
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true' && github.ref == 'refs/heads/main'
6869
run: twine upload dist/*
6970
env:
7071
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
@@ -79,7 +80,8 @@ jobs:
7980

8081
create-release:
8182
needs: [prepare-and-check, build-and-publish]
82-
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true'
83+
# Only create GitHub releases for real PyPI publishes AND only on the main branch
84+
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true' && github.ref == 'refs/heads/main'
8385
runs-on: ubuntu-latest
8486
permissions:
8587
id-token: write

check_version.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ def check_package_version(package_name, current_version, github_ref_=None):
2727
publish_to_pypi = False
2828
publish_to_testpypi = False
2929

30-
# Determine if this is a test version based on the GitHub ref or __test_version__
31-
is_test_version = "test" in github_ref_ if github_ref_ else __test_version__
30+
# Determine if this is a test version - prioritize __test_version__ flag
31+
if __test_version__:
32+
is_test_version = True
33+
elif github_ref_ and "test" in github_ref_:
34+
is_test_version = True
35+
else:
36+
is_test_version = False
37+
3238
pypi_url = "https://test.pypi.org/pypi/" if is_test_version else "https://pypi.org/pypi/"
3339

3440
# Check if the current version exists on the respective PyPI repository

0 commit comments

Comments
 (0)