|
| 1 | +name: Check and Publish to PyPi |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - '*.*.*' # Eg. 0.0.1 |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + PublishToPyPi: |
| 10 | + environment: |
| 11 | + name: Production |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout source code |
| 15 | + uses: actions/checkout@v3 |
| 16 | + |
| 17 | + - name: Installing python 3.10 |
| 18 | + uses: actions/setup-python@v4 |
| 19 | + with: |
| 20 | + python-version: '3.10' |
| 21 | + |
| 22 | + - name: Installing git |
| 23 | + run: pip install gitpython |
| 24 | + |
| 25 | + - name: Generate local version |
| 26 | + run: python freeze_version.py |
| 27 | + |
| 28 | + - name: Fetch local package version |
| 29 | + run: | |
| 30 | + packageLocalVersion=$(python -c 'from version import version; print(version);') |
| 31 | + echo "localVersion=$packageLocalVersion" >> $GITHUB_ENV |
| 32 | +
|
| 33 | + - name: Fetch remote package version |
| 34 | + run: | |
| 35 | + packageRemoteVersion=$(python -c "exec(\"import pkg_resources\\ntry: print(pkg_resources.get_distribution('python_ms_core').version)\\nexcept pkg_resources.DistributionNotFound: print('0.0.0');\")") |
| 36 | + echo "remoteVersion=$packageRemoteVersion" >> $GITHUB_ENV |
| 37 | +
|
| 38 | + - name: Printing local and remote versions |
| 39 | + run: echo "Local version ${{env.localVersion}} and remote version ${{env.remoteVersion}}" |
| 40 | + |
| 41 | + - name: Compare local and remote version with dpkg |
| 42 | + run: dpkg --compare-versions ${{env.localVersion}} "gt" ${{env.remoteVersion}} |
| 43 | + |
| 44 | + - name: Install Requirements |
| 45 | + run: pip install -r requirements.txt |
| 46 | + |
| 47 | + - name: Setup python wheel |
| 48 | + run: pip install wheel |
| 49 | + |
| 50 | + - name: Building Package |
| 51 | + run: python setup.py bdist_wheel |
| 52 | + |
| 53 | + - name: Publish package |
| 54 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 55 | + with: |
| 56 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 57 | + |
0 commit comments