-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathupdate_dependencies.sh
executable file
·83 lines (71 loc) · 2.07 KB
/
update_dependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Copyright (c) Mysten Labs, Inc.
# SPDX-License-Identifier: Apache-2.0
# This script attempts to update the Narwhal pointer in Sui
# It is expected to fail in cases
set -e
set -eo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TOPLEVEL="${DIR}/../"
GREP=${GREP:=grep}
# Crutch for old bash versions
# Very minimal readarray implementation using read.
readarray() {
while IFS= read -r var; do
MAPFILE+=("$var")
done
}
# check for the presence of needed executables:
# - we use GNU grep in perl re mode
# - we use cargo-hakari
function check_gnu_grep() {
GNUSTRING=$($GREP --version|head -n1| grep 'GNU grep')
if [[ -z $GNUSTRING ]];
then
echo "Could not find GNU grep. This requires GNU grep 3.7 with PCRE expressions"; exit 1
else
return 0
fi
}
function check_cargo_hakari() {
cargo hakari --version > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Could not find cargo hakari. Please install"; exit 1
else
return 0
fi
}
function latest_mi_revision() {
MI_CHECKOUT=$(mktemp -d)
cd "$MI_CHECKOUT"
git clone --depth 1 https://github.com/mystenlabs/mysten-infra
cd mysten-infra
git rev-parse HEAD
}
function current_mi_revision() {
cd "$TOPLEVEL"
readarray -t <<< "$(find ./ -iname '*.toml' -exec $GREP -oPie 'git = "https://github.com/[mM]ystenLabs/mysten-infra(\.git)?", *rev *= *\"\K[0-9a-fA-F]+' '{}' \;)"
watermark=${MAPFILE[0]}
for i in "${MAPFILE[@]}"; do
if [[ "$watermark" != "$i" ]]; then
not_equal=true
break
fi
done
[[ -n "$not_equal" ]] && echo "Different values found for the current mysten-infra revision in NW, aborting" && exit 1
echo "$watermark"
}
# Check for tooling
check_gnu_grep
check_cargo_hakari
# Debug prints for mysten-infra
CURRENT_MI=$(current_mi_revision)
LATEST_MI=$(latest_mi_revision)
if [[ "$CURRENT_MI" != "$LATEST_MI" ]]; then
echo "About to replace $CURRENT_MI with $LATEST_MI as the mysten-infra pointer in Narwhal"
else
exit 0
fi
# Edit the source & run hakari
find ./ -iname "*.toml" -execdir sed -i '' -re "s/$CURRENT_MI/$LATEST_MI/" '{}' \;
cargo hakari generate