Upload Python Package to PYPI #6
Workflow file for this run
This file contains 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: Upload Python Package to PYPI | |
on: | |
release: | |
types: | |
- created | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install --upgrade setuptools wheel build twine | |
- name: Get current version from pyproject.toml | |
id: get_version | |
run: echo "::set-output name=version::$(grep -oP '(?<=version = ")[^"]*' pyproject.toml)" | |
- name: Increment version | |
id: increment_version | |
run: echo "::set-output name=version::$(python -c "version='${{ steps.get_version.outputs.version }}'.split('.'); version[-1] = str(int(version[-1]) + 1); print('.'.join(version))")" | |
- name: Update version in pyproject.toml | |
run: sed -i "s/version = \".*\"/version = \"${{ steps.increment_version.outputs.version }}\"/" pyproject.toml | |
- name: Commit changes to pyproject.toml | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Per Helge Aarnes" | |
git add pyproject.toml | |
git commit -m "Bump version to ${{ steps.increment_version.outputs.version }}" | |
- name: Push changes to the master branch | |
run: git push origin HEAD:${{ github.ref }} | |
if: github.ref == 'refs/heads/master' | |
- name: Build and upload to PyPI (master branch) | |
if: github.ref == 'refs/heads/master' | |
run: | | |
python -m build | |
twine upload --repository-url https://upload.pypi.org/legacy/ --username __token__ --password ${{ secrets.PYPI_TOKEN }} dist/* |