Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 49 additions & 30 deletions .github/workflows/publish-oceanbase-cli-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Optional version override for the published package (leave empty to use oceanbase-cli/pyproject.toml)'
description: 'Package version to publish (e.g., 0.1.0). Leave empty to use version from pyproject.toml'
required: false
type: string
publish_to_test_pypi:
description: 'Publish to Test PyPI instead of PyPI'
required: false
type: boolean
default: false
update_version:
description: 'Update version in pyproject.toml before publishing'
required: false
type: boolean
default: true

permissions:
contents: read

jobs:
release-build:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
publish_version: ${{ steps.verify_version.outputs.version }}
publish_to_test_pypi: ${{ steps.meta.outputs.publish_to_test_pypi }}
publish_version: ${{ steps.show_version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set publish metadata
id: meta
Expand All @@ -42,21 +50,35 @@ jobs:
with:
python-version: '3.11'

- name: Override package version
if: github.event_name == 'workflow_dispatch' && inputs.version != ''
- name: Check current version
working-directory: oceanbase-cli
id: current_version
run: |
sed -i 's/^version = ".*"/version = "${{ inputs.version }}"/' pyproject.toml
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version in pyproject.toml: $CURRENT_VERSION"

- name: Show package version
id: show_version
- name: Update version in pyproject.toml
if: github.event_name == 'workflow_dispatch' && inputs.update_version == true && inputs.version != ''
working-directory: oceanbase-cli
run: |
VER=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VER" >> $GITHUB_OUTPUT
sed -i "s/^version = \".*\"/version = \"${{ inputs.version }}\"/" pyproject.toml
echo "Updated version to ${{ inputs.version }}"
grep '^version' pyproject.toml

- name: Install dependencies
- name: Verify version
working-directory: oceanbase-cli
id: verify_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.version }}" != "" ] && [ "${{ inputs.update_version }}" = "true" ]; then
PUBLISH_VERSION="${{ inputs.version }}"
else
PUBLISH_VERSION="${{ steps.current_version.outputs.version }}"
fi
echo "Publishing version: $PUBLISH_VERSION"
echo "version=$PUBLISH_VERSION" >> $GITHUB_OUTPUT

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
Expand All @@ -73,55 +95,52 @@ jobs:
mkdir -p dist
python -m build ./oceanbase-cli -o dist

- name: Check distributions
- name: Check package
run: twine check dist/*

- name: Upload dists
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
name: pypi-distributions
path: dist/*

pypi-publish:
publish:
runs-on: ubuntu-latest
needs:
- release-build
needs: build
permissions:
contents: read

steps:
- name: Retrieve release distributions
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: release-dists
name: pypi-distributions
path: dist/

- name: Publish to Test PyPI
if: needs.release-build.outputs.publish_to_test_pypi == 'true'
if: needs.build.outputs.publish_to_test_pypi == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

- name: Publish to PyPI
if: needs.release-build.outputs.publish_to_test_pypi != 'true'
if: needs.build.outputs.publish_to_test_pypi != 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install twine
twine upload dist/*

- name: Display published package info
run: |
echo "Package publish step finished."
if [ "${{ needs.release-build.outputs.publish_to_test_pypi }}" = "true" ]; then
echo "Target: Test PyPI https://test.pypi.org/project/oceanbase-cli/"
echo "Package published successfully!"
if [ "${{ needs.build.outputs.publish_to_test_pypi }}" = "true" ]; then
echo "Published to: Test PyPI (https://test.pypi.org/project/oceanbase-cli/)"
else
echo "Target: PyPI https://pypi.org/project/oceanbase-cli/"
echo "Published to: PyPI (https://pypi.org/project/oceanbase-cli/)"
fi
echo "Version: ${{ needs.release-build.outputs.publish_version }}"
echo "Version: ${{ needs.build.outputs.publish_version }}"
Loading