From b29361af9bcfbd4e73295ae501adc0becec38a0d Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 4 Oct 2025 21:51:28 +0100 Subject: [PATCH 1/2] Add PyPI version check to version_check.py script --- .github/scripts/version_check.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/scripts/version_check.py b/.github/scripts/version_check.py index c6073bb..d1ccef5 100644 --- a/.github/scripts/version_check.py +++ b/.github/scripts/version_check.py @@ -1,6 +1,7 @@ import sys import tomllib import urllib.request +import urllib.error import json from packaging.version import Version @@ -16,5 +17,24 @@ if loc <= rem: print(f"❌ {loc} <= {rem}, bump Cargo.toml") sys.exit(1) - + print(f"✅ {loc} > {rem}") +# make the same check on pypi +pypi_url = f"https://pypi.org/pypi/{name}/json" +try: + json_data = json.load(urllib.request.urlopen(pypi_url)) + rem = Version(json_data["info"]["version"]) + print(f"PyPI: {name}") + print(f"Local: {loc}") + print(f"Remote: {rem}") + + if loc <= rem: + print(f"❌ {loc} <= {rem}, bump Cargo.toml") + sys.exit(1) + + print(f"✅ {loc} > {rem}") +except urllib.error.HTTPError as e: + if e.code == 404: + print(f"✅ {name} not found on PyPI, good to publish") + else: + raise e From 7b9cc8fe99b8e81f5c60183dee3e318ad5d08895 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:04:20 +0100 Subject: [PATCH 2/2] Add version check job to CI workflows and refactor version check action --- .github/actions/version-check/action.yml | 33 ++++++++++++++++++++++++ .github/workflows/ci-build-wheels.yml | 11 +++++++- .github/workflows/ci-develop.yml | 11 +++----- .github/workflows/ci-test.yml | 10 +++---- .github/workflows/ci-tests-main.yml | 10 +++++++ .github/workflows/publish-crates-io.yml | 9 ++++--- .github/workflows/publish-pypi.yml | 10 +++++++ .github/workflows/publish-test-pypi.yml | 10 +++++++ 8 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 .github/actions/version-check/action.yml diff --git a/.github/actions/version-check/action.yml b/.github/actions/version-check/action.yml new file mode 100644 index 0000000..9ac06fb --- /dev/null +++ b/.github/actions/version-check/action.yml @@ -0,0 +1,33 @@ +name: Version Check +description: Fail if Cargo.toml version is not greater than crates.io and PyPI published versions +author: git-insights maintainers + +inputs: + python-version: + description: Python version to use for running the check + required: false + default: "3.12" + working-directory: + description: Directory to run the version check from (where Cargo.toml is located) + required: false + default: "." + +runs: + using: composite + steps: + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Install Python dependencies + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + python -m pip install --upgrade pip + pip install "packaging>=24.0" + + - name: Run version check script + shell: bash + working-directory: ${{ inputs.working-directory }} + run: python .github/scripts/version_check.py diff --git a/.github/workflows/ci-build-wheels.yml b/.github/workflows/ci-build-wheels.yml index 3f26ff9..3e68600 100644 --- a/.github/workflows/ci-build-wheels.yml +++ b/.github/workflows/ci-build-wheels.yml @@ -17,9 +17,19 @@ env: UV_RESOLUTION_STRATEGY: highest jobs: + version-check: + name: Version check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./.github/actions/version-check + with: + python-version: "3.12" + build-test-package: name: build-test-package runs-on: ${{ matrix.os }} + needs: version-check strategy: fail-fast: false matrix: @@ -88,4 +98,3 @@ jobs: echo "The build-test-package job did not succeed." exit 1 fi - diff --git a/.github/workflows/ci-develop.yml b/.github/workflows/ci-develop.yml index 48de26e..082c319 100644 --- a/.github/workflows/ci-develop.yml +++ b/.github/workflows/ci-develop.yml @@ -19,15 +19,12 @@ jobs: steps: - uses: actions/checkout@v5 - - name: Set up Python 3.12 - uses: actions/setup-python@v5 + - uses: ./.github/actions/version-check with: python-version: "3.12" - - name: Run ci-health scripts - run: | - pip install packaging - python .github/scripts/version_check.py - python .github/scripts/commit_emails_check.py + + - name: Run commit emails check + run: python .github/scripts/commit_emails_check.py unittest-develop: name: unittest-develop diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index f43e181..7b319c0 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -19,15 +19,11 @@ jobs: steps: - uses: actions/checkout@v5 - - name: Set up Python 3.12 - uses: actions/setup-python@v5 + - uses: ./.github/actions/version-check with: python-version: "3.12" - - name: Run ci-health scripts - run: | - pip install packaging - python .github/scripts/version_check.py - python .github/scripts/commit_emails_check.py + - name: Run commit emails check + run: python .github/scripts/commit_emails_check.py unittest-test: name: unittest-test diff --git a/.github/workflows/ci-tests-main.yml b/.github/workflows/ci-tests-main.yml index af29017..a51ff6e 100644 --- a/.github/workflows/ci-tests-main.yml +++ b/.github/workflows/ci-tests-main.yml @@ -13,8 +13,18 @@ env: UV_RESOLUTION_STRATEGY: highest jobs: + version-check: + name: Version check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./.github/actions/version-check + with: + python-version: "3.12" + unittest-main: name: unittest-main + needs: version-check runs-on: ${{ matrix.os }} strategy: fail-fast: false diff --git a/.github/workflows/publish-crates-io.yml b/.github/workflows/publish-crates-io.yml index dec34e9..7811778 100644 --- a/.github/workflows/publish-crates-io.yml +++ b/.github/workflows/publish-crates-io.yml @@ -13,10 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - - name: Check crate version on crates.io - run: | - python .github/scripts/version_check.py - python .github/scripts/commit_emails_check.py + - uses: ./.github/actions/version-check + with: + python-version: "3.12" + - name: Run commit emails check + run: python .github/scripts/commit_emails_check.py unittests-release: name: Unit Tests (Release) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 18ee648..8236df7 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -15,9 +15,19 @@ env: UV_RESOLUTION_STRATEGY: highest jobs: + version-check: + name: Version check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./.github/actions/version-check + with: + python-version: "3.12" + build-test-package: name: Build & test (${{ matrix.os }}) runs-on: ${{ matrix.os }} + needs: version-check strategy: fail-fast: false matrix: diff --git a/.github/workflows/publish-test-pypi.yml b/.github/workflows/publish-test-pypi.yml index 1260f30..7f4d6ed 100644 --- a/.github/workflows/publish-test-pypi.yml +++ b/.github/workflows/publish-test-pypi.yml @@ -14,9 +14,19 @@ env: UV_RESOLUTION_STRATEGY: highest jobs: + version-check: + name: Version check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./.github/actions/version-check + with: + python-version: "3.12" + build-test-package: name: Build & test (${{ matrix.os }}) runs-on: ${{ matrix.os }} + needs: version-check strategy: fail-fast: false matrix: