Skip to content

Commit 0f59d8b

Browse files
committed
refactor: improve pyobsql PyPI publish workflow
- Make version input optional (use pyproject.toml version if empty) - Add option to update version in pyproject.toml before publishing - Pass version information between jobs using outputs - Improve version verification and display
1 parent ea1c2dd commit 0f59d8b

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

.github/workflows/publish-pyobsql-pypi.yml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: 'Package version to publish (e.g., 0.1.0)'
8-
required: true
7+
description: 'Package version to publish (e.g., 0.1.0). Leave empty to use version from pyproject.toml'
8+
required: false
99
type: string
1010
publish_to_test_pypi:
1111
description: 'Publish to Test PyPI instead of PyPI'
1212
required: false
1313
type: boolean
1414
default: false
15+
update_version:
16+
description: 'Update version in pyproject.toml before publishing'
17+
required: false
18+
type: boolean
19+
default: true
1520

1621
permissions:
1722
contents: read
@@ -20,6 +25,8 @@ permissions:
2025
jobs:
2126
build:
2227
runs-on: ubuntu-latest
28+
outputs:
29+
publish_version: ${{ steps.verify_version.outputs.version }}
2330
steps:
2431
- name: Checkout code
2532
uses: actions/checkout@v4
@@ -29,15 +36,35 @@ jobs:
2936
with:
3037
python-version: '3.11'
3138

39+
- name: Check current version
40+
working-directory: pyobsql-oceanbase-plugin
41+
id: current_version
42+
run: |
43+
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
44+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
45+
echo "Current version in pyproject.toml: $CURRENT_VERSION"
46+
3247
- name: Update version in pyproject.toml
33-
if: inputs.version != ''
48+
if: inputs.update_version == true && inputs.version != ''
49+
working-directory: pyobsql-oceanbase-plugin
3450
run: |
35-
cd pyobsql-oceanbase-plugin
3651
# Update version in pyproject.toml
3752
sed -i "s/^version = \".*\"/version = \"${{ inputs.version }}\"/" pyproject.toml
38-
echo "Updated version to ${{ inputs.version }}"
53+
echo "Updated version to ${{ inputs.version }}"
3954
cat pyproject.toml | grep "^version"
4055
56+
- name: Verify version
57+
working-directory: pyobsql-oceanbase-plugin
58+
id: verify_version
59+
run: |
60+
if [ "${{ inputs.version }}" != "" ] && [ "${{ inputs.update_version }}" == "true" ]; then
61+
PUBLISH_VERSION="${{ inputs.version }}"
62+
else
63+
PUBLISH_VERSION="${{ steps.current_version.outputs.version }}"
64+
fi
65+
echo "Publishing version: $PUBLISH_VERSION"
66+
echo "version=$PUBLISH_VERSION" >> $GITHUB_OUTPUT
67+
4168
- name: Install build dependencies
4269
run: |
4370
python -m pip install --upgrade pip
@@ -94,4 +121,4 @@ jobs:
94121
else
95122
echo "📍 Published to: PyPI (https://pypi.org/project/pyobsql/)"
96123
fi
97-
echo "📦 Version: ${{ inputs.version }}"
124+
echo "📦 Version: ${{ needs.build.outputs.publish_version }}"

0 commit comments

Comments
 (0)