|
1 | 1 | #! /usr/bin/env nix-shell |
2 | | -#! nix-shell update-shell.nix -i bash |
3 | | - |
4 | | -# Update script for the vscode versions and hashes. |
5 | | -# Usually doesn't need to be called by hand, |
6 | | -# but is called by a bot: https://github.com/samuela/nixpkgs-upkeep/actions |
7 | | -# Call it by hand if the bot fails to automatically update the versions. |
| 2 | +#!nix-shell -i bash -p bash curl gawk gnugrep gnused jq nix nix-prefetch nix-prefetch-scripts common-updater-scripts |
8 | 3 |
|
9 | 4 | set -eou pipefail |
10 | 5 |
|
11 | | -ROOT="$(dirname "$(readlink -f "$0")")" |
12 | | -if [ ! -f "$ROOT/vscode.nix" ]; then |
13 | | - echo "ERROR: cannot find vscode.nix in $ROOT" |
14 | | - exit 1 |
15 | | -fi |
16 | | - |
17 | | -# VSCode |
18 | | - |
19 | | -VSCODE_VER=$(curl --fail --silent https://api.github.com/repos/Microsoft/vscode/releases/latest | jq --raw-output .tag_name) |
20 | | -sed -i "s/version = \".*\"/version = \"${VSCODE_VER}\"/" "$ROOT/vscode.nix" |
21 | | - |
22 | | -TEMP_FOLDER=$(mktemp -d) |
| 6 | +latestVersion=$(curl --fail --silent https://api.github.com/repos/Microsoft/vscode/releases/latest | jq --raw-output .tag_name) |
| 7 | +currentVersion=$(nix eval --raw -f . vscode.version) |
23 | 8 |
|
24 | | -VSCODE_X64_LINUX_URL="https://update.code.visualstudio.com/${VSCODE_VER}/linux-x64/stable" |
| 9 | +echo "latest version: $latestVersion" |
| 10 | +echo "current version: $currentVersion" |
25 | 11 |
|
26 | | -# Split output by newlines into Bash array |
27 | | -readarray -t VSCODE_X64_LINUX <<< $(nix-prefetch-url --print-path ${VSCODE_X64_LINUX_URL}) |
28 | | - |
29 | | -sed -i "s/x86_64-linux = \".\{52\}\"/x86_64-linux = \"${VSCODE_X64_LINUX[0]}\"/" "$ROOT/vscode.nix" |
30 | | - |
31 | | -tar xf ${VSCODE_X64_LINUX[1]} -C $TEMP_FOLDER |
32 | | -VSCODE_COMMIT=$(jq --raw-output .commit $TEMP_FOLDER/VSCode-linux-x64/resources/app/product.json) |
33 | | -sed -i "s/rev = \".\{40\}\"/rev = \"${VSCODE_COMMIT}\"/" "$ROOT/vscode.nix" |
34 | | - |
35 | | -SERVER_X64_LINUX_URL="https://update.code.visualstudio.com/commit:${VSCODE_COMMIT}/server-linux-x64/stable" |
36 | | -SERVER_X64_LINUX_SHA256=$(nix-prefetch-url ${SERVER_X64_LINUX_URL}) |
37 | | -sed -i "s/sha256 = \".\{51,52\}\"/sha256 = \"${SERVER_X64_LINUX_SHA256}\"/" "$ROOT/vscode.nix" |
38 | | - |
39 | | -VSCODE_X64_DARWIN_URL="https://update.code.visualstudio.com/${VSCODE_VER}/darwin/stable" |
40 | | -VSCODE_X64_DARWIN_SHA256=$(nix-prefetch-url ${VSCODE_X64_DARWIN_URL}) |
41 | | -sed -i "s/x86_64-darwin = \".\{52\}\"/x86_64-darwin = \"${VSCODE_X64_DARWIN_SHA256}\"/" "$ROOT/vscode.nix" |
| 12 | +if [[ "$latestVersion" == "$currentVersion" ]]; then |
| 13 | + echo "package is up-to-date" |
| 14 | + exit 0 |
| 15 | +fi |
42 | 16 |
|
43 | | -VSCODE_AARCH64_LINUX_URL="https://update.code.visualstudio.com/${VSCODE_VER}/linux-arm64/stable" |
44 | | -VSCODE_AARCH64_LINUX_SHA256=$(nix-prefetch-url ${VSCODE_AARCH64_LINUX_URL}) |
45 | | -sed -i "s/aarch64-linux = \".\{52\}\"/aarch64-linux = \"${VSCODE_AARCH64_LINUX_SHA256}\"/" "$ROOT/vscode.nix" |
| 17 | +update-source-version vscode $latestVersion |
46 | 18 |
|
47 | | -VSCODE_AARCH64_DARWIN_URL="https://update.code.visualstudio.com/${VSCODE_VER}/darwin-arm64/stable" |
48 | | -VSCODE_AARCH64_DARWIN_SHA256=$(nix-prefetch-url ${VSCODE_AARCH64_DARWIN_URL}) |
49 | | -sed -i "s/aarch64-darwin = \".\{52\}\"/aarch64-darwin = \"${VSCODE_AARCH64_DARWIN_SHA256}\"/" "$ROOT/vscode.nix" |
| 19 | +systems=$(nix eval --json -f . vscode.meta.platforms | jq --raw-output '.[]') |
| 20 | +for system in $systems; do |
| 21 | + hash=$(nix hash convert --to sri --hash-algo sha256 $(nix-prefetch-url $(nix eval --raw -f . vscode.src.url --system "$system"))) |
| 22 | + update-source-version vscode $latestVersion $hash --system=$system --ignore-same-version --ignore-same-hash |
| 23 | +done |
50 | 24 |
|
51 | | -VSCODE_ARMV7L_LINUX_URL="https://update.code.visualstudio.com/${VSCODE_VER}/linux-armhf/stable" |
52 | | -VSCODE_ARMV7L_LINUX_SHA256=$(nix-prefetch-url ${VSCODE_ARMV7L_LINUX_URL}) |
53 | | -sed -i "s/armv7l-linux = \".\{52\}\"/armv7l-linux = \"${VSCODE_ARMV7L_LINUX_SHA256}\"/" "$ROOT/vscode.nix" |
| 25 | +rev=$(curl --fail --silent https://api.github.com/repos/Microsoft/vscode/git/ref/tags/$latestVersion | jq --raw-output .object.sha) |
| 26 | +update-source-version vscode $rev --version-key=rev --source-key=vscodeServer.src --ignore-same-version --ignore-same-hash |
0 commit comments