Skip to content

Commit 7ad5fc8

Browse files
committed
chore: add ci for updating wasm used in tests
Signed-off-by: davfsa <davfsa@gmail.com>
1 parent 9d0e521 commit 7ad5fc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+837
-745
lines changed

noxfile.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
from __future__ import annotations
22

3+
import hashlib
34
import os
45
import pathlib
56
import typing
67

78
import nox
9+
import yaml
810
from nox import options
911

1012
if typing.TYPE_CHECKING:
1113
import collections.abc
1214

13-
PATH_TO_PROJECT = pathlib.Path(__name__).parent
15+
PATH_TO_PROJECT = pathlib.Path(__name__).parent.absolute()
1416
SCRIPT_PATHS = ["noxfile.py", PATH_TO_PROJECT / "scripts", PATH_TO_PROJECT / "test"]
17+
TESTS_PATH = PATH_TO_PROJECT / "test"
1518

1619
DRIVER_PATHS = {
17-
"asyncpg": PATH_TO_PROJECT / "test" / "driver_asyncpg",
18-
"aiosqlite": PATH_TO_PROJECT / "test" / "driver_aiosqlite",
19-
"sqlite3": PATH_TO_PROJECT / "test" / "driver_sqlite3",
20+
"asyncpg": TESTS_PATH / "driver_asyncpg",
21+
"aiosqlite": TESTS_PATH / "driver_aiosqlite",
22+
"sqlite3": TESTS_PATH / "driver_sqlite3",
2023
}
2124

2225
SQLC_CONFIGS = ["sqlc.yaml"]
@@ -84,6 +87,49 @@ def sqlc_check(session: nox.Session, driver: str) -> None:
8487

8588

8689
@nox.session(reuse_venv=True)
90+
def update_test_plugin(session: nox.Session) -> None:
91+
# Build the plugin
92+
wasm_path = TESTS_PATH / "sqlc-gen-better-python.wasm"
93+
94+
with session.chdir("plugin"):
95+
session.run(
96+
"go",
97+
"build",
98+
"-o",
99+
str(wasm_path),
100+
env={"GOOS": "wasip1", "GOARCH": "wasm"},
101+
external=True,
102+
)
103+
104+
# Calculate the SHA256 hash
105+
sha256_hasher = hashlib.sha256()
106+
with wasm_path.open("rb") as fp:
107+
while True:
108+
data = fp.read(65536) # 64kb chunks
109+
if not data:
110+
break
111+
112+
sha256_hasher.update(data)
113+
114+
plugin_hash = sha256_hasher.hexdigest()
115+
116+
# Update the SHA256 in the config files
117+
for driver_name, driver_path in DRIVER_PATHS.items():
118+
for config_filename in SQLC_CONFIGS:
119+
config_path = driver_path / config_filename
120+
121+
with config_path.open() as fp:
122+
config = yaml.safe_load(fp)
123+
124+
config["plugins"][0]["wasm"]["sha256"] = plugin_hash
125+
126+
with config_path.open("w") as fp:
127+
yaml.safe_dump(config, fp)
128+
129+
sqlc_generate(session, driver_name)
130+
131+
132+
@nox.session(reuse_venv=True, requires=["update_test_plugin"])
87133
def sqlite3(session: nox.Session) -> None:
88134
uv_sync(session, include_self=True, groups=["pyright", "ruff"])
89135

@@ -92,7 +138,7 @@ def sqlite3(session: nox.Session) -> None:
92138
session.run("ruff", "check", *session.posargs, DRIVER_PATHS["sqlite3"])
93139

94140

95-
@nox.session(reuse_venv=True)
141+
@nox.session(reuse_venv=True, requires=["update_test_plugin"])
96142
def sqlite3_check(session: nox.Session) -> None:
97143
uv_sync(session, include_self=True, groups=["pyright", "ruff"])
98144

@@ -101,7 +147,7 @@ def sqlite3_check(session: nox.Session) -> None:
101147
session.run("ruff", "check", *session.posargs, DRIVER_PATHS["sqlite3"])
102148

103149

104-
@nox.session(reuse_venv=True)
150+
@nox.session(reuse_venv=True, requires=["update_test_plugin"])
105151
def aiosqlite(session: nox.Session) -> None:
106152
uv_sync(session, include_self=True, groups=["pyright", "ruff"])
107153

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
[dependency-groups]
1515
dev = [
1616
"nox>=2025.5.1",
17+
"pyyaml>=6.0.2",
1718
]
1819
dev-complete = [
1920
"nox>=2025.5.1",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Package containing queries and models automatically generated using sqlc-gen-better-python."""

test/driver_aiosqlite/attrs/classes/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Module containing models."""
66
from __future__ import annotations
77

test/driver_aiosqlite/attrs/classes/queries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Module containing queries from file queries.sql."""
66
from __future__ import annotations
77

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Package containing queries and models automatically generated using sqlc-gen-better-python."""

test/driver_aiosqlite/attrs/functions/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Module containing models."""
66
from __future__ import annotations
77

test/driver_aiosqlite/attrs/functions/queries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Module containing queries from file queries.sql."""
66
from __future__ import annotations
77

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Package containing queries and models automatically generated using sqlc-gen-better-python."""

test/driver_aiosqlite/dataclass/classes/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code generated by sqlc. DO NOT EDIT.
22
# versions:
3-
# sqlc v1.28.0
4-
# sqlc-gen-better-python v0.4.3
3+
# sqlc v1.29.0
4+
# sqlc-gen-better-python v0.4.4
55
"""Module containing models."""
66
from __future__ import annotations
77

0 commit comments

Comments
 (0)