|
| 1 | +name: Publish Python 🐍 distributions 📦 to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + # if the version.py changes, we should re-publish |
| 8 | + # this also allows us to run the workflow manually without skipping. |
| 9 | + - 'cartesia/version.py' |
| 10 | + |
| 11 | + # Allows you to run this workflow manually from the Actions tab |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + # Only run publishing when the commit message contains [bumpversion] |
| 17 | + # Auto-generated branches will be [bB]umpversion/<version>, so we also check for that. |
| 18 | + runs-on: ubuntu-latest |
| 19 | + environment: |
| 20 | + name: pypi |
| 21 | + url: https://pypi.org/p/cartesia |
| 22 | + # TODO: Make permissions more restrictive |
| 23 | + permissions: write-all |
| 24 | + env: |
| 25 | + commitmsg: ${{ github.event.head_commit.message }} |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v3 |
| 29 | + - name: Set up Python |
| 30 | + uses: actions/setup-python@v4 |
| 31 | + with: |
| 32 | + python-version: "3.10" |
| 33 | + |
| 34 | + - uses: actions/cache@v2 |
| 35 | + with: |
| 36 | + path: ~/.cache/pip |
| 37 | + key: ${{ runner.os }}-pip |
| 38 | + |
| 39 | + - name: Print commit message |
| 40 | + run: echo "Commit MSG = ${commitmsg}" |
| 41 | + |
| 42 | + - name: Install Dependencies |
| 43 | + run: | |
| 44 | + python -m pip install --upgrade pip |
| 45 | + pip install -e ".[all]" |
| 46 | + pip install importlib_metadata==7.2.1 |
| 47 | +
|
| 48 | + - name: Build PyPI |
| 49 | + run: | |
| 50 | + python setup.py upload --skip-upload |
| 51 | + twine check dist/* |
| 52 | +
|
| 53 | + - name: Publish distribution 📦 to PyPI |
| 54 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 55 | + with: |
| 56 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 57 | + verbose: true |
| 58 | + |
| 59 | + - name: Get version |
| 60 | + run: | |
| 61 | + export CARTESIA_PYTHON_VERSION=$(grep -o '".*"' cartesia/version.py | sed 's/"//g') |
| 62 | + echo "CARTESIA_PYTHON_VERSION=${CARTESIA_PYTHON_VERSION}" >> $GITHUB_ENV |
| 63 | +
|
| 64 | + - name: Verify version |
| 65 | + run: echo ${{ env.CARTESIA_PYTHON_VERSION }} |
| 66 | + |
| 67 | + - name: Bump version and push tag |
| 68 | + id: tag_version |
| 69 | + uses: mathieudutour/[email protected] |
| 70 | + with: |
| 71 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + custom_tag: ${{ env.CARTESIA_PYTHON_VERSION }} |
0 commit comments