diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 9b76668..b4d28d6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -9,6 +9,7 @@ on: jobs: build-and-publish: + runs-on: ubuntu-latest steps: diff --git a/appwrite_lab/test_suite/fixtures.py b/appwrite_lab/test_suite/fixtures.py index 5f64862..5627d64 100644 --- a/appwrite_lab/test_suite/fixtures.py +++ b/appwrite_lab/test_suite/fixtures.py @@ -1,9 +1,11 @@ from pathlib import Path -import pytest from appwrite_lab.labs import Labs from appwrite_lab.models import Lab +import hashlib +import pytest + @pytest.fixture(scope="session") def lab_svc(): @@ -42,19 +44,37 @@ def lab_config(): def lab(lab_svc: Labs, appwrite_file: Path, lab_config: dict) -> Lab: """Create or get existing lab with optional appwrite.json sync.""" lab_name = lab_config["name"] + hash_file_path = Path.home() / ".config" / "appwrite-lab" / "json_hashes" + hash_file_path.touch() if lab := lab_svc.get_lab(lab_name): + # Check if the file has changed before unnecessary sync if appwrite_file and appwrite_file.exists(): - lab_svc.sync_with_appwrite_config( - name=lab_name, appwrite_json=appwrite_file - ) + hash = hash_file(appwrite_file) + data = hash_file_path.read_text() + if len(data) > 0 and data.strip() == hash: + print("Skipping sync because the file has not changed") + else: + lab_svc.sync_with_appwrite_config( + name=lab_name, appwrite_json=appwrite_file + ) + hash_file_path.write_text(hash) return lab res = lab_svc.new(**lab_config) if appwrite_file and appwrite_file.exists(): + hash_file_path.write_text(hash_file(appwrite_file)) lab_svc.sync_with_appwrite_config(name=lab_name, appwrite_json=appwrite_file) if not res.error: return lab_svc.get_lab(lab_name) raise ValueError(res.message) + + +def hash_file(path, algo="sha256"): + h = hashlib.new(algo) + with open(path, "rb") as f: + for chunk in iter(lambda: f.read(8192), b""): + h.update(chunk) + return h.hexdigest() diff --git a/pyproject.toml b/pyproject.toml index e8c999a..3f0e143 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "appwrite-lab" -version = "0.1.1" +version = "0.1.2" description = "Zero-click Appwrite test environments." readme = "README.md" requires-python = ">=3.11"