From 4d0e3c3700e970824ecb4631f6d98f0db6ddd227 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Tue, 25 Mar 2025 11:53:20 -0700 Subject: [PATCH 01/27] Fixed the ability to override the API URL for Socket Requests --- socketsecurity/__init__.py | 2 +- socketsecurity/socketcli.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index b8c6665..0be278f 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.14' +__version__ = '2.0.15' diff --git a/socketsecurity/socketcli.py b/socketsecurity/socketcli.py index 5a75438..612ad1e 100644 --- a/socketsecurity/socketcli.py +++ b/socketsecurity/socketcli.py @@ -71,6 +71,7 @@ def main_code(): ) log.debug("loaded socket_config") client = CliClient(socket_config) + sdk.api.api_url = socket_config.api_url log.debug("loaded client") core = Core(socket_config, sdk) log.debug("loaded core") From 44298a27accc4bb0ab5fd6bc28cb82ba249be36d Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 16:53:32 -0700 Subject: [PATCH 02/27] Changed over to hatchling for releases --- Pipfile.lock | 4 ++-- pyproject.toml | 30 +++++++++++++++--------------- requirements-dev.lock | 3 +-- requirements.lock | 3 +-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Pipfile.lock b/Pipfile.lock index b6df5da..77f078c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "702ad05de9bc9de99a4807c8dde1686f31e0041d7b5f6f6b74861195a52110f5" + "sha256": "7e8ad3d0508bf0c279a648ee7a1873fc16334cf0b711f30b2dc54a1da68fef6c" }, "pipfile-spec": 6, "requires": { @@ -10,7 +10,7 @@ "sources": [ { "name": "pypi", - "url": "https://pypi.org/simple", + "url": "https://pypi.org/socketsecurity", "verify_ssl": true } ] diff --git a/pyproject.toml b/pyproject.toml index 6ea62cf..bf7f39a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,14 @@ [build-system] -requires = ["setuptools >= 61.0"] -build-backend = "setuptools.build_meta" +requires = [ + "hatchling", + "hatch-vcs" +] +build-backend = "hatchling.build" [project] name = "socketsecurity" dynamic = ["version"] -requires-python = ">= 3.9" +requires-python = ">= 3.10" dependencies = [ 'requests', 'mdutils', @@ -13,7 +16,7 @@ dependencies = [ 'GitPython', 'packaging', 'python-dotenv', - 'socket-sdk-python>=2.0.9' + 'socket-sdk-python>=2.0.15' ] readme = "README.md" description = "Socket Security CLI for CI/CD" @@ -25,6 +28,7 @@ maintainers = [ {name = "Douglas Coburn", email = "douglas@socket.dev"} ] classifiers = [ + "License :: OSI Approved :: MIT License", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 3.11", @@ -51,16 +55,6 @@ socketcli = "socketsecurity.socketcli:cli" [project.urls] Homepage = "https://socket.dev" -[tool.setuptools.packages.find] -include = [ - "socketsecurity*" -] - -[tool.setuptools.dynamic] -version = {attr = "socketsecurity.__version__"} - - - [tool.coverage.run] source = ["socketsecurity"] branch = true @@ -163,4 +157,10 @@ docstring-code-format = false # # This only has an effect when the `docstring-code-format` setting is # enabled. -docstring-code-line-length = "dynamic" \ No newline at end of file +docstring-code-line-length = "dynamic" + +[tool.hatch.version] +source = "vcs" # Uses the latest git tag like v2.0.15 + +[tool.hatch.build.targets.wheel] +include = ["socketsecurity", "LICENSE"] \ No newline at end of file diff --git a/requirements-dev.lock b/requirements-dev.lock index 137e3e6..6d0be66 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -9,7 +9,6 @@ # generate-hashes: false # universal: false --e file:. argparse==1.4.0 # via socketsecurity certifi==2024.12.14 @@ -60,7 +59,7 @@ requests==2.32.3 # via socketsecurity smmap==5.0.2 # via gitdb -socket-sdk-python @ file:///Users/erichibbs/code/socket/socket-sdk-python +socket-sdk-python==2.0.15 # via socketsecurity typing-extensions==4.12.2 # via socket-sdk-python diff --git a/requirements.lock b/requirements.lock index 137e3e6..6d0be66 100644 --- a/requirements.lock +++ b/requirements.lock @@ -9,7 +9,6 @@ # generate-hashes: false # universal: false --e file:. argparse==1.4.0 # via socketsecurity certifi==2024.12.14 @@ -60,7 +59,7 @@ requests==2.32.3 # via socketsecurity smmap==5.0.2 # via gitdb -socket-sdk-python @ file:///Users/erichibbs/code/socket/socket-sdk-python +socket-sdk-python==2.0.15 # via socketsecurity typing-extensions==4.12.2 # via socket-sdk-python From 74712ea96a588419a5463abe0026119ee669313d Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:07:57 -0700 Subject: [PATCH 03/27] Updated release workflows for hatchling build --- .github/workflows/pr-preview.yml | 30 ++++++------------------------ .github/workflows/release.yml | 15 ++++++--------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 8f455fb..64c8d7e 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -18,20 +18,11 @@ jobs: python -m pip install --upgrade pip pip install -e . - - name: Set preview version + - name: Get Hatch version + id: version run: | - BASE_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)") - PREVIEW_VERSION="${BASE_VERSION}.dev${{ github.event.pull_request.number }}${{ github.event.pull_request.commits }}" - echo "VERSION=${PREVIEW_VERSION}" >> $GITHUB_ENV - - # Update version in __init__.py - echo "__version__ = \"${PREVIEW_VERSION}\"" > socketsecurity/__init__.py.tmp - cat socketsecurity/__init__.py | grep -v "__version__" >> socketsecurity/__init__.py.tmp - mv socketsecurity/__init__.py.tmp socketsecurity/__init__.py - - # Verify the change - echo "Updated version in __init__.py:" - python -c "from socketsecurity import __version__; print(__version__)" + VERSION=$(hatch version) + echo "VERSION=$VERSION" >> $GITHUB_ENV - name: Check if version exists on Test PyPI id: version_check @@ -49,23 +40,14 @@ jobs: - name: Build package if: steps.version_check.outputs.exists != 'true' run: | - pip install build - python -m build - - - name: Restore original version - if: always() - run: | - BASE_VERSION=$(echo $VERSION | cut -d'.' -f1-3) - echo "__version__ = \"${BASE_VERSION}\"" > socketsecurity/__init__.py.tmp - cat socketsecurity/__init__.py | grep -v "__version__" >> socketsecurity/__init__.py.tmp - mv socketsecurity/__init__.py.tmp socketsecurity/__init__.py + pip install hatchling + hatch build - name: Publish to Test PyPI if: steps.version_check.outputs.exists != 'true' uses: pypa/gh-action-pypi-publish@v1.8.11 with: repository-url: https://test.pypi.org/legacy/ - password: ${{ secrets.TEST_PYPI_TOKEN }} verbose: true - name: Comment on PR diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index beb6cc9..b68119f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,7 @@ name: Release on: - push: - tags: - - 'v*' + release: + types: [published] jobs: release: @@ -22,10 +21,10 @@ jobs: - name: Get Version id: version run: | - RAW_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)") + RAW_VERSION=$(hatch version) echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV if [ "v$RAW_VERSION" != "${{ github.ref_name }}" ]; then - echo "Error: Git tag (${{ github.ref_name }}) does not match package version (v$RAW_VERSION)" + echo "Error: Git tag (${{ github.ref_name }}) does not match hatch version (v$RAW_VERSION)" exit 1 fi @@ -57,14 +56,12 @@ jobs: - name: Build package if: steps.version_check.outputs.pypi_exists != 'true' run: | - pip install build - python -m build + pip install hatchling + hatch build - name: Publish to PyPI if: steps.version_check.outputs.pypi_exists != 'true' uses: pypa/gh-action-pypi-publish@v1.8.11 - with: - password: ${{ secrets.PYPI_TOKEN }} - name: Login to Docker Hub uses: docker/login-action@v3 From a4063710599c1bb36c5cba526fb3b103a18aa35e Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:20:21 -0700 Subject: [PATCH 04/27] Adding needed modules for build --- .github/workflows/pr-preview.yml | 3 +-- .github/workflows/release.yml | 1 + pyproject.toml | 1 - requirements-dev.lock | 3 +++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 64c8d7e..e5a7d39 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -17,7 +17,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -e . - + pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 - name: Get Hatch version id: version run: | @@ -40,7 +40,6 @@ jobs: - name: Build package if: steps.version_check.outputs.exists != 'true' run: | - pip install hatchling hatch build - name: Publish to Test PyPI diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b68119f..ad1bec3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -e . + pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 - name: Get Version id: version diff --git a/pyproject.toml b/pyproject.toml index bf7f39a..0ea4709 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,6 @@ maintainers = [ {name = "Douglas Coburn", email = "douglas@socket.dev"} ] classifiers = [ - "License :: OSI Approved :: MIT License", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 3.11", diff --git a/requirements-dev.lock b/requirements-dev.lock index 6d0be66..7c2367b 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -9,6 +9,9 @@ # generate-hashes: false # universal: false +hatchling==1.27.0 +hatch==1.14.0 +hatch-vcs==0.4.0 argparse==1.4.0 # via socketsecurity certifi==2024.12.14 From 1097255d02878979dae8af015fab61083f8ad825 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:25:52 -0700 Subject: [PATCH 05/27] Added pre-commit hook to sync tag to version in file --- .hooks/sync_versions.py | 40 ++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 9 +++++++++ 2 files changed, 49 insertions(+) create mode 100644 .hooks/sync_versions.py create mode 100644 .pre-commit-config.yaml diff --git a/.hooks/sync_versions.py b/.hooks/sync_versions.py new file mode 100644 index 0000000..0b8dcce --- /dev/null +++ b/.hooks/sync_versions.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import subprocess +import pathlib +import re +import sys + +PACKAGE_FILE = pathlib.Path("socketsecurity/__init__.py") +VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]") + +def get_hatch_version(): + return subprocess.check_output(["hatch", "version"], text=True).strip() + +def get_current_version(): + content = PACKAGE_FILE.read_text() + match = VERSION_PATTERN.search(content) + return match.group(1) if match else None + +def update_version(new_version): + content = PACKAGE_FILE.read_text() + new_content = VERSION_PATTERN.sub(f"__version__ = '{new_version}'", content) + PACKAGE_FILE.write_text(new_content) + +def main(): + hatch_version = get_hatch_version() + current_version = get_current_version() + + if not current_version: + print("❌ Couldn't find __version__ in", PACKAGE_FILE) + return 1 + + if hatch_version != current_version: + print(f"🔁 Syncing version: {current_version} → {hatch_version}") + update_version(hatch_version) + return 1 # Exit 1 so pre-commit fails and shows diff + + print(f"✅ Version is in sync: {hatch_version}") + return 0 + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a6d9b0f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: + - repo: local + hooks: + - id: sync-version + name: Sync __version__ with hatch version + entry: python .hooks/sync_version.py + language: system + types: [python] + files: ^socketsecurity/__init__.py$ \ No newline at end of file From c0b1b6b7829bcedab991f0a910a228d83480bcbc Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:37:50 -0700 Subject: [PATCH 06/27] Fixing pr-release for hatch logic --- .github/workflows/pr-preview.yml | 7 +++++++ .hooks/{sync_versions.py => sync_version.py} | 16 ++++++++++------ docs/README.md | 10 ++++++++++ pyproject.toml | 3 +++ socketsecurity/__init__.py | 2 +- 5 files changed, 31 insertions(+), 7 deletions(-) rename .hooks/{sync_versions.py => sync_version.py} (61%) create mode 100644 docs/README.md diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index e5a7d39..6243e04 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -18,6 +18,10 @@ jobs: python -m pip install --upgrade pip pip install -e . pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 + + - name: Inject full dynamic version + run: python .hooks/sync_version.py --dev + - name: Get Hatch version id: version run: | @@ -41,6 +45,9 @@ jobs: if: steps.version_check.outputs.exists != 'true' run: | hatch build + - name: Reset __version__ to base version + if: always() + run: python .hooks/sync_version.py - name: Publish to Test PyPI if: steps.version_check.outputs.exists != 'true' diff --git a/.hooks/sync_versions.py b/.hooks/sync_version.py similarity index 61% rename from .hooks/sync_versions.py rename to .hooks/sync_version.py index 0b8dcce..0bdaf4c 100644 --- a/.hooks/sync_versions.py +++ b/.hooks/sync_version.py @@ -7,8 +7,11 @@ PACKAGE_FILE = pathlib.Path("socketsecurity/__init__.py") VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]") -def get_hatch_version(): - return subprocess.check_output(["hatch", "version"], text=True).strip() +def get_hatch_version(full=False): + raw = subprocess.check_output(["hatch", "version"], text=True).strip() + if full: + return raw + return raw.split(".dev")[0].split("+")[0] # Just base version def get_current_version(): content = PACKAGE_FILE.read_text() @@ -21,17 +24,18 @@ def update_version(new_version): PACKAGE_FILE.write_text(new_content) def main(): - hatch_version = get_hatch_version() + full_mode = "--dev" in sys.argv + hatch_version = get_hatch_version(full=full_mode) current_version = get_current_version() if not current_version: - print("❌ Couldn't find __version__ in", PACKAGE_FILE) + print(f"❌ Couldn't find __version__ in {PACKAGE_FILE}") return 1 if hatch_version != current_version: - print(f"🔁 Syncing version: {current_version} → {hatch_version}") + print(f"🔁 Updating version: {current_version} → {hatch_version}") update_version(hatch_version) - return 1 # Exit 1 so pre-commit fails and shows diff + return 1 if not full_mode else 0 # Fail locally to force re-add, but not in CI print(f"✅ Version is in sync: {hatch_version}") return 0 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..e6826fa --- /dev/null +++ b/docs/README.md @@ -0,0 +1,10 @@ +# 1. Clone the repo and create a virtualenv (Python 3.12+) +python3.12 -m venv .venv +source .venv/bin/activate + +# 2. Install dependencies +pip install --upgrade pip +pip install .[dev] + +# 3. Set up pre-commit hooks +pre-commit install diff --git a/pyproject.toml b/pyproject.toml index 0ea4709..0cf0840 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,9 @@ dev = [ "ruff>=0.3.0", "twine", # for building "pip-tools>=7.4.0", # for pip-compile + "pre-commit", + "hatch", + "hatch-vcs" ] [project.scripts] diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 0be278f..3955079 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.15' +__version__ = '2.0.17.dev2+g1097255.d20250401' From 56e3c6d0ce827c8adb44d2464b12b2156e99c676 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:42:29 -0700 Subject: [PATCH 07/27] Bumping version for deploy --- socketsecurity/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 3955079..6761821 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.17.dev2+g1097255.d20250401' +__version__ = '2.0.18' From 2e4d1f57d8ec6d53f8709f5cf0a2132d8861c654 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:49:30 -0700 Subject: [PATCH 08/27] Fixing build process --- .github/workflows/pr-preview.yml | 2 ++ .github/workflows/release.yml | 2 ++ socketsecurity/__init__.py | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 6243e04..e253964 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -8,6 +8,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-python@v5 with: python-version: '3.x' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad1bec3..9c89c2c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-python@v5 with: python-version: '3.x' diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 6761821..ba53727 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.18' +__version__ = '2.0.19' From d5c3f21d3439810926c9f243163ba65134fe0fa9 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 17:59:49 -0700 Subject: [PATCH 09/27] Change build process for PR build --- .github/workflows/pr-preview.yml | 3 --- .hooks/sync_version.py | 4 +++- socketsecurity/__init__.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index e253964..978cf40 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -47,9 +47,6 @@ jobs: if: steps.version_check.outputs.exists != 'true' run: | hatch build - - name: Reset __version__ to base version - if: always() - run: python .hooks/sync_version.py - name: Publish to Test PyPI if: steps.version_check.outputs.exists != 'true' diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index 0bdaf4c..7d934ea 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -35,7 +35,9 @@ def main(): if hatch_version != current_version: print(f"🔁 Updating version: {current_version} → {hatch_version}") update_version(hatch_version) - return 1 if not full_mode else 0 # Fail locally to force re-add, but not in CI + + # In --dev mode, we don't fail — we expect this to update it + return 0 if full_mode else 1 print(f"✅ Version is in sync: {hatch_version}") return 0 diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index ba53727..02e6345 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.19' +__version__ = '2.0.20' From 30e82234e88910356954c0ae86d95427393124d9 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 18:09:04 -0700 Subject: [PATCH 10/27] Added permissions for Trusted Publishing --- .github/workflows/pr-preview.yml | 5 ++++- .github/workflows/release.yml | 3 +++ socketsecurity/__init__.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 978cf40..fe30584 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -6,6 +6,9 @@ on: jobs: preview: runs-on: ubuntu-latest + permissions: + id-token: write + contents: read steps: - uses: actions/checkout@v4 with: @@ -37,7 +40,7 @@ jobs: run: | if curl -s -f https://test.pypi.org/pypi/socketsecurity/$VERSION/json > /dev/null; then echo "Version ${VERSION} already exists on Test PyPI" - echo "exists=true" >> $GITHUB_OUTPUT + echo "exists=true" >> $GITHUB_`OUTPUT else echo "Version ${VERSION} not found on Test PyPI" echo "exists=false" >> $GITHUB_OUTPUT diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9c89c2c..e3f18e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,9 @@ on: jobs: release: runs-on: ubuntu-latest + permissions: + id-token: write + contents: read steps: - uses: actions/checkout@v4 with: diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 02e6345..b25a250 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.20' +__version__ = '2.0.21' From 85a9cd2927ba39614a3bc186c40296c1763d903e Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 18:12:52 -0700 Subject: [PATCH 11/27] Fixed typo in preview logic --- .github/workflows/pr-preview.yml | 2 +- socketsecurity/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index fe30584..b35ea49 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -40,7 +40,7 @@ jobs: run: | if curl -s -f https://test.pypi.org/pypi/socketsecurity/$VERSION/json > /dev/null; then echo "Version ${VERSION} already exists on Test PyPI" - echo "exists=true" >> $GITHUB_`OUTPUT + echo "exists=true" >> $GITHUB_OUTPUT else echo "Version ${VERSION} not found on Test PyPI" echo "exists=false" >> $GITHUB_OUTPUT diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index b25a250..c27b80a 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.21' +__version__ = '2.0.22' From 68820537d99268a0f13b2cad876f28180f496ce1 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 18:24:26 -0700 Subject: [PATCH 12/27] Removing unneeded command breaking build --- .github/workflows/pr-preview.yml | 1 - .github/workflows/release.yml | 1 - socketsecurity/__init__.py | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index b35ea49..3175668 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -21,7 +21,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -e . pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 - name: Inject full dynamic version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3f18e6..0b436b3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -e . pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 - name: Get Version diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index c27b80a..8060589 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.22' +__version__ = '2.0.23' From a8ac6055c7e33bed9ce52958db9cee3618bc5790 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:05:44 -0700 Subject: [PATCH 13/27] Add debug for build process --- .github/workflows/pr-preview.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 3175668..7f668fa 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -45,11 +45,17 @@ jobs: echo "exists=false" >> $GITHUB_OUTPUT fi + - name: Clean dist + run: rm -rf dist + - name: Build package if: steps.version_check.outputs.exists != 'true' run: | hatch build + - name: Inspect built wheel + run: unzip -p dist/*.whl '*/METADATA' | grep -E '^Name:|^Version:' + - name: Publish to Test PyPI if: steps.version_check.outputs.exists != 'true' uses: pypa/gh-action-pypi-publish@v1.8.11 From 75437f87e950d4938c6a53a25115eaee32d5f35e Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:06:08 -0700 Subject: [PATCH 14/27] Bump version --- socketsecurity/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 8060589..08f796b 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.23' +__version__ = '2.0.24' From dafe8369e65c817f70138e07595036a63f11e71a Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:17:14 -0700 Subject: [PATCH 15/27] Added workaround for naming bug when pushing via OIDC --- .github/workflows/pr-preview.yml | 2 +- .hooks/sync_version.py | 14 ++++++-------- socketsecurity/__init__.py | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 7f668fa..b71eb3d 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -29,7 +29,7 @@ jobs: - name: Get Hatch version id: version run: | - VERSION=$(hatch version) + VERSION=$(hatch version | cut -d+ -f1) echo "VERSION=$VERSION" >> $GITHUB_ENV - name: Check if version exists on Test PyPI diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index 7d934ea..037aa07 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -7,11 +7,11 @@ PACKAGE_FILE = pathlib.Path("socketsecurity/__init__.py") VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]") -def get_hatch_version(full=False): - raw = subprocess.check_output(["hatch", "version"], text=True).strip() - if full: - return raw - return raw.split(".dev")[0].split("+")[0] # Just base version +def get_hatch_version(full=False, strip_local=False): + version = subprocess.check_output(["hatch", "version"], text=True).strip() + if not full or strip_local: + version = version.split("+")[0] # strip local metadata + return version def get_current_version(): content = PACKAGE_FILE.read_text() @@ -25,7 +25,7 @@ def update_version(new_version): def main(): full_mode = "--dev" in sys.argv - hatch_version = get_hatch_version(full=full_mode) + hatch_version = get_hatch_version(full=full_mode, strip_local=full_mode) current_version = get_current_version() if not current_version: @@ -35,8 +35,6 @@ def main(): if hatch_version != current_version: print(f"🔁 Updating version: {current_version} → {hatch_version}") update_version(hatch_version) - - # In --dev mode, we don't fail — we expect this to update it return 0 if full_mode else 1 print(f"✅ Version is in sync: {hatch_version}") diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 08f796b..49610ed 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.24' +__version__ = '2.0.25' From 00293c582b7e3a358192bf333ff7f381a4002e49 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:31:16 -0700 Subject: [PATCH 16/27] Moving to static version and pre commit hook to fix version publishing issue --- .github/workflows/pr-preview.yml | 2 +- .github/workflows/release.yml | 2 +- .hooks/sync_version.py | 79 +++++++++++++++++++++----------- pyproject.toml | 11 ++--- requirements-dev.lock | 1 - 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index b71eb3d..2e56eac 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 + pip install hatchling==1.27.0 hatch==1.14.0 - name: Inject full dynamic version run: python .hooks/sync_version.py --dev diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b436b3..a1d46bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0 + pip install hatchling==1.27.0 hatch==1.14.0 - name: Get Version id: version diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index 037aa07..718b6ab 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -4,41 +4,64 @@ import re import sys -PACKAGE_FILE = pathlib.Path("socketsecurity/__init__.py") +INIT_FILE = pathlib.Path("socketsecurity/__init__.py") +PYPROJECT_FILE = pathlib.Path("pyproject.toml") + VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]") +PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE) -def get_hatch_version(full=False, strip_local=False): - version = subprocess.check_output(["hatch", "version"], text=True).strip() - if not full or strip_local: - version = version.split("+")[0] # strip local metadata - return version +def get_git_tag(): + try: + tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match"], stderr=subprocess.DEVNULL, text=True).strip() + return tag.lstrip("v") # Remove 'v' prefix + except subprocess.CalledProcessError: + return None -def get_current_version(): - content = PACKAGE_FILE.read_text() - match = VERSION_PATTERN.search(content) - return match.group(1) if match else None +def get_latest_tag(): + try: + tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"], text=True).strip() + return tag.lstrip("v") + except subprocess.CalledProcessError: + return "0.0.0" -def update_version(new_version): - content = PACKAGE_FILE.read_text() - new_content = VERSION_PATTERN.sub(f"__version__ = '{new_version}'", content) - PACKAGE_FILE.write_text(new_content) +def get_commit_count_since(tag): + try: + output = subprocess.check_output(["git", "rev-list", f"{tag}..HEAD", "--count"], text=True).strip() + return int(output) + except subprocess.CalledProcessError: + return 0 -def main(): - full_mode = "--dev" in sys.argv - hatch_version = get_hatch_version(full=full_mode, strip_local=full_mode) - current_version = get_current_version() +def inject_version(version: str): + print(f"🔁 Injecting version: {version}") + + # Update __init__.py + init_content = INIT_FILE.read_text() + new_init_content = VERSION_PATTERN.sub(f"__version__ = '{version}'", init_content) + INIT_FILE.write_text(new_init_content) - if not current_version: - print(f"❌ Couldn't find __version__ in {PACKAGE_FILE}") - return 1 + # Update pyproject.toml + pyproject = PYPROJECT_FILE.read_text() + if PYPROJECT_PATTERN.search(pyproject): + new_pyproject = PYPROJECT_PATTERN.sub(f'version = "{version}"', pyproject) + else: + new_pyproject = re.sub(r"(\[project\])", rf"\1\nversion = \"{version}\"", pyproject) + PYPROJECT_FILE.write_text(new_pyproject) + +def main(): + mode = "--dev" if "--dev" in sys.argv else "release" - if hatch_version != current_version: - print(f"🔁 Updating version: {current_version} → {hatch_version}") - update_version(hatch_version) - return 0 if full_mode else 1 + if mode == "release": + version = get_git_tag() + if not version: + print("❌ Error: No exact tag found for release.") + sys.exit(1) + else: + base = get_latest_tag() + commits = get_commit_count_since(f"v{base}") + version = f"{base}.dev{commits}" - print(f"✅ Version is in sync: {hatch_version}") - return 0 + inject_version(version) + print(f"✅ Injected {mode} version: {version}") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/pyproject.toml b/pyproject.toml index 0cf0840..4f535f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,12 @@ [build-system] requires = [ - "hatchling", - "hatch-vcs" + "hatchling" ] build-backend = "hatchling.build" [project] name = "socketsecurity" -dynamic = ["version"] +version = "2.0.25" requires-python = ">= 3.10" dependencies = [ 'requests', @@ -47,8 +46,7 @@ dev = [ "twine", # for building "pip-tools>=7.4.0", # for pip-compile "pre-commit", - "hatch", - "hatch-vcs" + "hatch" ] [project.scripts] @@ -161,8 +159,5 @@ docstring-code-format = false # enabled. docstring-code-line-length = "dynamic" -[tool.hatch.version] -source = "vcs" # Uses the latest git tag like v2.0.15 - [tool.hatch.build.targets.wheel] include = ["socketsecurity", "LICENSE"] \ No newline at end of file diff --git a/requirements-dev.lock b/requirements-dev.lock index 7c2367b..099e79b 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -11,7 +11,6 @@ hatchling==1.27.0 hatch==1.14.0 -hatch-vcs==0.4.0 argparse==1.4.0 # via socketsecurity certifi==2024.12.14 From 048d421e5bc04feacc6e5775668cb228b8d202d8 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:36:27 -0700 Subject: [PATCH 17/27] Adding back in auto increment of version --- .hooks/sync_version.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index 718b6ab..5c87c42 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -12,27 +12,33 @@ def get_git_tag(): try: - tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match"], stderr=subprocess.DEVNULL, text=True).strip() - return tag.lstrip("v") # Remove 'v' prefix + tag = subprocess.check_output([ + "git", "describe", "--tags", "--exact-match" + ], stderr=subprocess.DEVNULL, text=True).strip() + return tag.lstrip("v") except subprocess.CalledProcessError: return None def get_latest_tag(): try: - tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"], text=True).strip() + tag = subprocess.check_output([ + "git", "describe", "--tags", "--abbrev=0" + ], text=True).strip() return tag.lstrip("v") except subprocess.CalledProcessError: return "0.0.0" def get_commit_count_since(tag): try: - output = subprocess.check_output(["git", "rev-list", f"{tag}..HEAD", "--count"], text=True).strip() + output = subprocess.check_output([ + "git", "rev-list", f"v{tag}..HEAD", "--count" + ], text=True).strip() return int(output) except subprocess.CalledProcessError: return 0 def inject_version(version: str): - print(f"🔁 Injecting version: {version}") + print(f"\U0001f501 Injecting version: {version}") # Update __init__.py init_content = INIT_FILE.read_text() @@ -48,20 +54,20 @@ def inject_version(version: str): PYPROJECT_FILE.write_text(new_pyproject) def main(): - mode = "--dev" if "--dev" in sys.argv else "release" + dev_mode = "--dev" in sys.argv - if mode == "release": + if dev_mode: + base = get_latest_tag() + commits = get_commit_count_since(base) + version = f"{base}.dev{commits}" + else: version = get_git_tag() if not version: - print("❌ Error: No exact tag found for release.") + print("\u274c Error: No exact tag found for release.") sys.exit(1) - else: - base = get_latest_tag() - commits = get_commit_count_since(f"v{base}") - version = f"{base}.dev{commits}" inject_version(version) - print(f"✅ Injected {mode} version: {version}") + print(f"\u2705 Injected {'dev' if dev_mode else 'release'} version: {version}") if __name__ == "__main__": - main() + main() \ No newline at end of file From c787e11f4c974a52691b3fa1b1e709e36ccb7c77 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:38:03 -0700 Subject: [PATCH 18/27] testing version bump --- socketsecurity/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 49610ed..43936be 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,3 @@ __author__ = 'socket.dev' __version__ = '2.0.25' + From 783001b74bd1adfb20c3d02adf7e495f6baa1327 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:43:29 -0700 Subject: [PATCH 19/27] Updating version logic --- .github/workflows/pr-preview.yml | 2 +- .hooks/sync_version.py | 69 +++++++++++++++----------------- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 2e56eac..b93b4ec 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -24,7 +24,7 @@ jobs: pip install hatchling==1.27.0 hatch==1.14.0 - name: Inject full dynamic version - run: python .hooks/sync_version.py --dev + run: python .hooks/sync_version.py - name: Get Hatch version id: version diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index 5c87c42..c5a462c 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -10,35 +10,33 @@ VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]") PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE) -def get_git_tag(): - try: - tag = subprocess.check_output([ - "git", "describe", "--tags", "--exact-match" - ], stderr=subprocess.DEVNULL, text=True).strip() - return tag.lstrip("v") - except subprocess.CalledProcessError: - return None +def read_version_from_init(path: pathlib.Path) -> str: + content = path.read_text() + match = VERSION_PATTERN.search(content) + if not match: + print(f"❌ Could not find __version__ in {path}") + sys.exit(1) + return match.group(1) -def get_latest_tag(): +def read_version_from_git(path: str) -> str: try: - tag = subprocess.check_output([ - "git", "describe", "--tags", "--abbrev=0" - ], text=True).strip() - return tag.lstrip("v") + output = subprocess.check_output(["git", "show", f"HEAD:{path}"], text=True) + match = VERSION_PATTERN.search(output) + if not match: + return None + return match.group(1) except subprocess.CalledProcessError: - return "0.0.0" + return None -def get_commit_count_since(tag): - try: - output = subprocess.check_output([ - "git", "rev-list", f"v{tag}..HEAD", "--count" - ], text=True).strip() - return int(output) - except subprocess.CalledProcessError: - return 0 +def bump_dev_version(version: str) -> str: + if ".dev" in version: + base, dev = version.split(".dev") + return f"{base}.dev{int(dev)+1}" + else: + return f"{version}.dev1" def inject_version(version: str): - print(f"\U0001f501 Injecting version: {version}") + print(f"🔁 Updating version to: {version}") # Update __init__.py init_content = INIT_FILE.read_text() @@ -54,20 +52,19 @@ def inject_version(version: str): PYPROJECT_FILE.write_text(new_pyproject) def main(): - dev_mode = "--dev" in sys.argv + current_version = read_version_from_init(INIT_FILE) + previous_version = read_version_from_git("socketsecurity/__init__.py") - if dev_mode: - base = get_latest_tag() - commits = get_commit_count_since(base) - version = f"{base}.dev{commits}" - else: - version = get_git_tag() - if not version: - print("\u274c Error: No exact tag found for release.") - sys.exit(1) + print(f"Current: {current_version}, Previous: {previous_version}") - inject_version(version) - print(f"\u2705 Injected {'dev' if dev_mode else 'release'} version: {version}") + if current_version == previous_version: + new_version = bump_dev_version(current_version) + inject_version(new_version) + print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.") + sys.exit(1) + else: + print("✅ Version already bumped — proceeding.") + sys.exit(0) if __name__ == "__main__": - main() \ No newline at end of file + main() From 50dd663b4aa37febdfd2058764760e89059e4852 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:50:56 -0700 Subject: [PATCH 20/27] Updated pre-commit hook --- .github/workflows/pr-preview.yml | 18 +-------------- .hooks/sync_version.py | 38 +++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index b93b4ec..06c9d91 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -24,7 +24,7 @@ jobs: pip install hatchling==1.27.0 hatch==1.14.0 - name: Inject full dynamic version - run: python .hooks/sync_version.py + run: python .hooks/sync_version.py --dev - name: Get Hatch version id: version @@ -32,22 +32,6 @@ jobs: VERSION=$(hatch version | cut -d+ -f1) echo "VERSION=$VERSION" >> $GITHUB_ENV - - name: Check if version exists on Test PyPI - id: version_check - env: - VERSION: ${{ env.VERSION }} - run: | - if curl -s -f https://test.pypi.org/pypi/socketsecurity/$VERSION/json > /dev/null; then - echo "Version ${VERSION} already exists on Test PyPI" - echo "exists=true" >> $GITHUB_OUTPUT - else - echo "Version ${VERSION} not found on Test PyPI" - echo "exists=false" >> $GITHUB_OUTPUT - fi - - - name: Clean dist - run: rm -rf dist - - name: Build package if: steps.version_check.outputs.exists != 'true' run: | diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index c5a462c..26ebc36 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -3,12 +3,15 @@ import pathlib import re import sys +import urllib.request +import json INIT_FILE = pathlib.Path("socketsecurity/__init__.py") PYPROJECT_FILE = pathlib.Path("pyproject.toml") VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]") PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE) +PYPI_API = "https://test.pypi.org/pypi/socketsecurity/json" def read_version_from_init(path: pathlib.Path) -> str: content = path.read_text() @@ -28,12 +31,30 @@ def read_version_from_git(path: str) -> str: except subprocess.CalledProcessError: return None -def bump_dev_version(version: str) -> str: +def bump_patch_version(version: str) -> str: if ".dev" in version: - base, dev = version.split(".dev") - return f"{base}.dev{int(dev)+1}" - else: - return f"{version}.dev1" + version = version.split(".dev")[0] + parts = version.split(".") + parts[-1] = str(int(parts[-1]) + 1) + return ".".join(parts) + +def fetch_existing_versions() -> set: + try: + with urllib.request.urlopen(PYPI_API) as response: + data = json.load(response) + return set(data.get("releases", {}).keys()) + except Exception as e: + print(f"⚠️ Warning: Failed to fetch existing versions from Test PyPI: {e}") + return set() + +def find_next_available_dev_version(base_version: str) -> str: + existing_versions = fetch_existing_versions() + for i in range(1, 100): + candidate = f"{base_version}.dev{i}" + if candidate not in existing_versions: + return candidate + print("❌ Could not find available .devN slot after 100 attempts.") + sys.exit(1) def inject_version(version: str): print(f"🔁 Updating version to: {version}") @@ -52,13 +73,18 @@ def inject_version(version: str): PYPROJECT_FILE.write_text(new_pyproject) def main(): + dev_mode = "--dev" in sys.argv current_version = read_version_from_init(INIT_FILE) previous_version = read_version_from_git("socketsecurity/__init__.py") print(f"Current: {current_version}, Previous: {previous_version}") if current_version == previous_version: - new_version = bump_dev_version(current_version) + if dev_mode: + base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version + new_version = find_next_available_dev_version(base_version) + else: + new_version = bump_patch_version(current_version) inject_version(new_version) print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.") sys.exit(1) From d841ded9e8ef441d9d385e5f90715255c1ea0030 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:53:33 -0700 Subject: [PATCH 21/27] version bumped --- .pre-commit-config.yaml | 6 +++--- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6d9b0f..d201e7f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,6 @@ repos: - id: sync-version name: Sync __version__ with hatch version entry: python .hooks/sync_version.py - language: system - types: [python] - files: ^socketsecurity/__init__.py$ \ No newline at end of file + language: python + always_run: true + pass_filenames: false \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 4f535f5..da0523c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.25" +version = "2.0.26" requires-python = ">= 3.10" dependencies = [ 'requests', diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 43936be..f0dc8e5 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.25' +__version__ = '2.0.26' From c05bf3c9fca45bcb2a53544c74faeb3d03d26121 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 19:57:58 -0700 Subject: [PATCH 22/27] Version bump --- .hooks/sync_version.py | 9 ++++++--- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.hooks/sync_version.py b/.hooks/sync_version.py index 26ebc36..f26dd76 100644 --- a/.hooks/sync_version.py +++ b/.hooks/sync_version.py @@ -83,11 +83,14 @@ def main(): if dev_mode: base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version new_version = find_next_available_dev_version(base_version) + inject_version(new_version) + print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.") + sys.exit(0) else: new_version = bump_patch_version(current_version) - inject_version(new_version) - print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.") - sys.exit(1) + inject_version(new_version) + print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.") + sys.exit(1) else: print("✅ Version already bumped — proceeding.") sys.exit(0) diff --git a/pyproject.toml b/pyproject.toml index da0523c..0ed974c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.26" +version = "2.0.27" requires-python = ">= 3.10" dependencies = [ 'requests', diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index f0dc8e5..526f120 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.26' +__version__ = '2.0.27' From 294742cad679212b99a2d67af4ee8fbcd365effe Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 20:11:35 -0700 Subject: [PATCH 23/27] Version bump --- .github/workflows/pr-preview.yml | 3 +++ pyproject.toml | 3 ++- socketsecurity/__init__.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 06c9d91..3de1fd5 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -26,6 +26,9 @@ jobs: - name: Inject full dynamic version run: python .hooks/sync_version.py --dev + - name: Clean previous builds + run: rm -rf dist/ build/ *.egg-info + - name: Get Hatch version id: version run: | diff --git a/pyproject.toml b/pyproject.toml index 0ed974c..4f888aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,8 +6,9 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.27" +version = "2.0.28" requires-python = ">= 3.10" +license = {"file" = "LICENSE"} dependencies = [ 'requests', 'mdutils', diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 526f120..630b1ee 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.27' +__version__ = '2.0.28' From 913d512b38354ca24cf7dc9d2428cc06654431b2 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 20:16:41 -0700 Subject: [PATCH 24/27] Version bump --- .github/workflows/pr-preview.yml | 2 ++ pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 3de1fd5..b8c6a44 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -39,6 +39,8 @@ jobs: if: steps.version_check.outputs.exists != 'true' run: | hatch build + # Don't publish whl to test.pypi until it supports metadata 2.4 + rm -rf dist/*.whl - name: Inspect built wheel run: unzip -p dist/*.whl '*/METADATA' | grep -E '^Name:|^Version:' diff --git a/pyproject.toml b/pyproject.toml index 4f888aa..3539f20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.28" +version = "2.0.29" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 630b1ee..a7b3b6b 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.28' +__version__ = '2.0.29' From 5b6b4c6105025bda94bc1f12be4c31df68108e65 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 20:19:02 -0700 Subject: [PATCH 25/27] Version bump --- .github/workflows/pr-preview.yml | 3 --- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index b8c6a44..7b0f1ea 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -42,9 +42,6 @@ jobs: # Don't publish whl to test.pypi until it supports metadata 2.4 rm -rf dist/*.whl - - name: Inspect built wheel - run: unzip -p dist/*.whl '*/METADATA' | grep -E '^Name:|^Version:' - - name: Publish to Test PyPI if: steps.version_check.outputs.exists != 'true' uses: pypa/gh-action-pypi-publish@v1.8.11 diff --git a/pyproject.toml b/pyproject.toml index 3539f20..e87d6be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.29" +version = "2.0.30" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index a7b3b6b..650d09c 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.29' +__version__ = '2.0.30' From e10dc135b6b45646e24cb19d6c1957ab8bf99a39 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 20:28:13 -0700 Subject: [PATCH 26/27] Version bump --- .github/workflows/pr-preview.yml | 4 +--- .github/workflows/release.yml | 2 +- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 7b0f1ea..dbc0a60 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -39,12 +39,10 @@ jobs: if: steps.version_check.outputs.exists != 'true' run: | hatch build - # Don't publish whl to test.pypi until it supports metadata 2.4 - rm -rf dist/*.whl - name: Publish to Test PyPI if: steps.version_check.outputs.exists != 'true' - uses: pypa/gh-action-pypi-publish@v1.8.11 + uses: pypa/gh-action-pypi-publish@v1.12.4 with: repository-url: https://test.pypi.org/legacy/ verbose: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1d46bc..0a5d0c6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -66,7 +66,7 @@ jobs: - name: Publish to PyPI if: steps.version_check.outputs.pypi_exists != 'true' - uses: pypa/gh-action-pypi-publish@v1.8.11 + uses: pypa/gh-action-pypi-publish@v1.12.4 - name: Login to Docker Hub uses: docker/login-action@v3 diff --git a/pyproject.toml b/pyproject.toml index e87d6be..ff05a70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.30" +version = "2.0.31" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 650d09c..9302768 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.30' +__version__ = '2.0.31' From 533b695aa0a84812bf6f3c5af7884596e6f15721 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 31 Mar 2025 20:31:33 -0700 Subject: [PATCH 27/27] Version bump --- .github/workflows/pr-preview.yml | 1 + pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index dbc0a60..8c706ac 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -9,6 +9,7 @@ jobs: permissions: id-token: write contents: read + pull-requests: write steps: - uses: actions/checkout@v4 with: diff --git a/pyproject.toml b/pyproject.toml index ff05a70..e720e60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.31" +version = "2.0.32" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 9302768..f77c81f 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.31' +__version__ = '2.0.32'