Skip to content
Draft
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
90 changes: 90 additions & 0 deletions nix/ext/update_versions_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 git nix-prefetch-git python3Packages.packaging

import subprocess
import json
import argparse
from pathlib import Path
from typing import Dict, List, Union
from packaging.version import parse as parse_version, InvalidVersion

Schema = Dict[str, Dict[str, Dict[str, Union[List[str], str, bool]]]]

POSTGRES_VERSIONS: List[str] = ["15", "17"]
VERSIONS_JSON_PATH = "versions.json"


def run(cmd: List[str]) -> str:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
return result.stdout.strip()


def get_tags(url: str) -> Dict[str, str]:
output = run(["git", "ls-remote", "--tags", url])
tags: Dict[str, str] = {}
for line in output.splitlines():
if "^{}" not in line:
parts = line.split("\t")
if len(parts) == 2:
commit_hash, ref = parts
if ref.startswith("refs/tags/"):
tag = ref.removeprefix("refs/tags/")
try:
parse_version(tag)
except InvalidVersion:
continue
tags[tag] = commit_hash
return tags


def get_sri_hash(url: str, commit_hash: str) -> str:
output = run(["nix-prefetch-git", "--quiet", "--url", url, "--rev", commit_hash])
nix_hash = json.loads(output)["sha256"]
return "sha256-" + run(["nix", "hash", "to-base64", "--type", "sha256", nix_hash])


def load() -> Schema:
if not Path(VERSIONS_JSON_PATH).exists():
return {}
with open(VERSIONS_JSON_PATH, "r", encoding="utf-8") as f:
return json.load(f)


def build(name: str, url: str, data: Schema, ignore: bool = False) -> Schema:
tags = get_tags(url)
versions = data.get(name, {})
for tag, commit_hash in tags.items():
if tag in versions:
continue
if ignore:
versions[tag] = {"ignore": True}
else:
sri_hash = get_sri_hash(url, commit_hash)
versions[tag] = {"postgresql": POSTGRES_VERSIONS, "hash": sri_hash}
data[name] = versions
return data


def save(data: Schema) -> None:
sorted_data = {}
for name, versions in data.items():
sorted_data[name] = dict(
sorted(versions.items(), key=lambda item: parse_version(item[0]))
)
with open(VERSIONS_JSON_PATH, "w", encoding="utf-8") as f:
json.dump(sorted_data, f, indent=2)
f.write("\n")


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("extension_name")
parser.add_argument("git_repo_url")
parser.add_argument("--ignore", action="store_true")
args = parser.parse_args()

save(build(args.extension_name, args.git_repo_url, load(), ignore=args.ignore))


if __name__ == "__main__":
main()
88 changes: 87 additions & 1 deletion nix/ext/versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,92 @@
{
"wrappers": {
"0.5.4": {
"0.3.0": {
"postgresql": [
"15"
],
"hash": "sha256-ogpF8NJ7kW3Ut8jaKMDiKYIXnI38nfRq2mMK4rqFAIA=",
"pgrx": "0.11.3",
"rust": "1.76.0"
},
"0.4.1": {
"postgresql": [
"15"
],
"hash": "sha256-AU9Y43qEMcIBVBThu+Aor1HCtfFIg+CdkzK9IxVdkzM=",
"pgrx": "0.11.3",
"rust": "1.76.0"
},
"0.4.2": {
"postgresql": [
"15"
],
"hash": "sha256-ut3IQED6ANXgabiHoEUdfSrwkuuYYSpRoeWdtBvSe64=",
"pgrx": "0.11.3",
"rust": "1.76.0"
},
"0.4.3": {
"postgresql": [
"15"
],
"hash": "sha256-CkoNMoh40zbQL4V49ZNYgv3JjoNWjODtTpHn+L8DdZA=",
"pgrx": "0.12.6",
"rust": "1.80.0"
},
"0.4.4": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-QoGFJpq8PuvMM8SS+VZd7MlNl56uFivRjs1tCtwX+oE=",
"pgrx": "0.12.6",
"rust": "1.80.0"
},
"0.4.5": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-IgDfVFROMCHYLZ/Iqj12MsQjPPCdRoH+3oi3Ki/iaRI=",
"pgrx": "0.12.9",
"rust": "1.81.0"
},
"0.4.6": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-hthb3qEXT1Kf4yPoq0udEbQzlyLtI5tug6sK4YAPFjU=",
"pgrx": "0.12.9",
"rust": "1.84.0"
},
"0.5.0": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-FbRTUcpEHBa5DI6dutvBeahYM0RZVAXIzIAZWIaxvn0=",
"pgrx": "0.12.9",
"rust": "1.84.0"
},
"0.5.1": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-3GfN3vZMFWf4FV/fSOe9ZN6KETmjoNw3Paz+JRzaH3c=",
"pgrx": "0.12.9",
"rust": "1.87.0"
},
"0.5.2": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-9VqQHduoAWnY8gtfRZLDOKiibfwuSTzyVFbH0uhsfCU=",
"pgrx": "0.14.3",
"rust": "1.87.0"
},
"0.5.3": {
"postgresql": [
"15",
"17",
Expand Down
Loading
Loading