-
-
Notifications
You must be signed in to change notification settings - Fork 233
feat: add older versions of the wrappers extension
#1748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
b109fd3
567da95
5137024
7763329
a1d7f70
86f9c80
945c081
d53d277
8fee2de
5f6b5d1
2efb39c
553be57
a9095c3
5c4996a
447f69b
1811269
afb82f9
944d04f
07e57d2
1e51078
11b4654
5b91640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||||
| #!/usr/bin/env nix-shell | ||||||||||
| #! nix-shell -i python3 -p python3 git nix-prefetch-git python3Packages.packaging | ||||||||||
|
|
||||||||||
yvan-sraka marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| 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" | ||||||||||
|
Comment on lines
+13
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix versions.json path resolution (currently relative to CWD). 🔧 Proposed fix-VERSIONS_JSON_PATH = "versions.json"
+VERSIONS_JSON_PATH = Path(__file__).resolve().parents[1] / "versions.json"
@@
- if not Path(VERSIONS_JSON_PATH).exists():
+ if not VERSIONS_JSON_PATH.exists():
return {}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
|
|
||||||||||
| 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] = {} | ||||||||||
| peeled_tags: Dict[str, str] = {} | ||||||||||
|
|
||||||||||
| # First pass: collect both normal and peeled entries | ||||||||||
| for line in output.splitlines(): | ||||||||||
| parts = line.split("\t") | ||||||||||
| if len(parts) == 2: | ||||||||||
| commit_hash, ref = parts | ||||||||||
| if ref.startswith("refs/tags/"): | ||||||||||
| if ref.endswith("^{}"): | ||||||||||
| # This is a peeled tag (commit hash for annotated tag) | ||||||||||
| tag = ref.removeprefix("refs/tags/").removesuffix("^{}") | ||||||||||
| peeled_tags[tag] = commit_hash | ||||||||||
| else: | ||||||||||
| # Regular tag entry | ||||||||||
| tag = ref.removeprefix("refs/tags/") | ||||||||||
| try: | ||||||||||
| parse_version(tag) | ||||||||||
| except InvalidVersion: | ||||||||||
| continue | ||||||||||
| tags[tag] = commit_hash | ||||||||||
|
|
||||||||||
| # Second pass: prefer peeled commit hashes when available | ||||||||||
| for tag, _ in tags.items(): | ||||||||||
| if tag in peeled_tags: | ||||||||||
| tags[tag] = peeled_tags[tag] | ||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| return tags | ||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| 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() | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.