Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

jobs:
build-and-publish:

runs-on: ubuntu-latest

steps:
Expand Down
28 changes: 24 additions & 4 deletions appwrite_lab/test_suite/fixtures.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading