Skip to content

Commit 8a948be

Browse files
authored
Merge pull request #1210 from gwillen/feature-andrew-merge-script
Check in Andrew's script for merging changes into Elements integration branch
2 parents 5cb3ace + 443a8c8 commit 8a948be

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed

contrib/merge-prs.sh

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
BASE_ORIG=merged-master
6+
BASE="${BASE_ORIG}"
7+
BITCOIN_UPSTREAM_REMOTE=bitcoin
8+
BITCOIN_UPSTREAM="${BITCOIN_UPSTREAM_REMOTE}/master"
9+
ELEMENTS_UPSTREAM_REMOTE=upstream
10+
ELEMENTS_UPSTREAM="${ELEMENTS_UPSTREAM_REMOTE}/master"
11+
12+
# Replace this with the location where we should put the fuzz test corpus
13+
BITCOIN_QA_ASSETS="${HOME}/.tmp/bitcoin/qa-assets"
14+
FUZZ_CORPUS="${BITCOIN_QA_ASSETS}/fuzz_seed_corpus/"
15+
mkdir -p "$(dirname ${BITCOIN_QA_ASSETS})"
16+
17+
# BEWARE: On some systems /tmp/ gets periodically cleaned, which may cause
18+
# random files from this directory to disappear based on timestamp, and
19+
# make git very confused
20+
WORKTREE="${HOME}/.tmp/elements-merge-worktree"
21+
mkdir -p "${HOME}/.tmp"
22+
23+
# These should be tuned to your machine; below values are for an 8-core
24+
# 16-thread macbook pro
25+
PARALLEL_BUILD=4 # passed to make -j
26+
PARALLEL_TEST=12 # passed to test_runner.py --jobs
27+
PARALLEL_FUZZ=8 # passed to test_runner.py -j when fuzzing
28+
29+
SKIP_MERGE=0
30+
DO_BUILD=1
31+
KEEP_GOING=1
32+
33+
if [[ "$1" == "setup" ]]; then
34+
echo "Setting up..."
35+
echo
36+
git config remote.upstream.url >/dev/null || remote add upstream "https://github.com/ElementsProject/elements.git"
37+
git config remote.bitcoin.url >/dev/null || git remote add bitcoin "https://github.com/bitcoin/bitcoin.git"
38+
if git worktree list --porcelain | grep --silent prunable; then
39+
echo "You have stale git worktrees, please either fix them or run 'git worktree prune'."
40+
exit 1
41+
fi
42+
git worktree list --porcelain | grep --silent "${WORKTREE}" || git worktree add "${WORKTREE}" --force --no-checkout --detach
43+
echo
44+
echo "Fetching all remotes..."
45+
echo
46+
git fetch --all
47+
echo
48+
#echo "Cloning fuzz test corpus..."
49+
#echo
50+
#if [[ ! -d "${BITCOIN_QA_ASSETS}" ]]; then
51+
# cd "$(dirname ${BITCOIN_QA_ASSETS})" && git clone https://github.com/bitcoin-core/qa-assets.git
52+
#fi
53+
#echo
54+
echo "Done! Remember to also check out merged-master, and push it back up when finished."
55+
exit 0
56+
elif [[ "$1" == "continue" ]]; then
57+
SKIP_MERGE=1
58+
elif [[ "$1" == "go" ]]; then
59+
true # this is the default, do nothing
60+
elif [[ "$1" == "list-only" ]]; then
61+
DO_BUILD=0
62+
elif [[ "$1" == "step" ]]; then
63+
KEEP_GOING=0
64+
elif [[ "$1" == "step-continue" ]]; then
65+
SKIP_MERGE=1
66+
KEEP_GOING=0
67+
else
68+
echo "Usage: $0 <setup|list-only|go|continue|step|step-continue>"
69+
echo " setup will configure your repository for the first run of this script"
70+
echo " list-only will simply list all the PRs yet to be done"
71+
echo " go will try to merge every PR, building/testing each"
72+
echo " continue assumes the first git-merge has already happened, and starts with building"
73+
echo " step will try to merge/build/test a single PR"
74+
echo " step-continue assumes the first git-merge has already happened, and will try to build/test a single PR"
75+
echo
76+
echo "Prior to use, please create a git worktree for the elements repo at:"
77+
echo " $WORKTREE"
78+
echo "Make sure it has an elements remote named '$ELEMENTS_UPSTREAM_REMOTE' and a bitcoin remote named '$BITCOIN_UPSTREAM_REMOTE'."
79+
echo "Make sure that your local branch '$BASE_ORIG' contains the integration"
80+
echo "branch you want to start from, and remember to push it up somewhere"
81+
echo "when you're done!"
82+
echo
83+
echo "You can also edit PARALLEL_{BUILD,TEST,FUZZ} in the script to tune for your machine."
84+
echo "And you can edit VERBOSE in the script to watch the build process."
85+
echo "(By default only the output of failing steps will be shown.)"
86+
exit 1
87+
fi
88+
89+
if [[ "$1" != "list-only" ]]; then
90+
if [[ -f "$WORKTREE/.git/MERGE_MSG" ]]; then
91+
echo "It looks like you're in the middle of a merge. Finish fixing"
92+
echo "things then run 'git commit' before running this program."
93+
exit 1
94+
fi
95+
fi
96+
97+
if [[ "$SKIP_MERGE" == "1" ]]; then
98+
# Rewind so the first loop iteration is the last one that we already merged.
99+
BASE="$BASE^1"
100+
fi
101+
102+
## Get full list of merges
103+
ELT_COMMITS=$(git -C "$WORKTREE" log "$ELEMENTS_UPSTREAM" --not $BASE --merges --first-parent --pretty='format:%ct %cI %h Elements %s')
104+
BTC_COMMITS=$(git -C "$WORKTREE" log "$BITCOIN_UPSTREAM" --not $BASE --merges --first-parent --pretty='format:%ct %cI %h Bitcoin %s')
105+
106+
#ELT_COMMITS=
107+
#BTC_COMMITS=$(git -C "$WORKTREE" log v0.21.0 --not $BASE --merges --first-parent --pretty='format:%ct %cI %h Bitcoin %s')
108+
109+
#play /home/apoelstra/games/Hover/sounds/mixed/hit_wall.wav 2>/dev/null ## play start sound
110+
111+
cd "$WORKTREE"
112+
113+
VERBOSE=1
114+
115+
quietly () {
116+
if [[ "$VERBOSE" == "1" ]]; then
117+
"$@"
118+
else
119+
chronic "$@"
120+
fi
121+
}
122+
123+
## Sort by unix timestamp and iterate over them
124+
#echo "$ELT_COMMITS" "$BTC_COMMITS" | sort -n -k1 | while read line
125+
echo "$ELT_COMMITS" | tac | while read line
126+
do
127+
echo
128+
echo "=-=-=-=-=-=-=-=-=-=-="
129+
echo
130+
131+
echo -e $line
132+
## Extract data and output what we're doing
133+
DATE=$(echo $line | cut -d ' ' -f 2)
134+
HASH=$(echo $line | cut -d ' ' -f 3)
135+
CHAIN=$(echo $line | cut -d ' ' -f 4)
136+
PR_ID=$(echo $line | cut -d ' ' -f 6 | tr -d :)
137+
PR_ID_ALT=$(echo $line | cut -d ' ' -f 8 | tr -d :)
138+
139+
if [[ "$PR_ID" == "pull" ]]; then
140+
PR_ID="${PR_ID_ALT}"
141+
fi
142+
echo -e "$CHAIN PR \e[37m$PR_ID \e[33m$HASH\e[0m on \e[32m$DATE\e[0m "
143+
144+
## Do it
145+
if [[ "$1" == "list-only" ]]; then
146+
continue
147+
fi
148+
149+
if [[ "$SKIP_MERGE" == "1" ]]; then
150+
echo -e "Continuing build of \e[37m$PR_ID\e[0m at $(date)"
151+
else
152+
echo -e "Start merge/build of \e[37m$PR_ID\e[0m at $(date)"
153+
git -C "$WORKTREE" merge $HASH --no-ff -m "Merge $HASH into merged_master ($CHAIN PR $PR_ID)"
154+
fi
155+
156+
if [[ "$DO_BUILD" == "1" ]]; then
157+
# Clean up
158+
echo "Cleaning up"
159+
# NB: this will fail the first time because there's not yet a makefile
160+
quietly make distclean || true
161+
quietly git -C "$WORKTREE" clean -xf
162+
echo "autogen & configure"
163+
quietly ./autogen.sh
164+
quietly ./configure --with-incompatible-bdb
165+
# The following is an expansion of `make check` that skips the libsecp
166+
# tests and also the benchmarks (though it does build them!)
167+
echo "Building"
168+
quietly make -j"$PARALLEL_BUILD" -k
169+
# quietly make -j1 check
170+
echo "Linting"
171+
quietly ./ci/lint/06_script.sh
172+
echo "Testing"
173+
quietly ./src/qt/test/test_elements-qt
174+
quietly ./src/test/test_bitcoin
175+
quietly ./src/bench/bench_bitcoin
176+
quietly ./test/util/bitcoin-util-test.py
177+
quietly ./test/util/rpcauth-test.py
178+
quietly make -C src/univalue/ check
179+
echo "Functional testing"
180+
quietly ./test/functional/test_runner.py --jobs="$PARALLEL_TEST"
181+
echo "Cleaning for fuzz"
182+
quietly make distclean || true
183+
quietly git -C "$WORKTREE" clean -xf
184+
echo "Building for fuzz"
185+
quietly ./autogen.sh
186+
# TODO turn on `,integer` after this rebase
187+
quietly ./configure --with-incompatible-bdb --enable-fuzz --with-sanitizers=address,fuzzer,undefined CC=clang CXX=clang++
188+
quietly make -j"$PARALLEL_BUILD" -k
189+
echo "Fuzzing"
190+
quietly ./test/fuzz/test_runner.py -j"$PARALLEL_FUZZ" "${FUZZ_CORPUS}"
191+
fi
192+
193+
if [[ "$KEEP_GOING" == "0" ]]; then
194+
exit 1
195+
fi
196+
197+
# bummer1.sh
198+
SKIP_MERGE=0
199+
done

0 commit comments

Comments
 (0)