Skip to content

Commit 0112c5e

Browse files
committed
feat: add older versions of wrappers extension
... and an utility script `update_versions_json.py`, handy when it comes to compute hashes for every source tarball in a bulk
1 parent 4947f52 commit 0112c5e

File tree

3 files changed

+190
-1
lines changed

3 files changed

+190
-1
lines changed

nix/ext/update_versions_json.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell -i python3 -p python3 git nix-prefetch-git python3Packages.packaging
3+
4+
import subprocess
5+
import json
6+
import argparse
7+
from pathlib import Path
8+
from typing import Dict, List, Union
9+
from packaging.version import parse as parse_version, InvalidVersion
10+
11+
Schema = Dict[str, Dict[str, Dict[str, Union[List[str], str, bool]]]]
12+
13+
POSTGRES_VERSIONS: List[str] = ["15", "17"]
14+
VERSIONS_JSON_PATH = "versions.json"
15+
16+
17+
def run(cmd: List[str]) -> str:
18+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
19+
return result.stdout.strip()
20+
21+
22+
def get_tags(url: str) -> Dict[str, str]:
23+
output = run(["git", "ls-remote", "--tags", url])
24+
tags: Dict[str, str] = {}
25+
for line in output.splitlines():
26+
if "^{}" not in line:
27+
parts = line.split("\t")
28+
if len(parts) == 2:
29+
commit_hash, ref = parts
30+
if ref.startswith("refs/tags/"):
31+
tag = ref.removeprefix("refs/tags/")
32+
try:
33+
parse_version(tag)
34+
except InvalidVersion:
35+
continue
36+
tags[tag] = commit_hash
37+
return tags
38+
39+
40+
def get_sri_hash(url: str, commit_hash: str) -> str:
41+
output = run(["nix-prefetch-git", "--quiet", "--url", url, "--rev", commit_hash])
42+
nix_hash = json.loads(output)["sha256"]
43+
return "sha256-" + run(["nix", "hash", "to-base64", "--type", "sha256", nix_hash])
44+
45+
46+
def load() -> Schema:
47+
if not Path(VERSIONS_JSON_PATH).exists():
48+
return {}
49+
with open(VERSIONS_JSON_PATH, "r", encoding="utf-8") as f:
50+
return json.load(f)
51+
52+
53+
def build(name: str, url: str, data: Schema, ignore: bool = False) -> Schema:
54+
tags = get_tags(url)
55+
versions = data.get(name, {})
56+
for tag, commit_hash in tags.items():
57+
if tag in versions:
58+
continue
59+
if ignore:
60+
versions[tag] = {"ignore": True}
61+
else:
62+
sri_hash = get_sri_hash(url, commit_hash)
63+
versions[tag] = {"postgresql": POSTGRES_VERSIONS, "hash": sri_hash}
64+
data[name] = versions
65+
return data
66+
67+
68+
def save(data: Schema) -> None:
69+
sorted_data = {}
70+
for name, versions in data.items():
71+
sorted_data[name] = dict(
72+
sorted(versions.items(), key=lambda item: parse_version(item[0]))
73+
)
74+
with open(VERSIONS_JSON_PATH, "w", encoding="utf-8") as f:
75+
json.dump(sorted_data, f, indent=2)
76+
f.write("\n")
77+
78+
79+
def main() -> None:
80+
parser = argparse.ArgumentParser()
81+
parser.add_argument("extension_name")
82+
parser.add_argument("git_repo_url")
83+
parser.add_argument("--ignore", action="store_true")
84+
args = parser.parse_args()
85+
86+
save(build(args.extension_name, args.git_repo_url, load(), ignore=args.ignore))
87+
88+
89+
if __name__ == "__main__":
90+
main()

nix/ext/versions.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,101 @@
428428
}
429429
},
430430
"wrappers": {
431+
"0.3.0": {
432+
"postgresql": [
433+
"15"
434+
],
435+
"hash": "sha256-ogpF8NJ7kW3Ut8jaKMDiKYIXnI38nfRq2mMK4rqFAIA=",
436+
"pgrx": "0.11.3",
437+
"rust": "1.76.0"
438+
},
439+
"0.4.1": {
440+
"postgresql": [
441+
"15"
442+
],
443+
"hash": "sha256-AU9Y43qEMcIBVBThu+Aor1HCtfFIg+CdkzK9IxVdkzM=",
444+
"pgrx": "0.11.3",
445+
"rust": "1.76.0"
446+
},
447+
"0.4.2": {
448+
"postgresql": [
449+
"15"
450+
],
451+
"hash": "sha256-ut3IQED6ANXgabiHoEUdfSrwkuuYYSpRoeWdtBvSe64=",
452+
"pgrx": "0.11.3",
453+
"rust": "1.76.0"
454+
},
455+
"0.4.3": {
456+
"postgresql": [
457+
"15"
458+
],
459+
"hash": "sha256-CkoNMoh40zbQL4V49ZNYgv3JjoNWjODtTpHn+L8DdZA=",
460+
"pgrx": "0.12.6",
461+
"rust": "1.80.0"
462+
},
463+
"0.4.4": {
464+
"postgresql": [
465+
"15",
466+
"17"
467+
],
468+
"hash": "sha256-QoGFJpq8PuvMM8SS+VZd7MlNl56uFivRjs1tCtwX+oE=",
469+
"pgrx": "0.12.6",
470+
"rust": "1.80.0"
471+
},
472+
"0.4.5": {
473+
"postgresql": [
474+
"15",
475+
"17"
476+
],
477+
"hash": "sha256-IgDfVFROMCHYLZ/Iqj12MsQjPPCdRoH+3oi3Ki/iaRI=",
478+
"pgrx": "0.12.9",
479+
"rust": "1.81.0"
480+
},
481+
"0.4.6": {
482+
"postgresql": [
483+
"15",
484+
"17"
485+
],
486+
"hash": "sha256-hthb3qEXT1Kf4yPoq0udEbQzlyLtI5tug6sK4YAPFjU=",
487+
"pgrx": "0.12.9",
488+
"rust": "1.84.0"
489+
},
490+
"0.5.0": {
491+
"postgresql": [
492+
"15",
493+
"17"
494+
],
495+
"hash": "sha256-FbRTUcpEHBa5DI6dutvBeahYM0RZVAXIzIAZWIaxvn0=",
496+
"pgrx": "0.12.9",
497+
"rust": "1.84.0"
498+
},
499+
"0.5.1": {
500+
"postgresql": [
501+
"15",
502+
"17"
503+
],
504+
"hash": "sha256-3GfN3vZMFWf4FV/fSOe9ZN6KETmjoNw3Paz+JRzaH3c=",
505+
"pgrx": "0.12.9",
506+
"rust": "1.87.0"
507+
},
508+
"0.5.2": {
509+
"postgresql": [
510+
"15",
511+
"17"
512+
],
513+
"hash": "sha256-9VqQHduoAWnY8gtfRZLDOKiibfwuSTzyVFbH0uhsfCU=",
514+
"pgrx": "0.14.3",
515+
"rust": "1.87.0"
516+
},
517+
"0.5.3": {
518+
"postgresql": [
519+
"15",
520+
"17"
521+
],
522+
"hash": "",
523+
"pgrx": "0.14.3",
524+
"rust": "1.87.0"
525+
},
431526
"0.5.4": {
432527
"postgresql": [
433528
"15",

nix/ext/wrappers/default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ let
151151
};
152152
}
153153
// lib.optionalAttrs (version == "0.3.0") {
154+
# TODO: there is an inference error on crate `time` caused by an API change in Rust 1.80.0;
155+
# so we should patch `Cargo.toml` with `time >= 0.3.35`, to use a more recent Rust version!
154156
patches = [ ./0001-bump-pgrx-to-0.11.3.patch ];
155157

156158
cargoLock = {
@@ -197,7 +199,9 @@ let
197199
numberOfPreviouslyPackagedVersions = builtins.length previouslyPackagedVersions;
198200
allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).wrappers;
199201
supportedVersions = lib.filterAttrs (
200-
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
202+
_: value:
203+
(!value ? ignore || value.ignore != true)
204+
&& builtins.elem (lib.versions.major postgresql.version) value.postgresql
201205
) allVersions;
202206
versions = lib.naturalSort (lib.attrNames supportedVersions);
203207
latestVersion = lib.last versions;

0 commit comments

Comments
 (0)