|
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 |
| 1 | +name: Upload motrackers to PyPI |
10 | 2 |
|
| 3 | +# Making this workflow only run when a new tag is added to the GitHub repo. |
| 4 | +# As done here: |
| 5 | +# https://stackoverflow.com/questions/18216991/create-a-tag-in-a-github-repository |
11 | 6 | on: |
12 | | - release: |
13 | | - types: [published] |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - "v*" |
14 | 10 |
|
15 | 11 | permissions: |
16 | 12 | contents: read |
17 | 13 |
|
18 | 14 | jobs: |
19 | | - deploy: |
20 | | - |
| 15 | + build-n-publish: |
| 16 | + name: Build and publish to PyPI |
21 | 17 | runs-on: ubuntu-latest |
22 | | - |
| 18 | + |
23 | 19 | steps: |
24 | | - - uses: actions/checkout@v3 |
25 | | - - name: Set up Python |
26 | | - uses: actions/setup-python@v3 |
27 | | - with: |
28 | | - python-version: '3.x' |
29 | | - - name: Install dependencies |
30 | | - run: | |
31 | | - python -m pip install --upgrade pip |
32 | | - pip install build |
33 | | - - name: Build package |
34 | | - run: python -m build |
35 | | - - name: Publish package |
36 | | - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 |
37 | | - with: |
38 | | - user: __token__ |
39 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 20 | + - name: Checkout source |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v3 |
| 25 | + with: |
| 26 | + python-version: '3.x' |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + pip install build |
| 31 | +
|
| 32 | + - name: Build source and wheel distributions |
| 33 | + run: | |
| 34 | + sudo apt-get update |
| 35 | + pip install --upgrade pip |
| 36 | + python -m pip install --upgrade build twine |
| 37 | + python -m build |
| 38 | + twine check --strict dist/* |
| 39 | +
|
| 40 | + - name: Publish distribution to PyPI |
| 41 | + uses: pypa/gh-action-pypi-publish@master |
| 42 | + with: |
| 43 | + user: __token__ |
| 44 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 45 | + |
| 46 | + - name: Create GitHub Release |
| 47 | + id: create_release |
| 48 | + uses: actions/create-release@v1 |
| 49 | + env: |
| 50 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 51 | + with: |
| 52 | + tag_name: ${{ github.ref }} |
| 53 | + release_name: ${{ github.ref }} |
| 54 | + draft: false |
| 55 | + prerelease: false |
| 56 | + |
| 57 | + - name: Get Asset name |
| 58 | + run: | |
| 59 | + export PKG=$(ls dist/ | grep tar) |
| 60 | + set -- $PKG |
| 61 | + echo "name=$1" >> $GITHUB_ENV |
| 62 | + - name: Upload Release Asset (sdist) to GitHub |
| 63 | + id: upload-release-asset |
| 64 | + uses: actions/upload-release-asset@v1 |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + with: |
| 68 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 69 | + asset_path: dist/${{ env.name }} |
| 70 | + asset_name: ${{ env.name }} |
| 71 | + asset_content_type: application/zip |
0 commit comments