Deploy to PyPI if Tests Pass #1
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: Deploy to PyPI if Tests Pass | |
on: | |
workflow_run: | |
workflows: ["Run Tests"] | |
branches: [main] | |
types: | |
- completed | |
jobs: | |
deploy: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
environment: release | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v3 | |
with: | |
python-version: 3.9 | |
- name: Check the current version on PyPi | |
run: | | |
python -m pip install requests | |
latest=$(python src/osmg/get_latest_pypi_version.py) | |
echo "Latest Version found on PyPi: $latest" | |
echo "PYPI_VERSION=$latest" >> $GITHUB_ENV | |
- name: Check the current version on setup.cfg | |
run: | | |
version=$(grep '^version' setup.cfg | awk -F= '{print $2}' | tr -d '[:space:]') | |
echo "Version found in setup.cfg: $version" | |
echo "SETUPCFG_VERSION=$version" >> $GITHUB_ENV | |
- name: Prepare package | |
if: ${{ env.PYPI_VERSION != env.SETUPCFG_VERSION }} | |
run: | | |
python -m pip install --upgrade pip setuptools wheel twine | |
python setup.py sdist bdist_wheel | |
python -m twine check dist/* | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: dist | |
path: dist | |
- name: Deploy | |
if: ${{ env.PYPI_VERSION != env.SETUPCFG_VERSION }} | |
uses: pypa/gh-action-pypi-publish@release/v1 |