Skip to content

Comments

vscode-extensions.github.copilot{-,-chat}: 1.{266.1363 -> 275.0}, 0.24.202502{0602 -> 1302}#384899

Merged
drupol merged 2 commits intoNixOS:masterfrom
FlameFlag:update-copilot
Feb 25, 2025
Merged

vscode-extensions.github.copilot{-,-chat}: 1.{266.1363 -> 275.0}, 0.24.202502{0602 -> 1302}#384899
drupol merged 2 commits intoNixOS:masterfrom
FlameFlag:update-copilot

Conversation

@FlameFlag
Copy link
Member

@FlameFlag FlameFlag commented Feb 24, 2025

Parsed latest version for 1.97.0 with:

# copilot
nix run nixpkgs#vsce -- show github.copilot --json 
| from json 
| get versions 
| where {|v| ($v.properties | where key == "Microsoft.VisualStudio.Code.Engine" | where value == "^1.97.0" | length) > 0 } 
| first 
| get version

# copilot-chat
nix run nixpkgs#vsce -- show github.copilot-chat --json 
| from json 
| get versions 
| where {|v| ($v.properties | where key == "Microsoft.VisualStudio.Code.Engine" | where value == "^1.97.0" | length) > 0 } 
| first 
| get version

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: vscode A free and versatile code editor that supports almost every major programming language. label Feb 24, 2025
@FlameFlag FlameFlag requested a review from drupol February 24, 2025 23:23
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Feb 24, 2025
@nix-owners nix-owners bot requested review from Laurent2916 and Zimmi48 February 24, 2025 23:30
@drupol
Copy link
Contributor

drupol commented Feb 25, 2025

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.

@drupol drupol merged commit 0d6b5b0 into NixOS:master Feb 25, 2025
34 of 35 checks passed
@FlameFlag FlameFlag deleted the update-copilot branch February 25, 2025 10:10
@FlameFlag
Copy link
Member Author

Hey, thanks for the quick merge! Also, thanks for leaving that comment (217d1f4)
about nix run nixpkgs#vsce --show github.copilot --json because I had no
idea how to update VSCode extensions and was wondering how people do it, and
that comment helped me out a lot!

We should try to find something equivalent with jq

I got you! We can do with jq by doing it like this:

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 jq that well and don't use it often, so let me know if
there's a better way to parse this!

We should do an update script based on it!

I like the idea and will look into creating one. I imagine the script would be
a Bash script, where the first argument is the extension name and the second is
the VSCode version. I timed both Nushell and Bash, and they took the same time
to retrieve the version, so it should be in Bash IMO

Any help is welcome!

@drupol
Copy link
Contributor

drupol commented Feb 25, 2025

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 nix-update-script or similar tool, so I won't be able to help.

@FlameFlag
Copy link
Member Author

Sadly, I don't have much knowledge with nix-update-script or similar tool, so I won't be able to help.

nix-update-script is just a wrapper for nix-update I don't think it's
possible to use nix-update to update extensions, so most likely the script
will need custom logic

@drupol
Copy link
Contributor

drupol commented Feb 25, 2025

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:

❯ ./pkgs.py github.copilot-chat
VSCode version: 1.97.2
Extension: github.copilot-chat, total versions found: 577
Testing extension version: 0.25.2025030502 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025030502 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025030404 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025030404 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025030403 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025030403 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025030402 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025030402 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025030302 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025030302 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022803 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022803 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022802 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022802 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022801 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022801 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022701 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022701 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022601 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022601 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022501 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022501 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022401 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022401 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022101 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022101 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025022001 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025022001 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025021901 with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Extension version 0.25.2025021901 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240218)
Testing extension version: 0.25.2025021801 with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Extension version 0.25.2025021801 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Testing extension version: 0.25.2025021701 with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Extension version 0.25.2025021701 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Testing extension version: 0.25.2025021401 with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Extension version 0.25.2025021401 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Testing extension version: 0.25.2025021301 with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Extension version 0.25.2025021301 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0-20240213)
Testing extension version: 0.25.2025021201 with VSCode 1.97.2 (constraint: ^1.98.0)
Extension version 0.25.2025021201 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0)
Testing extension version: 0.25.2025021101 with VSCode 1.97.2 (constraint: ^1.98.0)
Extension version 0.25.2025021101 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0)
Testing extension version: 0.25.2025021001 with VSCode 1.97.2 (constraint: ^1.98.0)
Extension version 0.25.2025021001 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0)
Testing extension version: 0.25.2025020703 with VSCode 1.97.2 (constraint: ^1.98.0)
Extension version 0.25.2025020703 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0)
Testing extension version: 0.25.2025020702 with VSCode 1.97.2 (constraint: ^1.98.0)
Extension version 0.25.2025020702 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0)
Testing extension version: 0.25.2025020603 with VSCode 1.97.2 (constraint: ^1.98.0)
Extension version 0.25.2025020603 is not compatible with VSCode 1.97.2 (constraint: ^1.98.0)
Testing extension version: 0.24.2025021302 with VSCode 1.97.2 (constraint: ^1.97.0)
Compatible version found for VSCode 1.97.2 -> Extension version: 0.24.2025021302
Selected extension version: 0.24.2025021302

Inspired from #385030

@drupol
Copy link
Contributor

drupol commented Feb 26, 2025

I just updated the script and it works well for any extension, with the correct VScode version constraint matching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: vscode A free and versatile code editor that supports almost every major programming language. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants