Skip to content

Commit 2e879a3

Browse files
committed
fix: PyPI upload
1 parent 27859a5 commit 2e879a3

File tree

1 file changed

+55
-63
lines changed

1 file changed

+55
-63
lines changed

.github/workflows/release_pypi.yml

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ jobs:
2323
- uses: actions/checkout@v4
2424
with:
2525
fetch-depth: 0 # Ensure all history and tags are fetched
26-
26+
2727
- name: Set up Python
2828
uses: actions/setup-python@v4
2929
with:
3030
python-version: '3.x'
31-
31+
3232
- name: Install dependencies
3333
run: |
3434
python -m pip install --upgrade pip
3535
pip install build twine setuptools wheel toml
36-
37-
- name: Get version from pyproject.toml
36+
37+
- name: Get current version from pyproject.toml
3838
id: get_version
3939
run: |
4040
CURRENT_VERSION=$(python -c '
@@ -52,54 +52,53 @@ jobs:
5252
')
5353
5454
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
55-
56-
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
57-
echo "major_version=${major}" >> $GITHUB_OUTPUT
58-
echo "minor_version=${minor}" >> $GITHUB_OUTPUT
59-
60-
- name: Check if version exists on PyPI
61-
id: check_pypi
55+
56+
- name: Debug - Current Version
57+
run: |
58+
echo "Current Version: ${{ steps.get_version.outputs.current_version }}"
59+
60+
- name: Determine New Version
61+
id: determine_version
6262
run: |
63+
CURRENT_VERSION="${{ steps.get_version.outputs.current_version }}"
64+
echo "Current Version: $CURRENT_VERSION"
65+
66+
# Split the current version into major, minor, and patch
67+
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
68+
69+
# Check if the current version exists on PyPI
6370
PACKAGE_NAME=$(python -c "
6471
import toml
6572
config = toml.load('pyproject.toml')
6673
print(config['project']['name'])
6774
")
68-
VERSION="${{ steps.get_version.outputs.current_version }}"
69-
PYPI_URL="https://pypi.org/pypi/${PACKAGE_NAME}/${VERSION}/json"
70-
71-
echo "Checking PyPI for ${PACKAGE_NAME} version ${VERSION}..."
72-
75+
PYPI_URL="https://pypi.org/pypi/${PACKAGE_NAME}/${CURRENT_VERSION}/json"
76+
77+
echo "Checking PyPI for ${PACKAGE_NAME} version ${CURRENT_VERSION}..."
7378
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$PYPI_URL")
74-
79+
7580
if [ "$RESPONSE_CODE" -eq 200 ]; then
76-
echo "Version ${VERSION} already exists on PyPI."
77-
NEW_VERSION="${VERSION}-dev"
81+
echo "Version ${CURRENT_VERSION} already exists on PyPI. Incrementing patch version."
82+
NEW_PATCH=$((patch + 1))
83+
NEW_VERSION="${major}.${minor}.${NEW_PATCH}"
7884
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
7985
else
80-
echo "Version ${VERSION} is available on PyPI."
81-
echo "new_version=${VERSION}" >> $GITHUB_OUTPUT
86+
echo "Version ${CURRENT_VERSION} is available on PyPI."
87+
echo "new_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
8288
fi
83-
84-
- name: Debug - Version Check
89+
90+
- name: Debug - New Version
8591
run: |
86-
echo "New Version: ${{ steps.check_pypi.outputs.new_version }}"
87-
88-
- name: Update version
92+
echo "New Version: ${{ steps.determine_version.outputs.new_version }}"
93+
94+
- name: Update version in files
8995
run: |
90-
set -e # Exit immediately if a command exits with a non-zero status
91-
92-
# Use the new_version from the PyPI check
93-
NEW_VERSION="${{ steps.check_pypi.outputs.new_version }}"
94-
echo "Using new version: ${NEW_VERSION}"
95-
96-
# Split version into major, minor, patch components
97-
IFS='.-' read -r major minor patch <<< "$NEW_VERSION"
98-
echo "Major: $major, Minor: $minor, Patch: $patch"
99-
96+
NEW_VERSION="${{ steps.determine_version.outputs.new_version }}"
97+
echo "Updating files to version ${NEW_VERSION}"
98+
10099
# Update version in __init__.py
101100
sed -i "s/__version__ = \".*\"/__version__ = \"${NEW_VERSION}\"/" llm_dialog_manager/__init__.py
102-
101+
103102
# Update version in pyproject.toml
104103
python -c "
105104
import toml
@@ -109,35 +108,28 @@ jobs:
109108
with open('pyproject.toml', 'w') as f:
110109
toml.dump(data, f)
111110
"
112-
113-
# Commit the version update if it's a dev version
114-
if [[ "$NEW_VERSION" == *"-dev" ]]; then
115-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
116-
git config --local user.name "github-actions[bot]"
117-
git add llm_dialog_manager/__init__.py pyproject.toml
118-
git commit -m "Bump version to ${NEW_VERSION} [skip ci]"
119-
fi
120-
121-
# Tag the new version if it's not a dev version
122-
if [[ "$NEW_VERSION" != *"-dev" ]]; then
123-
git tag "v${NEW_VERSION}"
124-
git push origin main
125-
git push origin "v${NEW_VERSION}"
126-
fi
127-
111+
112+
- name: Commit version changes
113+
run: |
114+
NEW_VERSION="${{ steps.determine_version.outputs.new_version }}"
115+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
116+
git config --local user.name "github-actions[bot]"
117+
git add llm_dialog_manager/__init__.py pyproject.toml
118+
git commit -m "Bump version to ${NEW_VERSION} [skip ci]"
119+
120+
- name: Tag the new version
121+
run: |
122+
NEW_VERSION="${{ steps.determine_version.outputs.new_version }}"
123+
git tag "v${NEW_VERSION}"
124+
git push origin main
125+
git push origin "v${NEW_VERSION}"
126+
128127
- name: Build package
129128
run: python -m build
130-
129+
131130
- name: Publish to PyPI
132-
if: ${{ steps.check_pypi.outputs.new_version != format('{0}-dev', steps.get_version.outputs.current_version) }}
133131
env:
134132
TWINE_USERNAME: __token__
135133
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
136-
run: twine upload dist/*
137-
138-
- name: Publish to Test PyPI
139-
if: ${{ steps.check_pypi.outputs.new_version == format('{0}-dev', steps.get_version.outputs.current_version) }}
140-
env:
141-
TWINE_USERNAME: __token__
142-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
143-
run: twine upload --repository-url https://test.pypi.org/legacy/ dist/*
134+
run: |
135+
twine upload dist/* --verbose

0 commit comments

Comments
 (0)