1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p nix coreutils curl jq nix-prefetch-git prefetch-npm-deps
9 TARGET_TAG
="$(curl -L -s ${GITHUB_TOKEN:+-u ":${GITHUB_TOKEN}"} "https
://api.github.com
/repos
/$OWNER/$REPO/releases
/latest
" | jq -r '.tag_name')"
10 TARGET_VERSION
="$(echo "$TARGET_TAG" | sed -e 's/^v//')"
12 if [[ "$UPDATE_NIX_OLD_VERSION" == "$TARGET_VERSION" ]]; then
13 # mailpit is up-to-date
14 if [[ -n "$UPDATE_NIX_ATTR_PATH" ]]; then
22 original
="${1?original hash missing}"
23 result
="$(nix-build -A mailpit.goModules 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
24 [ -z "$result" ] && { echo "$original"; } ||
{ echo "$result"; }
28 trap 'rm -rf "$TMP"' exit
30 NIXPKGS_MAILPIT_PATH
=$
(cd $
(dirname ${BASH_SOURCE[0]}); pwd -P)/
31 VERSIONS_NIX
="$NIXPKGS_MAILPIT_PATH/versions.nix"
33 PREFETCH_JSON
=$TMP/prefetch.json
34 nix-prefetch-git
--rev "$TARGET_TAG" --url "https://github.com/$OWNER/$REPO" > "$PREFETCH_JSON"
35 PREFETCH_HASH
="$(jq '.hash' -r < "$PREFETCH_JSON")"
36 PREFETCH_PATH
="$(jq '.path' -r < "$PREFETCH_JSON")"
37 NPM_DEPS_HASH
="$(prefetch-npm-deps $PREFETCH_PATH/package-lock.json)"
39 FAKE_HASH
="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
41 cat > $VERSIONS_NIX <<-EOF
43 version = "$TARGET_VERSION";
44 hash = "$PREFETCH_HASH";
45 npmDepsHash = "$NPM_DEPS_HASH";
46 vendorHash = "$FAKE_HASH";
50 GO_HASH
="$(nix-instantiate --eval -A mailpit.vendorHash | tr -d '"')"
51 VENDOR_HASH=$(extractVendorHash "$GO_HASH")
53 cat > $VERSIONS_NIX <<-EOF
55 version = "$TARGET_VERSION";
56 hash = "$PREFETCH_HASH";
57 npmDepsHash = "$NPM_DEPS_HASH";
58 vendorHash = "$VENDOR_HASH";
62 if [[ -z "$UPDATE_NIX_ATTR_PATH" ]]; then
68 "attrPath": "$UPDATE_NIX_ATTR_PATH",
69 "oldVersion": "$UPDATE_NIX_OLD_VERSION",
70 "newVersion": "$TARGET_VERSION",
71 "files": ["$VERSIONS_NIX"]