|
| 1 | +name: Publish to PyPI / TestPyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: '3.11' |
| 19 | + |
| 20 | + - name: Install build tools |
| 21 | + run: | |
| 22 | + python -m pip install --upgrade pip |
| 23 | + pip install build |
| 24 | +
|
| 25 | + # Bump version for main (PyPI) |
| 26 | + - name: Bump patch version for PyPI |
| 27 | + if: github.ref == 'refs/heads/main' |
| 28 | + run: python scripts/bump_version.py |
| 29 | + |
| 30 | + # Set dev version for TestPyPI |
| 31 | + - name: Set dev version for TestPyPI |
| 32 | + if: github.ref == 'refs/heads/dev' |
| 33 | + run: | |
| 34 | + BASE_VERSION=$(grep -oP "__version__ = '\K[^']+" src/PTLF/_version.py) |
| 35 | + DATE=$(date +%Y%m%d%H%M%S%N) |
| 36 | + GIT_HASH=$(git rev-parse --short HEAD) |
| 37 | + DEV_VERSION="${BASE_VERSION}.dev${DATE}" |
| 38 | + echo "__version__ = '${DEV_VERSION}'" > src/PTLF/_version.py |
| 39 | + echo "✅ Set dev version: $DEV_VERSION" |
| 40 | +
|
| 41 | + # Show current version file for debugging |
| 42 | + - name: Show current version |
| 43 | + run: cat src/PTLF/_version.py |
| 44 | + |
| 45 | + # Clean old builds before build |
| 46 | + - name: Clean old builds |
| 47 | + run: rm -rf dist |
| 48 | + |
| 49 | + - name: Build package |
| 50 | + run: python -m build |
| 51 | + |
| 52 | + - name: Upload dist artifact |
| 53 | + uses: actions/upload-artifact@v4 |
| 54 | + with: |
| 55 | + name: dist-files |
| 56 | + path: dist/ |
| 57 | + |
| 58 | + publish: |
| 59 | + needs: build |
| 60 | + runs-on: ubuntu-latest |
| 61 | + steps: |
| 62 | + - name: Download dist artifact |
| 63 | + uses: actions/download-artifact@v4 |
| 64 | + with: |
| 65 | + name: dist-files |
| 66 | + path: dist/ |
| 67 | + |
| 68 | + - name: Set up Python |
| 69 | + uses: actions/setup-python@v5 |
| 70 | + with: |
| 71 | + python-version: '3.11' |
| 72 | + |
| 73 | + - name: Install Twine |
| 74 | + run: pip install twine |
| 75 | + |
| 76 | + - name: Publish to PyPI or TestPyPI |
| 77 | + env: |
| 78 | + TWINE_USERNAME: __token__ |
| 79 | + PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
| 80 | + TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 81 | + run: | |
| 82 | + if [ "${GITHUB_REF}" = "refs/heads/main" ]; then |
| 83 | + echo "🚀 Publishing to PyPI" |
| 84 | + twine upload --verbose -u __token__ -p "$PYPI_TOKEN" dist/* |
| 85 | + elif [ "${GITHUB_REF}" = "refs/heads/dev" ]; then |
| 86 | + echo "🧪 Publishing to TestPyPI" |
| 87 | + twine upload --verbose --repository-url https://test.pypi.org/legacy/ -u __token__ -p "$TEST_PYPI_TOKEN" dist/* |
| 88 | + fi |
0 commit comments