Skip to content

fix: Fix monorepo CI workflow pip install paths #1

fix: Fix monorepo CI workflow pip install paths

fix: Fix monorepo CI workflow pip install paths #1

name: Release CI
on:
push:
tags:
# Match version tags with package prefix
- 'async-cassandra-v[0-9]*'
- 'async-cassandra-bulk-v[0-9]*'
jobs:
determine-package:
runs-on: ubuntu-latest
outputs:
package: ${{ steps.determine.outputs.package }}
version: ${{ steps.determine.outputs.version }}
steps:
- name: Determine package from tag
id: determine
run: |
TAG="${{ github.ref_name }}"
if [[ "$TAG" =~ ^async-cassandra-v(.*)$ ]]; then
echo "package=async-cassandra" >> $GITHUB_OUTPUT
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
elif [[ "$TAG" =~ ^async-cassandra-bulk-v(.*)$ ]]; then
echo "package=async-cassandra-bulk" >> $GITHUB_OUTPUT
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
else
echo "Unknown tag format: $TAG"
exit 1
fi
full-ci:
needs: determine-package
uses: ./.github/workflows/ci-monorepo.yml
with:
package: ${{ needs.determine-package.outputs.package }}
run-integration-tests: true
run-full-suite: ${{ needs.determine-package.outputs.package == 'async-cassandra' }}
build-package:
needs: [determine-package, full-ci]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
cd libs/${{ needs.determine-package.outputs.package }}
python -m build
- name: Check package
run: |
cd libs/${{ needs.determine-package.outputs.package }}
twine check dist/*
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: libs/${{ needs.determine-package.outputs.package }}/dist/
retention-days: 7
publish-testpypi:
name: Publish to TestPyPI
needs: [determine-package, build-package]
runs-on: ubuntu-latest
# Only publish for proper pre-release versions (PEP 440)
if: contains(needs.determine-package.outputs.version, 'rc') || contains(needs.determine-package.outputs.version, 'a') || contains(needs.determine-package.outputs.version, 'b')
permissions:
id-token: write # Required for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: List distribution files
run: |
echo "Distribution files to be published:"
ls -la dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
verbose: true
- name: Create TestPyPI Summary
run: |
echo "## 📦 Published to TestPyPI" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Package: ${{ needs.determine-package.outputs.package }}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ needs.determine-package.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ${{ needs.determine-package.outputs.package }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "View on TestPyPI: https://test.pypi.org/project/${{ needs.determine-package.outputs.package }}/" >> $GITHUB_STEP_SUMMARY
validate-testpypi:
name: Validate TestPyPI Package
needs: [determine-package, publish-testpypi]
runs-on: ubuntu-latest
# Only validate for pre-release versions that were published to TestPyPI
if: contains(needs.determine-package.outputs.version, 'rc') || contains(needs.determine-package.outputs.version, 'a') || contains(needs.determine-package.outputs.version, 'b')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Wait for package availability
run: |
echo "Waiting for package to be available on TestPyPI..."
sleep 30
- name: Install from TestPyPI
run: |
VERSION="${{ needs.determine-package.outputs.version }}"
PACKAGE="${{ needs.determine-package.outputs.package }}"
echo "Installing $PACKAGE version: $VERSION"
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple $PACKAGE==$VERSION
- name: Test imports
run: |
PACKAGE="${{ needs.determine-package.outputs.package }}"
if [ "$PACKAGE" = "async-cassandra" ]; then
python -c "import async_cassandra; print(f'✅ Package version: {async_cassandra.__version__}')"
else
python -c "import async_cassandra_bulk; print(f'✅ Package version: {async_cassandra_bulk.__version__}')"
fi
- name: Create validation summary
run: |
echo "## ✅ TestPyPI Validation Passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Package successfully installed and imported from TestPyPI" >> $GITHUB_STEP_SUMMARY
publish-pypi:
name: Publish to PyPI
needs: [determine-package, build-package]
runs-on: ubuntu-latest
# Only publish stable versions (no pre-release suffix)
if: "!contains(needs.determine-package.outputs.version, '-')"
permissions:
id-token: write # Required for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: List distribution files
run: |
echo "Distribution files to be published to PyPI:"
ls -la dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
print-hash: true
- name: Create PyPI Summary
run: |
echo "## 🚀 Published to PyPI" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Package: ${{ needs.determine-package.outputs.package }}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ needs.determine-package.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install ${{ needs.determine-package.outputs.package }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "View on PyPI: https://pypi.org/project/${{ needs.determine-package.outputs.package }}/" >> $GITHUB_STEP_SUMMARY
create-github-release:
name: Create GitHub Release
needs: [determine-package, build-package]
runs-on: ubuntu-latest
if: success()
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for release notes
- name: Check if pre-release
id: check-prerelease
run: |
VERSION="${{ needs.determine-package.outputs.version }}"
if [[ "$VERSION" =~ rc|a|b ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "Pre-release detected"
else
echo "prerelease=false" >> $GITHUB_OUTPUT
echo "Stable release detected"
fi
- name: Generate Release Notes
run: |
PACKAGE="${{ needs.determine-package.outputs.package }}"
VERSION="${{ needs.determine-package.outputs.version }}"
# Create release notes based on type
if [[ "$VERSION" =~ rc|a|b ]]; then
cat > release-notes.md << EOF
## Pre-release for Testing - $PACKAGE
⚠️ **This is a pre-release version available on TestPyPI**
### Installation
\`\`\`bash
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple $PACKAGE==$VERSION
\`\`\`
### Testing Instructions
Please test:
- Package installation
- Basic imports
- Report any issues on GitHub
### What's Changed
EOF
else
cat > release-notes.md << EOF
## Stable Release - $PACKAGE
### Installation
\`\`\`bash
pip install $PACKAGE
\`\`\`
### What's Changed
EOF
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: ${{ github.ref_name }}
tag_name: ${{ github.ref }}
prerelease: ${{ steps.check-prerelease.outputs.prerelease }}
generate_release_notes: true
body_path: release-notes.md
draft: false