Merge pull request #13 from BBEK-Anand/BBEK-Anand-patch-2 #31
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 to PyPI / TestPyPI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| # Bump version for main (PyPI) | |
| - name: Bump patch version for PyPI | |
| if: github.ref == 'refs/heads/main' | |
| run: python scripts/bump_version.py | |
| # Set dev version for TestPyPI | |
| - name: Set dev version for TestPyPI | |
| if: github.ref == 'refs/heads/dev' | |
| run: | | |
| BASE_VERSION=$(grep -oP "__version__ = '\K[^']+" src/PTLF/_version.py) | |
| DATE=$(date +%Y%m%d%H%M%S%N) | |
| GIT_HASH=$(git rev-parse --short HEAD) | |
| DEV_VERSION="${BASE_VERSION}.dev${DATE}" | |
| echo "__version__ = '${DEV_VERSION}'" > src/PTLF/_version.py | |
| echo "✅ Set dev version: $DEV_VERSION" | |
| # Show current version file for debugging | |
| - name: Show current version | |
| run: cat src/PTLF/_version.py | |
| # Clean old builds before build | |
| - name: Clean old builds | |
| run: rm -rf dist | |
| - name: Build package | |
| run: python -m build | |
| - name: Upload dist artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-files | |
| path: dist/ | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download dist artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist-files | |
| path: dist/ | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Twine | |
| run: pip install twine | |
| - name: Publish to PyPI or TestPyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| run: | | |
| if [ "${GITHUB_REF}" = "refs/heads/main" ]; then | |
| echo "🚀 Publishing to PyPI" | |
| twine upload --verbose -u __token__ -p "$PYPI_TOKEN" dist/* | |
| elif [ "${GITHUB_REF}" = "refs/heads/dev" ]; then | |
| echo "🧪 Publishing to TestPyPI" | |
| twine upload --verbose --repository-url https://test.pypi.org/legacy/ -u __token__ -p "$TEST_PYPI_TOKEN" dist/* | |
| fi |