Skip to content

Commit 93bf23b

Browse files
printing the ran commands and their outputs
1 parent 657efeb commit 93bf23b

5 files changed

Lines changed: 79 additions & 23 deletions

File tree

scripts/ops/common.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,39 @@ confirm() {
3030
read -rp "$1 [y/N] " reply
3131
[[ "$reply" == y || "$reply" == Y ]]
3232
}
33+
34+
# Render a command so the printed line stays copy-pasteable: anything outside
35+
# the shell-safe set gets single-quoted.
36+
fmt_cmd() {
37+
local out="" arg
38+
for arg in "$@"; do
39+
case "$arg" in
40+
''|*[!A-Za-z0-9_/.:=@%+,-]*) out+=" '${arg//\'/\'\\\'\'}'" ;;
41+
*) out+=" $arg" ;;
42+
esac
43+
done
44+
printf '%s' "${out# }"
45+
}
46+
47+
# Echo a command as it runs. Goes to stderr so it stays visible even when the
48+
# caller captures the command's stdout.
49+
show_cmd() {
50+
printf '\n $ %s\n' "$(fmt_cmd "$@")" >&2
51+
}
52+
53+
# Echo a captured response the caller would otherwise swallow, truncating the
54+
# long ones (Nomad job definitions run to several KB).
55+
show_output() {
56+
local text=$1 limit=${2:-1500}
57+
if (( ${#text} > limit )); then
58+
printf '%s\n … (%d more characters)\n' "${text:0:limit}" "$(( ${#text} - limit ))" >&2
59+
else
60+
printf '%s\n' "$text" >&2
61+
fi
62+
}
63+
64+
# Print a command, run it, and let its output through.
65+
run_cmd() {
66+
show_cmd "$@"
67+
"$@"
68+
}

scripts/ops/dev-cluster/dev-common.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ verify_nodes() {
3838

3939
local addr info ok=0 fail=0
4040
for addr in ${MPC_NODE_ADDRS}; do
41-
printf '%s: ' "$addr"
41+
show_cmd curl -sf "http://${addr}/metrics" '|' grep mpc_node_build_info
4242
info=$(curl -sf --max-time 5 "http://${addr}/metrics" \
43-
| grep -o 'mpc_node_build_info{[^}]*}') || { echo "(unreachable)"; fail=1; continue; }
44-
echo "$info"
43+
| grep -o 'mpc_node_build_info{[^}]*}') || { echo " (unreachable)"; fail=1; continue; }
44+
echo " $info"
4545
if [[ "$info" == *"release=\"${version}\""* ]]; then ok=1; else fail=1; fi
4646
done
4747
[[ "$fail" -eq 0 && "$ok" -eq 1 ]] \
@@ -56,11 +56,14 @@ test_sign() {
5656

5757
local signer=${MEMBER_ACCOUNTS%% *}
5858
local payload='[12,1,2,0,4,5,6,8,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,44]'
59+
local cmd=(near call --network-id "$NEAR_NET" "$CONTRACT" sign
60+
"{\"request\": {\"payload\": ${payload}, \"path\": \"test\", \"key_version\": 0}}"
61+
--accountId "$signer" --gas 300000000000000 --deposit "$SIGN_DEPOSIT")
62+
5963
echo "Test sign on ${CONTRACT} as ${signer} (deposit ${SIGN_DEPOSIT} NEAR)."
64+
show_cmd "${cmd[@]}"
6065
confirm "Send it?" || return 0
61-
near call --network-id "$NEAR_NET" "$CONTRACT" sign \
62-
"{\"request\": {\"payload\": ${payload}, \"path\": \"test\", \"key_version\": 0}}" \
63-
--accountId "$signer" --gas 300000000000000 --deposit "$SIGN_DEPOSIT" \
66+
"${cmd[@]}" \
6467
&& echo "Signature returned — the cluster is signing." \
6568
|| echo "Test sign failed — investigate before proceeding."
6669
}

scripts/ops/dev-cluster/dev-menu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ confirm "Proceed?" || { echo "Aborted."; exit 0; }
5454

5555
echo
5656
echo "### Step 1 — nodes"
57-
"${SCRIPT_DIR}/migrate-dev-cluster.sh" "$VERSION" \
57+
run_cmd "${SCRIPT_DIR}/migrate-dev-cluster.sh" "$VERSION" \
5858
|| die "Node upgrade did not complete — stopping before the contract step."
5959

6060
echo
@@ -67,7 +67,7 @@ echo
6767
echo "### Step 2 — contract"
6868
echo "Only for releases that change crates/contract (diff it between the two tags)."
6969
if confirm "Upgrade the contract too?"; then
70-
"${SCRIPT_DIR}/upgrade-dev-contract.sh" "$VERSION" "$NETWORK" || true
70+
run_cmd "${SCRIPT_DIR}/upgrade-dev-contract.sh" "$VERSION" "$NETWORK" || true
7171
else
7272
echo "Skipped — nodes only."
7373
fi

scripts/ops/dev-cluster/migrate-dev-cluster.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1616
# shellcheck source=../common.sh
1717
source "${SCRIPT_DIR}/../common.sh"
1818

19+
# Echoes the request being made and, for mutations, the response the caller
20+
# would otherwise swallow. Credentials are never part of what's printed.
1921
nomad_curl() {
2022
local method=$1 path=$2 data=${3:-}
21-
local args=(-sf --max-time 30 -X "$method" "${NOMAD_ADDR%/}/v1${path}")
23+
local url="${NOMAD_ADDR%/}/v1${path}"
24+
local args=(-sf --max-time 30 -X "$method" "$url")
2225
[[ -z "${NOMAD_TOKEN:-}" ]] || args+=(-H "X-Nomad-Token: ${NOMAD_TOKEN}")
2326
[[ -z "$data" ]] || args+=(-H 'Content-Type: application/json' --data "$data")
27+
28+
show_cmd curl -X "$method" "$url" ${data:+--data @-}
29+
30+
local response
2431
if [[ -n "${NOMAD_HTTP_AUTH:-}" ]]; then
2532
# -K - keeps the credentials out of the process list.
26-
printf 'user = "%s"\n' "$NOMAD_HTTP_AUTH" | curl -K - "${args[@]}"
33+
response=$(printf 'user = "%s"\n' "$NOMAD_HTTP_AUTH" | curl -K - "${args[@]}") || return 1
2734
else
28-
curl "${args[@]}"
35+
response=$(curl "${args[@]}") || return 1
2936
fi
37+
38+
# GET bodies are job definitions the caller only parses; showing them buries
39+
# the interesting output, so only mutations are echoed.
40+
[[ "$method" == GET ]] || show_output "$response"
41+
printf '%s' "$response"
3042
}
3143

3244
# Credentials are supplied per run rather than kept in the environment.
@@ -93,6 +105,7 @@ upgrade_nomad_job() {
93105
confirm " Apply to ${job_id} on ${NOMAD_ADDR}?" || { echo " skipped."; return; }
94106
nomad_curl POST "/job/${job_id}" "$(jq -n --argjson job "$updated" '{Job: $job}')" >/dev/null \
95107
|| die "Job registration failed for ${job_id}."
108+
echo
96109
wait_for_alloc "$job_id"
97110
}
98111

scripts/ops/dev-cluster/upgrade-dev-contract.sh

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ fetch_wasm() {
5151
else
5252
echo "==> Downloading contract WASM from release ${version}..." >&2
5353
require_cmds gh tar
54-
gh release download "$version" --repo near/mpc \
54+
run_cmd gh release download "$version" --repo near/mpc \
5555
--pattern "mpc-contract-v${version}.tar.gz" --dir "$dir" --clobber >&2
56-
tar xzf "${dir}/mpc-contract-v${version}.tar.gz" -C "$dir" >&2
56+
run_cmd tar xzf "${dir}/mpc-contract-v${version}.tar.gz" -C "$dir" >&2
5757
[[ -f "$wasm" ]] || die "Expected ${wasm} after extracting the tarball."
5858
fi
5959
else
6060
require_cmds cargo git
6161
local root built
6262
root=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel)
6363
echo "==> Building the contract from ${root} (local build — not a released artifact)..." >&2
64-
( cd "$root" && cargo near build non-reproducible-wasm --features abi \
64+
( cd "$root" && run_cmd cargo near build non-reproducible-wasm --features abi \
6565
--profile=release-contract --manifest-path crates/contract/Cargo.toml --locked >&2 )
6666
built=$(find "${root}/target/near" -maxdepth 1 -name '*.wasm' -newermt '-10 minutes' \
6767
| head -1)
@@ -97,19 +97,22 @@ WASM_SIZE=$(wc -c < "$WASM")
9797
echo "==> ${SERIALIZED} ready ($(wc -c < "$SERIALIZED") bytes)"
9898

9999
PROPOSER=${MEMBER_ACCOUNTS%% *}
100+
PROPOSE_CMD=(near contract call-function as-transaction "$CONTRACT" propose_update
101+
file-args "$SERIALIZED" prepaid-gas '100.0 Tgas' attached-deposit "$PROPOSE_DEPOSIT"
102+
sign-as "$PROPOSER" network-config "$NEAR_NET" "$SIGN_WITH" send)
103+
100104
echo
101105
echo "About to propose the ${VERSION} contract on ${CONTRACT} (${NEAR_NET})"
102106
echo " proposer: ${PROPOSER}, deposit ${PROPOSE_DEPOSIT}"
107+
show_cmd "${PROPOSE_CMD[@]}"
103108
confirm "Send propose_update?" || { echo "Aborted before proposing."; exit 0; }
104109

105-
near contract call-function as-transaction "$CONTRACT" propose_update \
106-
file-args "$SERIALIZED" prepaid-gas '100.0 Tgas' attached-deposit "$PROPOSE_DEPOSIT" \
107-
sign-as "$PROPOSER" network-config "$NEAR_NET" "$SIGN_WITH" send \
110+
"${PROPOSE_CMD[@]}" \
108111
|| die "propose_update failed (an account low on NEAR is the usual cause — top it up)."
109112

110113
echo
111114
echo "==> Pending proposals:"
112-
near contract call-function as-read-only "$CONTRACT" proposed_updates \
115+
run_cmd near contract call-function as-read-only "$CONTRACT" proposed_updates \
113116
json-args '{}' network-config "$NEAR_NET" now || true
114117

115118
# near-cli's result formatting is not stable enough to parse an id out of, so
@@ -120,14 +123,15 @@ read -rp "UpdateId to vote on: " UPDATE_ID
120123
# The vote that reaches threshold deploys + migrates inline, hence 300 Tgas.
121124
for account in $MEMBER_ACCOUNTS; do
122125
echo
126+
vote_cmd=(near contract call-function as-transaction "$CONTRACT" vote_update
127+
json-args "{\"id\": ${UPDATE_ID}}" prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR'
128+
sign-as "$account" network-config "$NEAR_NET" "$SIGN_WITH" send)
129+
show_cmd "${vote_cmd[@]}"
123130
confirm "Vote for update ${UPDATE_ID} as ${account}?" || { echo " skipped."; continue; }
124-
near contract call-function as-transaction "$CONTRACT" vote_update \
125-
json-args "{\"id\": ${UPDATE_ID}}" prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' \
126-
sign-as "$account" network-config "$NEAR_NET" "$SIGN_WITH" send \
127-
|| echo " vote failed for ${account}."
131+
"${vote_cmd[@]}" || echo " vote failed for ${account}."
128132
done
129133

130134
echo
131135
echo "==> Contract version (expect ${VERSION} once threshold was reached):"
132-
near contract call-function as-read-only "$CONTRACT" version \
136+
run_cmd near contract call-function as-read-only "$CONTRACT" version \
133137
json-args '{}' network-config "$NEAR_NET" now || true

0 commit comments

Comments
 (0)