Merge pull request #330634 from r-ryantm/auto-update/circumflex
[NixPkgs.git] / pkgs / servers / mail / mailpit / update.sh
blob979cd11cda8a70dfc6bca80995bb16c264d327d7
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p nix coreutils curl jq nix-prefetch-git prefetch-npm-deps
4 set -euo pipefail
6 OWNER=axllent
7 REPO=mailpit
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
15 echo "[{}]";
18 exit 0
21 extractVendorHash() {
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"; }
27 TMP="$(mktemp -d)"
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";
48 EOF
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";
60 EOF
62 if [[ -z "$UPDATE_NIX_ATTR_PATH" ]]; then
63 exit 0
66 cat <<-EOF
68 "attrPath": "$UPDATE_NIX_ATTR_PATH",
69 "oldVersion": "$UPDATE_NIX_OLD_VERSION",
70 "newVersion": "$TARGET_VERSION",
71 "files": ["$VERSIONS_NIX"]
73 EOF