Skip to content

Commit 06746c7

Browse files
committed
hardfork/build-and-test.sh: clean up CI run logic
1 parent 1afbd21 commit 06746c7

File tree

2 files changed

+47
-66
lines changed

2 files changed

+47
-66
lines changed

buildkite/src/Jobs/Test/HardForkTest.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ in Pipeline.build
2929
[ S.strictlyStart (S.contains "src")
3030
, S.exactly "buildkite/src/Jobs/Test/HardForkTest" "dhall"
3131
, S.strictlyStart (S.contains "scripts/hardfork")
32+
, S.strictlyStart (S.contains "scripts/mina-local-network")
3233
, S.strictlyStart (S.contains "nix")
3334
, S.exactly "flake" "nix"
3435
, S.exactly "flake" "lock"

scripts/hardfork/build-and-test.sh

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11
#!/usr/bin/env bash
22

33
# This scripts builds compatible and current branch with nix
4-
# It handles two cases differently:
5-
# - When given an $1 argument, it treats itself as being run in
6-
# Buildkite CI and $1 to be "fork" branch that needs to be built
7-
# - When it isn't given any arguments, it asusmes it is being
8-
# executed locally and builds code in $PWD as the fork branch
9-
#
10-
# When run locally, `compatible` branch is built in a temporary folder
11-
# (and fetched clean from Mina's repository). When run in CI,
12-
# `compatible` branch of git repo in $PWD is used to being the
13-
# compatible executable.
14-
#
15-
# In either case at the end of its execution this script leaves
16-
# current dir at the fork branch (in case of local run, it never
17-
# switches the branch with git) and nix builds put to `compatible-devnet`
18-
# and `fork-devnet` symlinks (located in $PWD).
19-
20-
set -exo pipefail
4+
# 0. Prepare environment if needed
5+
# 1. Build compatible as a prefork build;
6+
# 2. Build current branch(not compatible) as a postfork build;
7+
# 3. Build hardfork_test on current branch;
8+
# 4. Upload to nix cache
9+
# 5. Execute hardfork_test on them.
10+
11+
# Step 0. Prepare environment if needed
12+
set -eux -o pipefail
2113

2214
NIX_OPTS=( --accept-flake-config --experimental-features 'nix-command flakes' )
2315

24-
if [[ "$NIX_CACHE_NAR_SECRET" != "" ]]; then
16+
if [[ -n "${NIX_CACHE_NAR_SECRET:-}" ]]; then
2517
echo "$NIX_CACHE_NAR_SECRET" > /tmp/nix-cache-secret
2618
echo "Configuring the NAR signing secret"
2719
NIX_SECRET_KEY=/tmp/nix-cache-secret
2820
fi
2921

30-
if [[ "$NIX_CACHE_GCP_ID" != "" ]] && [[ "$NIX_CACHE_GCP_SECRET" != "" ]]; then
22+
if [[ -n "${NIX_CACHE_GCP_ID:-}" ]] && [[ -n "${NIX_CACHE_GCP_SECRET:-}" ]]; then
3123
echo "GCP uploading configured (for nix binaries)"
3224
cat <<'EOF'> /tmp/nix-post-build
3325
#!/bin/sh
@@ -42,26 +34,23 @@ EOF
4234
NIX_POST_BUILD_HOOK=/tmp/nix-post-build
4335
fi
4436

45-
if [[ "$NIX_POST_BUILD_HOOK" != "" ]]; then
37+
if [[ -n "${NIX_POST_BUILD_HOOK:-}" ]]; then
4638
NIX_OPTS+=( --post-build-hook "$NIX_POST_BUILD_HOOK" )
4739
fi
48-
if [[ "$NIX_SECRET_KEY" != "" ]]; then
40+
if [[ -n "${NIX_SECRET_KEY:-}" ]]; then
4941
NIX_OPTS+=( --secret-key-files "$NIX_SECRET_KEY" )
5042
fi
5143

52-
INIT_DIR="$PWD"
44+
pushd "$(git rev-parse --show-toplevel)"
5345
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5446

55-
if [[ $# -gt 0 ]]; then
56-
# Branch is specified, this is a CI run
57-
chown -R "${USER}" /workdir
58-
git config --global --add safe.directory /workdir
59-
git fetch
47+
if [ -n "${BUILDKITE:-}" ]; then
48+
# This is a CI run, ensure nix docker has everything what we want.
6049
nix-env -iA unstable.{curl,git-lfs,gnused,jq,python311}
6150

6251
python -m venv .venv
6352
source .venv/bin/activate
64-
pip install -r $INIT_DIR/scripts/mina-local-network/requirements.txt
53+
pip install -r scripts/mina-local-network/requirements.txt
6554

6655
# Manually patch zone infos, nix doesn't provide stdenv breaking janestreet's core
6756
zone_info=(/nix/store/*tzdata*/share/zoneinfo)
@@ -78,60 +67,51 @@ if [[ $# -gt 0 ]]; then
7867
fi
7968
fi
8069

81-
if [[ ! -L compatible-devnet ]]; then
82-
if [[ $# == 0 ]]; then
83-
compatible_build=$(mktemp --tmpdir -d mina-compatible-worktree.XXXXXXXXXX)
84-
git fetch origin compatible
85-
git worktree add "$compatible_build" origin/compatible
86-
cd "$compatible_build"
87-
else
88-
git checkout -f $1
89-
git checkout -f compatible
90-
git checkout -f $1 -- scripts/hardfork
91-
compatible_build="$INIT_DIR"
92-
fi
93-
git submodule sync --recursive
94-
git submodule update --init --recursive --depth 1
95-
nix "${NIX_OPTS[@]}" build "$compatible_build?submodules=1#devnet" --out-link "$INIT_DIR/compatible-devnet"
96-
if [[ $# == 0 ]]; then
97-
cd -
98-
rm -Rf "$compatible_build"
99-
fi
100-
fi
70+
# 1. Build compatible as a prefork build;
71+
git fetch origin compatible
72+
git checkout origin/compatible
73+
git submodule sync --recursive
74+
git submodule update --init --recursive --depth 1
75+
nix "${NIX_OPTS[@]}" build "$PWD?submodules=1#devnet" --out-link "prefork-devnet"
76+
77+
# 2. Build current branch(not compatible) as a postfork build;
78+
git checkout -
79+
git submodule sync --recursive
80+
git submodule update --init --recursive --depth 1
81+
nix "${NIX_OPTS[@]}" build "$PWD?submodules=1#devnet" --out-link "postfork-devnet"
10182

102-
if [[ $# -gt 0 ]]; then
103-
# Branch is specified, this is a CI run
104-
git checkout -f $1
105-
git submodule sync --recursive
106-
git submodule update --init --recursive --depth 1
107-
fi
108-
nix "${NIX_OPTS[@]}" build "$INIT_DIR?submodules=1#devnet" --out-link "$INIT_DIR/fork-devnet"
10983

110-
if [[ "$NIX_CACHE_GCP_ID" != "" ]] && [[ "$NIX_CACHE_GCP_SECRET" != "" ]]; then
84+
# 3. Build hardfork_test on current branch;
85+
nix "${NIX_OPTS[@]}" build "$PWD?submodules=1#hardfork_test" --out-link "hardfork_test"
86+
87+
# 4. Upload to nix cache
88+
89+
if [[ -n "${NIX_CACHE_GCP_ID:-}" ]] && [[ -n "${NIX_CACHE_GCP_SECRET:-}" ]]; then
11190
mkdir -p $HOME/.aws
11291
cat <<EOF> $HOME/.aws/credentials
11392
[default]
11493
aws_access_key_id=$NIX_CACHE_GCP_ID
11594
aws_secret_access_key=$NIX_CACHE_GCP_SECRET
11695
EOF
11796
118-
nix --experimental-features nix-command copy --to "s3://mina-nix-cache?endpoint=https://storage.googleapis.com" --stdin </tmp/nix-paths
97+
nix "${NIX_OPTS[@]}" copy \
98+
--to "s3://mina-nix-cache?endpoint=https://storage.googleapis.com" \
99+
--stdin </tmp/nix-paths
119100
fi
120101
121-
122-
nix "${NIX_OPTS[@]}" build "$INIT_DIR?submodules=1#hardfork_test" --out-link "$INIT_DIR/hardfork_test"
102+
# 5. Execute hardfork_test on them.
123103
124104
SLOT_TX_END=${SLOT_TX_END:-$((40))}
125105
SLOT_CHAIN_END=${SLOT_CHAIN_END:-$((SLOT_TX_END+5))}
126106
127-
echo "Running HF test with SLOT_TX_END=$SLOT_TX_END"
128-
129-
"$INIT_DIR/hardfork_test/bin/hardfork_test" \
130-
--main-mina-exe "$INIT_DIR/compatible-devnet/bin/mina" \
131-
--main-runtime-genesis-ledger "$INIT_DIR/compatible-devnet/bin/runtime_genesis_ledger" \
132-
--fork-mina-exe "$INIT_DIR/fork-devnet/bin/mina" \
133-
--fork-runtime-genesis-ledger "$INIT_DIR/fork-devnet/bin/runtime_genesis_ledger" \
107+
hardfork_test/bin/hardfork_test \
108+
--main-mina-exe prefork-devnet/bin/mina \
109+
--main-runtime-genesis-ledger prefork-devnet/bin/runtime_genesis_ledger \
110+
--fork-mina-exe postfork-devnet/bin/mina \
111+
--fork-runtime-genesis-ledger postfork-devnet/bin/runtime_genesis_ledger \
134112
--slot-tx-end "$SLOT_TX_END" \
135113
--slot-chain-end "$SLOT_CHAIN_END" \
136114
--script-dir "$SCRIPT_DIR" \
137115
&& echo "HF test completed successfully"
116+
117+
popd

0 commit comments

Comments
 (0)