fix(n8n/update.sh): print diagnostics instead of dying silently

Under `set -euo pipefail` the pnpmDeps hash-extraction pipeline
(`grep -oE | grep -v | tail`) returns non-zero when the nix build output
contains no real sha256 — aborting the script BEFORE the ERROR
diagnostics could run. Symptom: update.sh exited 1 right after
'Computing pnpmDeps hash ...' with no message at all.

- Append `|| true` to the extraction pipeline so the empty-hash
  diagnostics are reachable again
- Same hardening for the GitHub release lookup (curl/jq) and
  nix-prefetch-url (now with an explicit guard + message)
- New diagnostic branch for ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY
  (newer upstream pnpm-lock serialisation → bump the pnpm major)
This commit is contained in:
Sascha König committed 2026-10-28 14:12:07 +01:00
1 parent 14baf2a926
commit 68e22ee34b
1 file changed
+24 -4
+24 -4
View File
@@ -71,8 +71,11 @@ TAG_PREFIX="n8n@"
# ── 1. Latest stable release ───────────────────────────────────────────────
echo "Fetching latest stable release of $REPO ..."
# `|| true` keeps `set -euo pipefail` from killing the script inside the
# substitution on curl/jq failure (e.g. network down) — the empty-value
# check below then produces the actual error message.
LATEST_TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" |
jq -r 'select(.prerelease == false) | .tag_name')
jq -r 'select(.prerelease == false) | .tag_name' || true)
if [[ -z "$LATEST_TAG" ]]; then
echo "ERROR: No stable release found for $REPO" >&2
@@ -114,8 +117,14 @@ sed -i "s|^\([[:space:]]*\)version = \"[^\"]*\";|\1version = \"$VERSION\";|" "$N
echo "==> Computing src hash ..."
SRC_URL="https://github.com/$REPO/archive/refs/tags/${TAG_PREFIX}${VERSION}.tar.gz"
# `--name n8n-source` works around the `@` in the upstream tag name
# (nix-prefetch-url refuses filenames containing `@`).
SRC_HASH=$(nix-prefetch-url --unpack --type sha256 --name n8n-source "$SRC_URL" 2>/dev/null)
# (nix-prefetch-url refuses filenames containing `@`). `|| true` + guard so a
# prefetch failure (network, rate limit, vanished tag) prints an error instead
# of dying silently under `set -e` (stderr is discarded on purpose above).
SRC_HASH=$(nix-prefetch-url --unpack --type sha256 --name n8n-source "$SRC_URL" 2>/dev/null || true)
if [[ -z "$SRC_HASH" ]]; then
echo "ERROR: nix-prefetch-url could not fetch/hash $SRC_URL" >&2
exit 1
fi
SRC_SRI=$(nix hash convert --hash-algo sha256 --to sri "$SRC_HASH")
echo " src hash: $SRC_SRI"
@@ -155,10 +164,15 @@ BUILD_OUTPUT=$(nix build --impure --no-link --expr "$NIX_EXPR" 2>&1 || true)
# "specified"/"Expected" and the correct one as "got:"/"Got:". Different nix
# versions label/capitalise differently, so filter out the sentinel and take
# whatever real sha256 remains.
#
# The trailing `|| true` is load-bearing: with `set -euo pipefail` a pipeline
# like `grep -oE | grep -v | tail` returns non-zero when NO hash is present
# (grep finds nothing / grep -v filters everything), which used to abort the
# script right here — silently, before the diagnostics below could run.
PNPM_HASH=$(echo "$BUILD_OUTPUT" |
grep -oE 'sha256-[A-Za-z0-9+/=]+' |
grep -v 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' |
tail -1)
tail -1 || true)
if [[ -z "$PNPM_HASH" ]]; then
echo "ERROR: could not extract a pnpmDeps hash from the build output." >&2
@@ -170,6 +184,12 @@ if [[ -z "$PNPM_HASH" ]]; then
echo " Cause: the pinned pnpm cannot parse upstream's pnpm-lock.yaml" >&2
echo " anymore (lockfile serialisation changed across pnpm majors)." >&2
echo " Bump the pnpm major and fetcherVersion in $NIX_FILE." >&2
elif grep -q 'ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY' <<<"$BUILD_OUTPUT"; then
echo " Cause: the pinned pnpm cannot resolve upstream's pnpm-lock.yaml" >&2
echo " (upstream serialises newer lockfile constructs, e.g. patched-" >&2
echo " dependency patch_hash keys, that this pnpm major mishandles)." >&2
echo " Bump the pnpm major in $NIX_FILE (fetchPnpmDeps AND the" >&2
echo " nativeBuildInputs swap threshold)." >&2
else
echo " This usually means fetchPnpmDeps failed for a reason OTHER than" >&2
echo " a hash mismatch (e.g. a pnpm-lock patch in n8n.nix no longer applies," >&2