diff --git a/.github/workflows/test_and_deploy.yaml b/.github/workflows/test_and_deploy.yaml index ea57e40e..9b14a295 100644 --- a/.github/workflows/test_and_deploy.yaml +++ b/.github/workflows/test_and_deploy.yaml @@ -39,8 +39,7 @@ jobs: - name: Check the current version on PyPi id: version_step_pypi run: | - python -m pip install osmg --upgrade - latest=$(pip show osmg | grep 'Version:' | awk '{print $2}') + 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 @@ -50,6 +49,7 @@ jobs: 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 diff --git a/src/osmg/get_latest_pypi_version.py b/src/osmg/get_latest_pypi_version.py new file mode 100644 index 00000000..0c0191f3 --- /dev/null +++ b/src/osmg/get_latest_pypi_version.py @@ -0,0 +1,20 @@ +import requests + + +def get_latest_version(package_name): + url = f"https://pypi.org/pypi/{package_name}/json" + + try: + response = requests.get(url) + package_info = response.json() + latest_version = package_info['info']['version'] + return latest_version + except Exception as e: + print(f"An error occurred: {e}") + return None + + +if __name__ == '__main__': + package = 'osmg' + version = get_latest_version(package) + print(version)