biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / development / tools / tabnine / update.sh
blob5269a027198b9cd6c1710df99cd446639f418525
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq git
3 #shellcheck shell=bash
5 set -euo pipefail
7 SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
9 function prefetch-sri() {
10 nix-prefetch-url "$1" 2>/dev/null |
11 xargs nix --experimental-features nix-command hash to-sri --type sha256
14 declare -A platforms=(
15 [x86_64-unknown-linux-musl]="x86_64-linux"
16 [x86_64-apple-darwin]="x86_64-darwin"
17 [aarch64-apple-darwin]="aarch64-darwin"
20 old_version="$(jq -r '.version' "$SCRIPT_DIR/sources.json")"
21 new_version="$(curl -sS https://update.tabnine.com/bundles/version)"
23 echo "Updating $old_version -> $new_version"
25 sources_tmp="$(mktemp)"
26 trap 'rm -f "$sources_tmp"' EXIT
28 cat <<EOF >"$sources_tmp"
30 "version": "$new_version",
31 "platforms": {}
33 EOF
35 for platform in "${!platforms[@]}"; do
36 url="https://update.tabnine.com/bundles/${new_version}/${platform}/TabNine.zip"
37 hash="$(prefetch-sri "$url")"
38 nix_platform="${platforms[$platform]}"
39 cat <<<"$(jq --arg nix_platform "$nix_platform" --arg platform "$platform" --arg hash "$hash" '.platforms += {($nix_platform): {name: $platform, hash: $hash}}' "$sources_tmp")" >"$sources_tmp"
40 done
42 cp "$sources_tmp" "$SCRIPT_DIR/sources.json"
44 if [[ `git status --porcelain "$SCRIPT_DIR/sources.json"` ]]; then
45 git add "$SCRIPT_DIR/sources.json"
46 git commit -m "tabnine: $old_version -> $new_version"
47 else
48 echo "No changes made to $SCRIPT_DIR/sources.json, skipping commit"