<commit_before>#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq nix-prefetch-github nodePackages.node2nix
set -euo pipefail
cd "$(dirname "$0")"
owner=rust-analyzer
repo=rust-analyzer
nixpkgs=../../../../..

# Update lsp

rev=$(
    curl -s "https://api.github.com/repos/$owner/$repo/releases" |
    jq 'map(select(.prerelease | not)) | .[0].tag_name' --raw-output
)
old_rev=$(sed -nE 's/.*\brev = "(.*)".*/\1/p' ./default.nix)
if grep -q '0000000000000000000000000000000000000000000000000000' ./default.nix; then
    old_rev='broken'
fi
if [[ "$rev" == "$old_rev" ]]; then
    echo "Up to date: $rev"
    exit
fi
echo "$old_rev -> $rev"

sha256=$(nix-prefetch-github --prefetch "$owner" "$repo" --rev "$rev" | jq '.sha256' --raw-output)
sed -e "s/rev = \".*\"/rev = \"$rev\"/" \
    -e "s/sha256 = \".*\"/sha256 = \"$sha256\"/" \
    -e "s/cargoSha256 = \".*\"/cargoSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \
    --in-place ./default.nix

echo "Prebuilding nix"
cargo_sha256=$({
    ! nix-build "$nixpkgs" -A rust-analyzer-unwrapped --no-out-link 2>&1
} | tee /dev/stderr | sed -nE 's/\s*got:\s*sha256:(\w+)/\1/p' | head -n1)
echo "cargoSha256: $cargo_sha256"
[[ "$cargo_sha256" ]]
sed "s/cargoSha256 = \".*\"/cargoSha256 = \"$cargo_sha256\"/" \
    --in-place ./default.nix

# Update vscode extension

echo "Generating node lock"
node_src="$(nix-build "$nixpkgs" -A rust-analyzer.src --no-out-link)/editors/code"
pushd "$nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer"
ext_version=$(jq '.version' "$node_src/package.json" --raw-output)
ext_publisher=$(jq '.publisher' "$node_src/package.json" --raw-output)
echo "Extension version: $ext_version"
[[ "$ext_publisher" == "matklad" ]]
node2nix \
    --nodejs-12 \
    --development \
    --input "$node_src/package.json" \
    --lock "$node_src/package-lock.json" \
    --output ./node-packages.nix \
    --composition ./node-composition.nix \
    --no-copy-node-env \
    --node-env ../../../development/node-packages/node-env.nix
sed -e 's_^.*src = [./]*/nix/store.*__g' \
    --in-place ./node-packages.nix
sed -e "s/version = \".*\"/version = \"$ext_version\"/" \<commit_msg>rust-analyzer: check compatibility in update script<commit_after>#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq nix-prefetch-github nodePackages.node2nix
set -euo pipefail
cd "$(dirname "$0")"
owner=rust-analyzer
repo=rust-analyzer
nixpkgs=../../../../..

# Update lsp

rev=$(
    curl -s "https://api.github.com/repos/$owner/$repo/releases" |
    jq 'map(select(.prerelease | not)) | .[0].tag_name' --raw-output
)
old_rev=$(sed -nE 's/.*\brev = "(.*)".*/\1/p' ./default.nix)
if grep -q '0000000000000000000000000000000000000000000000000000' ./default.nix; then
    old_rev='broken'
fi
if [[ "$rev" == "$old_rev" ]]; then
    echo "Up to date: $rev"
    exit
fi
echo "$old_rev -> $rev"

sha256=$(nix-prefetch-github --prefetch "$owner" "$repo" --rev "$rev" | jq '.sha256' --raw-output)
sed -e "s/rev = \".*\"/rev = \"$rev\"/" \
    -e "s/sha256 = \".*\"/sha256 = \"$sha256\"/" \
    -e "s/cargoSha256 = \".*\"/cargoSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \
    --in-place ./default.nix
node_src="$(nix-build "$nixpkgs" -A rust-analyzer.src --no-out-link)/editors/code"

# Check vscode compatibility
req_vscode_ver="$(jq '.engines.vscode' "$node_src/package.json" --raw-output)"
req_vscode_ver="${req_vscode_ver#^}"
cur_vscode_ver="$(nix eval --raw -f "$nixpkgs" vscode.version)"
if [[ "$(nix eval "(builtins.compareVersions \"$req_vscode_ver\" \"$cur_vscode_ver\")")" != "-1" ]]; then
    echo "vscode $cur_vscode_ver is incompatible with the extension requiring ^$req_vscode_ver"
    exit 1
fi

echo "Prebuilding nix"
cargo_sha256=$({
    ! nix-build "$nixpkgs" -A rust-analyzer-unwrapped --no-out-link 2>&1
} | tee /dev/stderr | sed -nE 's/\s*got:\s*sha256:(\w+)/\1/p' | head -n1)
echo "cargoSha256: $cargo_sha256"
[[ "$cargo_sha256" ]]
sed "s/cargoSha256 = \".*\"/cargoSha256 = \"$cargo_sha256\"/" \
    --in-place ./default.nix

# Update vscode extension

echo "Generating node lock"
pushd "$nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer"
ext_version=$(jq '.version' "$node_src/package.json" --raw-output)
ext_publisher=$(jq '.publisher' "$node_src/package.json" --raw-output)
echo "Extension version: $ext_version"
[[ "$ext_publisher" == "matklad" ]]
node2nix \
    --nodejs-12 \
    --development \
    --input "$node_src/package.json" \
    --lock "$node_src/package-lock.json" \
    --output ./node-packages.nix \
    --composition ./node-composition.nix \
    --no-copy-node-env \
    --node-env ../../../development/node-packages/node-env.nix
sed -e 's_^.*src = [./]*/nix/store.*__g' \
    --in-place ./node-packages.nix
sed -e "s/version = \".*\"/version = \"$ext_version\"/" \
{'fraction_non_alphanumeric': 0.22215269086357947, 'fraction_numerical': 0.06716729244889445, 'mean_word_length': 3.1841186736474696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3102392', 'n_tokens_mistral': 2190, 'n_tokens_neox': 1837, 'n_words': 362}