vscode-extensions.github.copilot{-,-chat}: 1.{266.1363 -> 275.0}, 0.24.202502{0602 -> 1302}#384899
vscode-extensions.github.copilot{-,-chat}: 1.{266.1363 -> 275.0}, 0.24.202502{0602 -> 1302}#384899drupol merged 2 commits intoNixOS:masterfrom
Conversation
|
Thanks, the parsing is great! We should do an update script based on it! I guess your script is using nushell? We should try to find something equivalent with jq. |
|
Hey, thanks for the quick merge! Also, thanks for leaving that comment (217d1f4)
I got you! We can do with nix run nixpkgs#vsce -- show github.copilot --json | jq 'first(
.versions[] |
select(
(.properties // []) | any(
.key == "Microsoft.VisualStudio.Code.Engine" and
.value == "^1.97.0"
)
)
) | .version'I don't really know
I like the idea and will look into creating one. I imagine the script would be Any help is welcome! |
|
I am glad my comment helped you... to be honest, this is also helping me every single time I have to update them since I always forgot about it! Sadly, I don't have much knowledge with |
|
|
I think something (tested now!) similar to this might do the job: #! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 vsce common-updater-scripts nodePackages.semver
import subprocess
import json
import sys
from typing import List, Dict, Any
def run_command(command: str) -> str:
"""Run a shell command and return the output as a string."""
try:
result = subprocess.run(
command, shell=True, check=True, capture_output=True, text=True
)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
print(f"Error running command: {command}\n{e.stderr}")
sys.exit(1)
def get_vscode_version() -> str:
"""Retrieve the VSCode version from Nix."""
return run_command("nix eval --raw -f . vscode.version")
def get_extension_data(extension_name: str) -> Dict[str, Any]:
"""Retrieve extension data from VSCode marketplace."""
try:
extension_data = run_command(f"vsce show {extension_name} --json")
return json.loads(extension_data)
except json.JSONDecodeError:
print(
f"Error: Extension '{extension_name}' not found in the VSCode marketplace."
)
sys.exit(1)
def find_first_compatible_version(
vscode_version: str, versions: List[Dict[str, Any]]
) -> str:
"""Find the first available compatible extension version."""
for version_data in versions:
candidate_version: str = version_data["version"]
engine_version: str | None = None
for prop in version_data.get("properties", []):
if prop["key"] == "Microsoft.VisualStudio.Code.Engine":
engine_version = prop["value"]
break
if engine_version:
print(
f"Testing extension version: {candidate_version} with VSCode {
vscode_version
} (constraint: {engine_version})"
)
semver_check_command = f"semver {vscode_version} -r '{engine_version}'"
semver_check = subprocess.run(
semver_check_command, shell=True, capture_output=True
)
if semver_check.returncode == 0:
print(
f"Compatible version found for VSCode {
vscode_version
} -> Extension version: {candidate_version}"
)
return candidate_version
print(
f"Extension version {candidate_version} is not compatible with VSCode {
vscode_version
} (constraint: {engine_version})"
)
return ""
def update_extension(extension_name: str, new_version: str) -> None:
"""Run nix-update for the selected extension version."""
run_command(
f"update-source-version vscode-extensions.{extension_name} {new_version}"
)
def main() -> None:
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <extension-name>")
sys.exit(1)
extension_name: str = sys.argv[1]
extension_data: Dict[str, Any] = get_extension_data(extension_name)
vscode_version: str = get_vscode_version()
print(f"VSCode version: {vscode_version}")
total_versions: int = len(extension_data.get("versions", []))
print(f"Extension: {extension_name}, total versions found: {total_versions}")
new_version: str = find_first_compatible_version(
vscode_version, extension_data.get("versions", [])
)
if not new_version:
print(f"No compatible version found for VSCode {vscode_version}")
sys.exit(1)
print(f"Selected extension version: {new_version}")
update_extension(extension_name, new_version)
if __name__ == "__main__":
main()Example output: Inspired from #385030 |
|
I just updated the script and it works well for any extension, with the correct VScode version constraint matching. |
Parsed latest version for 1.97.0 with:
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.