Skip to content

Commit f9ceb54

Browse files
authored
Update release_pypi.yml
1 parent c2426ae commit f9ceb54

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

.github/workflows/release_pypi.yml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Publish to PyPI
2+
23
on:
34
workflow_dispatch:
45
push:
@@ -10,13 +11,12 @@ on:
1011

1112
jobs:
1213
publish:
13-
if: "!contains(github.event.head_commit.message, 'Bump version')"
14+
if: "!contains(toLower(github.event.head_commit.message), 'bump version')"
1415
runs-on: ubuntu-latest
1516
steps:
1617
- uses: actions/checkout@v4
1718
with:
18-
fetch-depth: 0
19-
token: ${{ secrets.GH_TOKEN }}
19+
fetch-depth: 0 # 需要完整的历史记录以获取所有标签
2020

2121
- name: Set up Python
2222
uses: actions/setup-python@v4
@@ -26,56 +26,63 @@ jobs:
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install build twine setuptools wheel
29+
pip install build twine setuptools wheel toml
3030
3131
- name: Get version from pyproject.toml
3232
id: get_version
3333
run: |
34-
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
34+
CURRENT_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
3535
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
3636
3737
# Split version into parts
38-
IFS='.' read -r major minor _ <<< "$CURRENT_VERSION"
38+
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
3939
echo "major_version=${major}" >> $GITHUB_OUTPUT
4040
echo "minor_version=${minor}" >> $GITHUB_OUTPUT
4141
4242
- name: Update version
4343
run: |
44+
set -e # Exit immediately if a command exits with a non-zero status
45+
4446
# Get major and minor version from previous step
4547
MAJOR_VERSION="${{ steps.get_version.outputs.major_version }}"
4648
MINOR_VERSION="${{ steps.get_version.outputs.minor_version }}"
47-
49+
4850
# Find the latest tag matching the current major.minor version
4951
VERSION_PREFIX="v${MAJOR_VERSION}.${MINOR_VERSION}."
5052
LAST_VERSION_TAG=$(git tag --list "${VERSION_PREFIX}*" --sort=-v:refname | head -n 1)
51-
53+
5254
if [ -z "$LAST_VERSION_TAG" ]; then
53-
# No tag exists for this major.minor version, start from 0
54-
COMMIT_COUNT=0
55+
# No tag exists for this major.minor version, start from 1
56+
COMMIT_COUNT=1
5557
else
5658
# Count commits since the last version tag
5759
COMMIT_COUNT=$(git rev-list ${LAST_VERSION_TAG}..HEAD --count)
5860
# Increment commit count to start from the next patch version
5961
COMMIT_COUNT=$((COMMIT_COUNT + 1))
6062
fi
61-
63+
6264
# Create the new version
6365
NEW_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${COMMIT_COUNT}"
64-
66+
echo "New version will be: ${NEW_VERSION}"
67+
6568
# Update version in __init__.py
6669
sed -i "s/__version__ = \".*\"/__version__ = \"${NEW_VERSION}\"/" llm_dialog_manager/__init__.py
67-
70+
6871
# Update version in pyproject.toml
69-
sed -i "s/version = \".*\"/version = \"${NEW_VERSION}\"/" pyproject.toml
70-
72+
python -c "import toml; data = toml.load('pyproject.toml'); data['tool']['poetry']['version'] = '${NEW_VERSION}'; with open('pyproject.toml', 'w') as f: toml.dump(data, f)"
73+
7174
# Commit the version update
7275
git config --local user.email "github-actions[bot]@users.noreply.github.com"
7376
git config --local user.name "github-actions[bot]"
7477
git add llm_dialog_manager/__init__.py pyproject.toml
7578
git commit -m "Bump version to ${NEW_VERSION} [skip ci]"
79+
80+
# Tag the new version
7681
git tag "v${NEW_VERSION}"
77-
git push && git push --tags
78-
82+
83+
# Push changes and tags
84+
git push origin main
85+
git push origin "v${NEW_VERSION}"
7986
8087
- name: Build package
8188
run: python -m build
@@ -84,4 +91,4 @@ jobs:
8491
env:
8592
TWINE_USERNAME: __token__
8693
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
87-
run: twine upload dist/*
94+
run: twine upload dist/*

0 commit comments

Comments
 (0)