Skip to content

Commit 39652f5

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 25f6fb6 commit 39652f5

File tree

3 files changed

+181
-1
lines changed

3 files changed

+181
-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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,91 @@
11
{
22
"wrappers": {
3+
"0.3.0": {
4+
"postgresql": [
5+
"15"
6+
],
7+
"hash": "sha256-ogpF8NJ7kW3Ut8jaKMDiKYIXnI38nfRq2mMK4rqFAIA=",
8+
"pgrx": "0.11.3",
9+
"rust": "1.76.0"
10+
},
11+
"0.4.1": {
12+
"postgresql": [
13+
"15"
14+
],
15+
"hash": "sha256-AU9Y43qEMcIBVBThu+Aor1HCtfFIg+CdkzK9IxVdkzM=",
16+
"pgrx": "0.11.3",
17+
"rust": "1.76.0"
18+
},
19+
"0.4.2": {
20+
"postgresql": [
21+
"15"
22+
],
23+
"hash": "sha256-ut3IQED6ANXgabiHoEUdfSrwkuuYYSpRoeWdtBvSe64=",
24+
"pgrx": "0.11.3",
25+
"rust": "1.76.0"
26+
},
27+
"0.4.3": {
28+
"postgresql": [
29+
"15"
30+
],
31+
"hash": "sha256-CkoNMoh40zbQL4V49ZNYgv3JjoNWjODtTpHn+L8DdZA=",
32+
"pgrx": "0.12.6",
33+
"rust": "1.80.0"
34+
},
35+
"0.4.4": {
36+
"postgresql": [
37+
"15",
38+
"17"
39+
],
40+
"hash": "sha256-QoGFJpq8PuvMM8SS+VZd7MlNl56uFivRjs1tCtwX+oE=",
41+
"pgrx": "0.12.6",
42+
"rust": "1.80.0"
43+
},
44+
"0.4.5": {
45+
"postgresql": [
46+
"15",
47+
"17"
48+
],
49+
"hash": "sha256-IgDfVFROMCHYLZ/Iqj12MsQjPPCdRoH+3oi3Ki/iaRI=",
50+
"pgrx": "0.12.9",
51+
"rust": "1.81.0"
52+
},
53+
"0.4.6": {
54+
"postgresql": [
55+
"15",
56+
"17"
57+
],
58+
"hash": "sha256-hthb3qEXT1Kf4yPoq0udEbQzlyLtI5tug6sK4YAPFjU=",
59+
"pgrx": "0.12.9",
60+
"rust": "1.84.0"
61+
},
62+
"0.5.0": {
63+
"postgresql": [
64+
"15",
65+
"17"
66+
],
67+
"hash": "sha256-FbRTUcpEHBa5DI6dutvBeahYM0RZVAXIzIAZWIaxvn0=",
68+
"pgrx": "0.12.9",
69+
"rust": "1.84.0"
70+
},
71+
"0.5.1": {
72+
"postgresql": [
73+
"15",
74+
"17"
75+
],
76+
"hash": "sha256-3GfN3vZMFWf4FV/fSOe9ZN6KETmjoNw3Paz+JRzaH3c=",
77+
"pgrx": "0.12.9",
78+
"rust": "1.87.0"
79+
},
80+
"0.5.2": {
81+
"postgresql": [
82+
"15",
83+
"17"
84+
],
85+
"hash": "sha256-9VqQHduoAWnY8gtfRZLDOKiibfwuSTzyVFbH0uhsfCU=",
86+
"pgrx": "0.14.3",
87+
"rust": "1.87.0"
88+
},
389
"0.5.3": {
490
"postgresql": [
591
"15",

nix/ext/wrappers/default.nix

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

151153
cargoLock = {
@@ -189,7 +191,9 @@ let
189191
numberOfPreviouslyPackagedVersions = builtins.length previouslyPackagedVersions;
190192
allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).wrappers;
191193
supportedVersions = lib.filterAttrs (
192-
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
194+
_: value:
195+
(!value ? ignore || value.ignore != true)
196+
&& builtins.elem (lib.versions.major postgresql.version) value.postgresql
193197
) allVersions;
194198
versions = lib.naturalSort (lib.attrNames supportedVersions);
195199
latestVersion = lib.last versions;

0 commit comments

Comments
 (0)