2025-12-09 17:24:11 +01:00
#!/usr/bin/env bash
set -euo pipefail
2025-12-16 17:14:24 +01:00
if [ -z " ${ BASH_VERSION :- } " ] ; then
exec bash " $0 " " $@ "
2025-12-09 17:24:11 +01:00
fi
2025-12-16 17:14:24 +01:00
# shellcheck disable=SC1091
2025-12-18 17:26:02 +01:00
. " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) /../lib/common.sh "
2025-12-16 21:20:27 +01:00
update_nomos_rev::usage( ) {
cat <<'EOF'
Usage:
2025-12-18 17:26:02 +01:00
scripts/ops/update-nomos-rev.sh --rev <git_rev>
scripts/ops/update-nomos-rev.sh --path <local_dir>
scripts/ops/update-nomos-rev.sh --unskip-worktree
2025-12-16 21:20:27 +01:00
Notes:
2026-01-26 16:36:51 +01:00
--rev sets LOGOS_BLOCKCHAIN_NODE_REV and updates Cargo.toml revs
--path sets LOGOS_BLOCKCHAIN_NODE_PATH ( clears LOGOS_BLOCKCHAIN_NODE_REV) and patches Cargo.toml to use a local logos-blockchain-node checkout
2025-12-16 21:20:27 +01:00
--unskip-worktree clears any skip-worktree flag for Cargo.toml
Only one may be used at a time.
EOF
}
update_nomos_rev::fail_with_usage( ) {
echo " $1 " >& 2
update_nomos_rev::usage
exit 1
}
update_nomos_rev::maybe_unskip_worktree( ) {
local file = " $1 "
if git -C " ${ ROOT_DIR } " rev-parse --is-inside-work-tree >/dev/null 2>& 1; then
git -C " ${ ROOT_DIR } " update-index --no-skip-worktree " ${ file } " >/dev/null 2>& 1 || true
fi
}
update_nomos_rev::maybe_skip_worktree( ) {
local file = " $1 "
if git -C " ${ ROOT_DIR } " rev-parse --is-inside-work-tree >/dev/null 2>& 1; then
git -C " ${ ROOT_DIR } " update-index --skip-worktree " ${ file } " >/dev/null 2>& 1 || true
fi
}
update_nomos_rev::ensure_env_key( ) {
local key = " $1 " default_value = " $2 "
if ! grep -Eq " ^#?[[:space:]]* ${ key } = " " ${ ROOT_DIR } /versions.env " ; then
echo " ${ default_value } " >> " ${ ROOT_DIR } /versions.env "
fi
}
update_nomos_rev::parse_args( ) {
REV = ""
LOCAL_PATH = ""
UNSKIP_WORKTREE = 0
while [ " $# " -gt 0 ] ; do
case " $1 " in
--rev) REV = " ${ 2 :- } " ; shift 2 ; ;
--path) LOCAL_PATH = " ${ 2 :- } " ; shift 2 ; ;
--unskip-worktree) UNSKIP_WORKTREE = 1; shift ; ;
-h| --help) update_nomos_rev::usage; exit 0 ; ;
*) update_nomos_rev::fail_with_usage " Unknown arg: $1 " ; ;
esac
done
if [ " ${ UNSKIP_WORKTREE } " -eq 1 ] && { [ -n " ${ REV } " ] || [ -n " ${ LOCAL_PATH } " ] ; } ; then
update_nomos_rev::fail_with_usage "Use --unskip-worktree alone."
fi
if [ -n " ${ REV } " ] && [ -n " ${ LOCAL_PATH } " ] ; then
update_nomos_rev::fail_with_usage "Use either --rev or --path, not both"
fi
if [ -z " ${ REV } " ] && [ -z " ${ LOCAL_PATH } " ] && [ " ${ UNSKIP_WORKTREE } " -eq 0 ] ; then
update_nomos_rev::usage
exit 1
fi
}
update_nomos_rev::load_env( ) {
ROOT_DIR = " $( common::repo_root) "
export ROOT_DIR
common::require_file " ${ ROOT_DIR } /versions.env "
}
update_nomos_rev::update_to_rev( ) {
local rev = " $1 "
2026-01-20 13:39:43 +01:00
echo " Updating logos-blockchain-node rev to ${ rev } "
2025-12-16 21:20:27 +01:00
sed -i.bak -E \
2026-01-26 16:36:51 +01:00
-e " s/^#?[[:space:]]*LOGOS_BLOCKCHAIN_NODE_REV=.*/LOGOS_BLOCKCHAIN_NODE_REV= ${ rev } / " \
-e "s/^#?[[:space:]]*LOGOS_BLOCKCHAIN_NODE_PATH=.*/# LOGOS_BLOCKCHAIN_NODE_PATH=/" \
2025-12-16 21:20:27 +01:00
" ${ ROOT_DIR } /versions.env "
rm -f " ${ ROOT_DIR } /versions.env.bak "
python3 - " ${ ROOT_DIR } " " ${ rev } " <<'PY'
import pathlib, re, sys
root = pathlib.Path( sys.argv[ 1] )
rev = sys.argv[ 2]
cargo_toml = root / "Cargo.toml"
txt = cargo_toml.read_text( )
txt = txt.replace( "\\n" , "\n" )
txt = re.sub(
2026-01-22 05:57:59 +01:00
r'(?ms)^\[patch\."https://github\.com/logos-co/nomos-node"\].*?(?=^\[|\Z)' ,
2025-12-16 21:20:27 +01:00
"" ,
txt,
)
txt = re.sub(
2026-01-22 05:57:59 +01:00
r'(git = "https://github\.com/logos-co/nomos-node\.git", rev = ")[^"]+(")' ,
2025-12-16 21:20:27 +01:00
r"\g<1>" + rev + r"\2" ,
txt,
)
cargo_toml.write_text( txt.rstrip( ) + "\n" )
PY
update_nomos_rev::maybe_unskip_worktree "Cargo.toml"
}
update_nomos_rev::update_to_path( ) {
local node_path = " $1 "
2026-01-20 13:39:43 +01:00
echo " Pointing to local logos-blockchain-node at ${ node_path } "
2025-12-16 21:20:27 +01:00
[ -d " ${ node_path } " ] || common::die " path does not exist: ${ node_path } "
local current_rev escaped_path
2026-01-26 16:36:51 +01:00
current_rev = " $( grep -E '^[#[:space:]]*LOGOS_BLOCKCHAIN_NODE_REV=' " ${ ROOT_DIR } /versions.env " | head -n1 | sed -E 's/^#?[[:space:]]*LOGOS_BLOCKCHAIN_NODE_REV=//' ) "
2025-12-16 21:20:27 +01:00
escaped_path = " ${ node_path // \/ / \\ / } "
2025-12-09 17:24:11 +01:00
2025-12-16 21:20:27 +01:00
sed -i.bak -E \
2026-01-26 16:36:51 +01:00
-e " s/^#?[[:space:]]*LOGOS_BLOCKCHAIN_NODE_PATH=.*/LOGOS_BLOCKCHAIN_NODE_PATH= ${ escaped_path } / " \
-e " s/^#?[[:space:]]*LOGOS_BLOCKCHAIN_NODE_REV=.*/# LOGOS_BLOCKCHAIN_NODE_REV= ${ current_rev } / " \
2025-12-16 21:20:27 +01:00
" ${ ROOT_DIR } /versions.env "
rm -f " ${ ROOT_DIR } /versions.env.bak "
local python_bin = " ${ PYTHON_BIN :- python3 } "
command -v " ${ python_bin } " >/dev/null 2>& 1 || common::die "python3 is required to patch Cargo.toml for local paths"
" ${ python_bin } " - " ${ ROOT_DIR } " " ${ node_path } " <<'PY'
import json
import pathlib
import re
import subprocess
import sys
root = pathlib.Path( sys.argv[ 1] )
node_path = pathlib.Path( sys.argv[ 2] )
targets = [
2026-01-20 13:39:43 +01:00
"logos-blockchain-api-service" ,
"logos-blockchain-blend-message" ,
"logos-blockchain-blend-service" ,
"logos-blockchain-chain-broadcast-service" ,
"logos-blockchain-chain-leader-service" ,
"logos-blockchain-chain-network-service" ,
"logos-blockchain-chain-service" ,
"logos-blockchain-common-http-client" ,
"logos-blockchain-cryptarchia-engine" ,
"logos-blockchain-cryptarchia-sync" ,
"logos-blockchain-groth16" ,
"logos-blockchain-http-api-common" ,
"logos-blockchain-key-management-system-service" ,
"logos-blockchain-ledger" ,
"logos-blockchain-libp2p" ,
"logos-blockchain-network-service" ,
"logos-blockchain-node" ,
"logos-blockchain-poc" ,
"logos-blockchain-pol" ,
"logos-blockchain-sdp-service" ,
"logos-blockchain-tests" ,
"logos-blockchain-time-service" ,
"logos-blockchain-tracing" ,
"logos-blockchain-tracing-service" ,
"logos-blockchain-tx-service" ,
"logos-blockchain-utils" ,
"logos-blockchain-wallet" ,
"logos-blockchain-wallet-service" ,
"logos-blockchain-zksign" ,
2025-12-16 21:20:27 +01:00
]
try:
meta = subprocess.check_output(
[ "cargo" , "metadata" , "--format-version" , "1" , "--no-deps" ] ,
cwd = node_path,
)
except subprocess.CalledProcessError as exc:
sys.stderr.write( f"Failed to run cargo metadata in {node_path}: {exc}\n" )
sys.exit( 1)
data = json.loads( meta)
paths = { }
for pkg in data.get( "packages" , [ ] ) :
paths[ pkg[ "name" ] ] = str( pathlib.Path( pkg[ "manifest_path" ] ) .parent)
patch_lines = [ '[patch."https://github.com/logos-co/nomos-node"]' ]
missing = [ ]
for name in targets:
if name in paths:
patch_lines.append( f'{name} = {{ path = "{paths[name]}" }}' )
else :
missing.append( name)
cargo_toml = root / "Cargo.toml"
txt = cargo_toml.read_text( )
txt = txt.replace( "\\n" , "\n" )
txt = re.sub(
2026-01-22 05:57:59 +01:00
r'(?ms)^\[patch\."https://github\.com/logos-co/nomos-node"\].*?(?=^\[|\Z)' ,
2025-12-16 21:20:27 +01:00
"" ,
txt,
)
txt = txt.rstrip( ) + "\n\n" + "\n" .join( patch_lines) + "\n"
cargo_toml.write_text( txt)
if missing:
sys.stderr.write(
2026-01-20 13:39:43 +01:00
"Warning: missing crates in local logos-blockchain-node checkout: "
2025-12-16 21:20:27 +01:00
+ ", " .join( missing)
+ "\n"
)
PY
update_nomos_rev::maybe_skip_worktree "Cargo.toml"
2026-01-20 13:39:43 +01:00
echo "Local logos-blockchain-node patch applied; Cargo.toml marked skip-worktree (run --unskip-worktree to clear)."
2025-12-16 21:20:27 +01:00
}
update_nomos_rev::main( ) {
update_nomos_rev::load_env
update_nomos_rev::parse_args " $@ "
2026-01-26 16:36:51 +01:00
update_nomos_rev::ensure_env_key "LOGOS_BLOCKCHAIN_NODE_REV" "# LOGOS_BLOCKCHAIN_NODE_REV="
update_nomos_rev::ensure_env_key "LOGOS_BLOCKCHAIN_NODE_PATH" "# LOGOS_BLOCKCHAIN_NODE_PATH="
2025-12-16 21:20:27 +01:00
if [ " ${ UNSKIP_WORKTREE } " -eq 1 ] ; then
update_nomos_rev::maybe_unskip_worktree "Cargo.toml"
echo "Cleared skip-worktree on Cargo.toml (if it was set)."
exit 0
fi
if [ -n " ${ REV } " ] ; then
update_nomos_rev::update_to_rev " ${ REV } "
else
update_nomos_rev::update_to_path " ${ LOCAL_PATH } "
fi
echo "Done. Consider updating Cargo.lock if needed (cargo fetch)."
}
if [ [ " ${ BASH_SOURCE [0] } " = = " $0 " ] ] ; then
update_nomos_rev::main " $@ "
fi