|
| 1 | +# This workflow will upload a Python Package using Twine when a release is created |
| 2 | +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries |
| 3 | + |
| 4 | +# This workflow uses actions that are not certified by GitHub. |
| 5 | +# They are provided by a third-party and are governed by |
| 6 | +# separate terms of service, privacy policy, and support |
| 7 | +# documentation. |
| 8 | + |
| 9 | +name: Upload Python Package |
| 10 | + |
| 11 | +on: |
| 12 | + release: |
| 13 | + types: [published] |
| 14 | + push: |
| 15 | + branches: [main] |
| 16 | + |
| 17 | +jobs: |
| 18 | + deploy: |
| 19 | + |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 25 | + if: github.event_name == 'push' |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v2 |
| 28 | + with: |
| 29 | + python-version: '3.x' |
| 30 | + - name: Install dependencies |
| 31 | + id: set-version |
| 32 | + run: | |
| 33 | + VERSION=$(grep version setup.cfg | cut -d= -f2 | tr -d '[:blank:]') |
| 34 | + [ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/} |
| 35 | + [ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=b && VERSION+=$(($(git tag -l "*$VERSION*" | cut -db -f2 | sort -n | tail -1)+1)) |
| 36 | + sed -ie "s/version = .*/version = $VERSION/" setup.cfg |
| 37 | + python -m pip install --upgrade pip |
| 38 | + pip install build |
| 39 | + echo ::set-output name=version::$VERSION |
| 40 | + NAME="sqlalchemy_iris"-${VERSION}-py3-none-any |
| 41 | + echo ::set-output name=name::$NAME |
| 42 | + - name: Build package |
| 43 | + run: python -m build |
| 44 | + - name: Publish package |
| 45 | + uses: pypa/gh-action-pypi-publish@release/v1.5 |
| 46 | + with: |
| 47 | + user: __token__ |
| 48 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 49 | + - name: Create Beta Release |
| 50 | + id: create_release |
| 51 | + if: github.event_name == 'push' |
| 52 | + uses: actions/create-release@v1 |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + with: |
| 56 | + tag_name: ${{ steps.set-version.outputs.version }} |
| 57 | + release_name: ${{ steps.set-version.outputs.version }} |
| 58 | + prerelease: ${{ github.event_name != 'release' }} |
| 59 | + - name: Upload Release Asset |
| 60 | + id: upload-release-asset |
| 61 | + uses: actions/upload-release-asset@v1 |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + with: |
| 65 | + upload_url: ${{ github.event_name == 'release' && github.event.release.upload_url || steps.create_release.outputs.upload_url }} |
| 66 | + asset_path: dist/${{ steps.set-version.outputs.name }}.whl |
| 67 | + asset_name: ${{ steps.set-version.outputs.name }}.whl |
| 68 | + asset_content_type: application/zip |
| 69 | + - uses: actions/checkout@v2 |
| 70 | + if: github.event_name == 'release' |
| 71 | + with: |
| 72 | + ref: main |
| 73 | + - name: Bump version |
| 74 | + if: github.event_name == 'release' |
| 75 | + run: | |
| 76 | + git config --global user.name 'ProjectBot' |
| 77 | + git config --global user.email 'bot@users.noreply.github.com' |
| 78 | + VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/} |
| 79 | + VERSION=`echo $VERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.` |
| 80 | + sed -ie "s/version = .*/version = $VERSION/" setup.cfg |
| 81 | + git add setup.cfg |
| 82 | + git commit -m 'auto bump version with release' |
| 83 | + git push |
0 commit comments