1 #! /usr/bin/env nix-shell
2 #! nix-shell -i oil -p oil jq sd nix-prefetch-github ripgrep moreutils
4 # TODO set to `verbose` or `extdebug` once implemented in oil
6 # we need failures inside of command subs to get the correct dependency sha256
7 shopt --unset inherit_errexit
9 const directory = $(dirname $0 | xargs realpath)
10 const owner = "LemmyNet"
11 const ui_repo = "lemmy-ui"
12 const server_repo = "lemmy"
13 const latest_rev = $(curl -q https://api.github.com/repos/${owner}/${server_repo}/releases/latest | \
15 const latest_version = $(echo $latest_rev)
16 const current_version = $(jq -r '.version' $directory/pin.json)
17 echo "latest version: $latest_version, current version: $current_version"
18 if ("$latest_version" === "$current_version") {
19 echo "lemmy is already up-to-date"
22 # for some strange reason, hydra fails on reading upstream package.json directly
23 const source = "https://raw.githubusercontent.com/$owner/$ui_repo/$latest_version"
24 const package_json = $(curl -qf $source/package.json)
25 echo $package_json > $directory/package.json
27 const server_tarball_meta = $(nix-prefetch-github $owner $server_repo --rev $latest_rev --fetch-submodules)
28 const server_tarball_hash = "sha256-$(echo $server_tarball_meta | jq -r '.sha256')"
29 const ui_tarball_meta = $(nix-prefetch-github $owner $ui_repo --rev $latest_rev --fetch-submodules)
30 const ui_tarball_hash = "sha256-$(echo $ui_tarball_meta | jq -r '.sha256')"
32 jq ".version = \"$latest_version\" | \
33 .\"serverSha256\" = \"$server_tarball_hash\" | \
34 .\"uiSha256\" = \"$ui_tarball_hash\" | \
35 .\"serverCargoSha256\" = \"\" | \
36 .\"uiYarnDepsSha256\" = \"\"" $directory/pin.json | sponge $directory/pin.json
38 const new_cargo_sha256 = $(nix-build $directory/../../../.. -A lemmy-server 2>&1 | \
43 const new_offline_cache_sha256 = $(nix-build $directory/../../../.. -A lemmy-ui 2>&1 | \
48 jq ".\"serverCargoSha256\" = \"$new_cargo_sha256\" | \
49 .\"uiYarnDepsSha256\" = \"$new_offline_cache_sha256\"" \
50 $directory/pin.json | sponge $directory/pin.json