blob: f925f75bcd70e53dae7492c0348d7059a4a9f097 (
plain) (
blame)
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
55
56
|
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix wget nix-prefetch-github moreutils jq prefetch-npm-deps nodejs
set -euo pipefail
TARGET_VERSION_REMOTE=$(curl -s https://api.github.com/repos/usememos/memos/releases/latest | jq -r ".tag_name")
TARGET_VERSION=${TARGET_VERSION_REMOTE#v}
if [[ "$UPDATE_NIX_OLD_VERSION" == "$TARGET_VERSION" ]]; then
echo "memos is up-to-date: ${UPDATE_NIX_OLD_VERSION}"
exit 0
fi
extractVendorHash() {
original="${1?original hash missing}"
result="$(nix-build -A memos.go-modules 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
[ -z "$result" ] && { echo "$original"; } || { echo "$result"; }
}
replaceHash() {
old="${1?old hash missing}"
new="${2?new hash missing}"
awk -v OLD="$old" -v NEW="$new" '{
if (i=index($0, OLD)) {
$0 = substr($0, 1, i-1) NEW substr($0, i+length(OLD));
}
print $0;
}' ./pkgs/servers/memos/default.nix | sponge ./pkgs/servers/memos/default.nix
}
# change version number
sed -e "s/version =.*;/version = \"$TARGET_VERSION\";/g" \
-i ./pkgs/servers/memos/default.nix
# update hash
SRC_HASH="$(nix-instantiate --eval -A memos.src.outputHash | tr -d '"')"
NEW_HASH="$(nix-prefetch-github usememos memos --rev v$TARGET_VERSION | jq -r .sha256)"
replaceHash "$SRC_HASH" "$NEW_HASH"
GO_HASH="$(nix-instantiate --eval -A memos.vendorSha256 | tr -d '"')"
EMPTY_HASH="$(nix-instantiate --eval -A lib.fakeSha256 | tr -d '"')"
replaceHash "$GO_HASH" "$EMPTY_HASH"
replaceHash "$EMPTY_HASH" "$(extractVendorHash "$GO_HASH")"
# update src yarn lock
SRC_FILE_BASE="https://raw.githubusercontent.com/usememos/memos/v$TARGET_VERSION"
trap 'rm -rf ./pkgs/servers/memos/package.json' EXIT
pushd ./pkgs/servers/memos
wget -q "$SRC_FILE_BASE/web/package.json"
npm install --package-lock-only
NPM_HASH=$(prefetch-npm-deps ./package-lock.json)
popd
sed -i -E -e "s#npmDepsHash = \".*\"#npmDepsHash = \"$NPM_HASH\"#" ./pkgs/servers/memos/default.nix
|