From 536d534ab4739912b0b7f10c2b4b3776c91c7d05 Mon Sep 17 00:00:00 2001 From: mauwii Date: Sat, 4 Feb 2023 22:58:21 +0100 Subject: [PATCH] add pypi-release.yml and pypi-helper.py --- .github/workflows/pypi-release.yml | 44 ++++++++++++++++++++++++++++++ scripts/pypi-helper.py | 27 ++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 .github/workflows/pypi-release.yml create mode 100644 scripts/pypi-helper.py diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml new file mode 100644 index 0000000000..95243bf1fe --- /dev/null +++ b/.github/workflows/pypi-release.yml @@ -0,0 +1,44 @@ +name: PyPI Release + +on: + push: + branches: + - "dev/ci/add-pypi-release" + paths: + - 'ldm/invoke/_version.py' + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-22.04 + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + TWINE_NON_INTERACTIVE: 1 + steps: + - name: checkout sources + uses: actions/checkout@v3 + + - name: install deps + run: pip install --upgrade build twine + + - name: build package + run: python3 -m build + + - name: check distribution + run: twine check dist/* + + - name: check PyPI versions + # if: github.ref == 'refs/heads/main' + run: | + pip install --upgrade requests + python -c "\ + import scripts.pypi_helper; \ + EXISTS=scripts.pypi_helper.local_on_pypi(); \ + print(f'PACKAGE_EXISTS={EXISTS}')" >> $GITHUB_ENV + + - name: just for debugging + run: echo $PACKAGE_EXISTS + # - name: upload package + # if: env.PACKAGE_EXISTS == 'False' + # run: twine upload dist/* diff --git a/scripts/pypi-helper.py b/scripts/pypi-helper.py new file mode 100644 index 0000000000..66560d11c6 --- /dev/null +++ b/scripts/pypi-helper.py @@ -0,0 +1,27 @@ +import requests as request + +import ldm.invoke._version as version + +local_version = str(version.__version__) + + +def get_pypi_versions(package_name="InvokeAI") -> list[str]: + """Get the versions of the package from PyPI""" + url = f"https://pypi.org/pypi/{package_name}/json" + response = request.get(url).json() + versions: list[str] = list(response["releases"].keys()) + return versions + + +def local_on_pypi(package_name="InvokeAI", local_version=local_version) -> bool: + """Compare the versions of the package from PyPI and the local package""" + pypi_versions = get_pypi_versions(package_name) + return local_version in pypi_versions + + +if __name__ == "__main__": + package_name = "InvokeAI" + if local_on_pypi(): + print(f"Package {package_name} is up to date") + else: + print(f"Package {package_name} is not up to date")