summaryrefslogtreecommitdiff
path: root/pkgs/by-name/po/positron-bin/update.sh
blob: a024b382ec961b685a0062e08e983c3011f702e6 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq git

nixpkgs="$(git rev-parse --show-toplevel)"
positron_nix="$nixpkgs/pkgs/by-name/po/positron-bin/package.nix"

current_version=$(grep -oP "version = \"\K.*\d" $positron_nix)
new_version=$(curl -sSfL \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  "https://api.github.com/repos/posit-dev/positron/releases?per_page=1" \
  | jq -r '.[0].name')

if [[ "$new_version" == "$current_version" ]]; then
    echo 'Positron is already up to date'
    exit 0;
fi

# Update Darwin hash.
current_hash=$(nix store prefetch-file --json --hash-type sha256 \
    "https://github.com/posit-dev/positron/releases/download/${current_version}/Positron-${current_version}.dmg" \
    | jq -r .hash)

new_hash=$(nix store prefetch-file --json --hash-type sha256 \
    "https://github.com/posit-dev/positron/releases/download/${new_version}/Positron-${new_version}.dmg" \
    | jq -r .hash)

sed -i "s|$current_hash|$new_hash|g" $positron_nix

# Update Linux hash.
current_hash=$(nix store prefetch-file --json --hash-type sha256 \
    "https://github.com/posit-dev/positron/releases/download/${current_version}/Positron-${current_version}-x64.deb" \
    | jq -r .hash)

new_hash=$(nix store prefetch-file --json --hash-type sha256 \
    "https://github.com/posit-dev/positron/releases/download/${new_version}/Positron-${new_version}-x64.deb" \
    | jq -r .hash)

sed -i "s|$current_hash|$new_hash|g" $positron_nix

# Update version
sed -i "s|$current_version|$new_version|g" $positron_nix

# Attempt to build.
export NIXPKGS_ALLOW_UNFREE=1

if ! nix-build -A positron-bin "$nixpkgs"; then
  echo "The updated positron-bin failed to build."
  exit 1
fi

# Commit changes
git add "$positron_nix"
git commit -m "positron-bin: ${current_version} -> ${new_version}"