|
| 1 | +name: Publish ${package_name} to PyPI / GitHub |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-n-publish: |
| 10 | + name: Build and publish to PyPI |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout source |
| 15 | + uses: actions/checkout@v2 |
| 16 | + |
| 17 | + - name: Set up Python |
| 18 | + uses: actions/setup-python@v2 |
| 19 | + with: |
| 20 | + python-version: "3.x" |
| 21 | + |
| 22 | + - name: Build source and wheel distributions |
| 23 | + run: | |
| 24 | + python -m pip install --upgrade build twine |
| 25 | + python -m build |
| 26 | + twine check --strict dist/* |
| 27 | + - name: Publish distribution to PyPI |
| 28 | + uses: pypa/gh-action-pypi-publish@master |
| 29 | + with: |
| 30 | + user: __token__ |
| 31 | + password: ${{ secrets.PYPI_TOKEN }} |
| 32 | + |
| 33 | + - name: Create GitHub Release |
| 34 | + id: create_release |
| 35 | + uses: actions/create-release@v1 |
| 36 | + env: |
| 37 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 38 | + with: |
| 39 | + tag_name: ${{ github.ref }} |
| 40 | + release_name: ${{ github.ref }} |
| 41 | + draft: false |
| 42 | + prerelease: false |
| 43 | + |
| 44 | + - name: Get Asset name |
| 45 | + run: | |
| 46 | + export PKG=$(ls dist/ | grep tar) |
| 47 | + set -- $PKG |
| 48 | + echo "name=$1" >> $GITHUB_ENV |
| 49 | + - name: Upload Release Asset (sdist) to GitHub |
| 50 | + id: upload-release-asset |
| 51 | + uses: actions/upload-release-asset@v1 |
| 52 | + env: |
| 53 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + with: |
| 55 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 56 | + asset_path: dist/${{ env.name }} |
| 57 | + asset_name: ${{ env.name }} |
| 58 | + asset_content_type: application/zip |
0 commit comments