Publish SDK to PyPI #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish SDK to PyPI | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version number (e.g., 0.1.0, 0.2.0)' | |
| required: true | |
| type: string | |
| release_notes: | |
| description: 'Release notes' | |
| required: false | |
| type: string | |
| default: 'Bug fixes and improvements' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| pip install -e ".[dev]" | |
| - name: Update version in __version__.py | |
| run: | | |
| echo '"""Version information for DataSpace SDK."""' > dataspace_sdk/__version__.py | |
| echo "" >> dataspace_sdk/__version__.py | |
| echo "__version__ = \"${{ inputs.version }}\"" >> dataspace_sdk/__version__.py | |
| - name: Update version in pyproject.toml (if exists) | |
| run: | | |
| if [ -f pyproject.toml ]; then | |
| sed -i "s/version = \".*\"/version = \"${{ inputs.version }}\"/" pyproject.toml | |
| fi | |
| - name: Commit and push version changes | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add dataspace_sdk/__version__.py | |
| if [ -f pyproject.toml ]; then git add pyproject.toml; fi | |
| git commit -m "Bump SDK version to ${{ inputs.version }}" || echo "No changes to commit" | |
| # Get current branch name | |
| BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | |
| echo "Pushing to branch: $BRANCH_NAME" | |
| git push origin $BRANCH_NAME || echo "No changes to push" | |
| - name: Run tests | |
| run: | | |
| # Run mypy | |
| mypy dataspace_sdk/ --ignore-missing-imports --config-file=/dev/null | |
| # Run pytest | |
| pytest tests/test_auth.py tests/test_base.py tests/test_client.py tests/test_datasets.py tests/test_aimodels.py tests/test_usecases.py tests/test_exceptions.py -v -p no:django -o addopts= --override-ini=django_find_project=false --noconftest --cov=dataspace_sdk --cov-report=term-missing | |
| - name: Build package | |
| run: | | |
| python -m build | |
| - name: Check package | |
| run: | | |
| twine check dist/* | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| twine upload dist/* | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ inputs.version }} | |
| release_name: SDK v${{ inputs.version }} | |
| body: ${{ inputs.release_notes }} | |
| draft: false | |
| prerelease: false |