Skip to content

Commit fb7a3d9

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

File tree

2 files changed

+44
-65
lines changed

2 files changed

+44
-65
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: 43 additions & 65 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,24 @@ 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
47+
if [ -n "${BUILDKITE:-}" ]; then
48+
# This is a CI run, ensure nix docker has everything what we want.
5949
git fetch
6050
nix-env -iA unstable.{curl,git-lfs,gnused,jq,python311}
6151

6252
python -m venv .venv
6353
source .venv/bin/activate
64-
pip install -r $INIT_DIR/scripts/mina-local-network/requirements.txt
54+
pip install -r scripts/mina-local-network/requirements.txt
6555

6656
# Manually patch zone infos, nix doesn't provide stdenv breaking janestreet's core
6757
zone_info=(/nix/store/*tzdata*/share/zoneinfo)
@@ -78,60 +68,48 @@ if [[ $# -gt 0 ]]; then
7868
fi
7969
fi
8070

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
71+
# 1. Build compatible as a prefork build;
72+
git fetch origin compatible
73+
git checkout origin/compatible
74+
nix "${NIX_OPTS[@]}" build "$PWD?submodules=1#devnet" --out-link "prefork-devnet"
75+
git checkout -
10176

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"
10977

110-
if [[ "$NIX_CACHE_GCP_ID" != "" ]] && [[ "$NIX_CACHE_GCP_SECRET" != "" ]]; then
78+
# 2. Build current branch(not compatible) as a postfork build;
79+
nix "${NIX_OPTS[@]}" build "$PWD?submodules=1#devnet" --out-link "postfork-devnet"
80+
81+
82+
# 3. Build hardfork_test on current branch;
83+
nix "${NIX_OPTS[@]}" build "$PWD?submodules=1#hardfork_test" --out-link "hardfork_test"
84+
85+
# 4. Upload to nix cache
86+
87+
if [[ -n "${NIX_CACHE_GCP_ID:-}" ]] && [[ -n "${NIX_CACHE_GCP_SECRET:-}" ]]; then
11188
mkdir -p $HOME/.aws
11289
cat <<EOF> $HOME/.aws/credentials
11390
[default]
11491
aws_access_key_id=$NIX_CACHE_GCP_ID
11592
aws_secret_access_key=$NIX_CACHE_GCP_SECRET
11693
EOF
11794
118-
nix --experimental-features nix-command copy --to "s3://mina-nix-cache?endpoint=https://storage.googleapis.com" --stdin </tmp/nix-paths
95+
nix "${NIX_OPTS[@]}" nix-command copy \
96+
--to "s3://mina-nix-cache?endpoint=https://storage.googleapis.com" \
97+
--stdin </tmp/nix-paths
11998
fi
12099
121-
122-
nix "${NIX_OPTS[@]}" build "$INIT_DIR?submodules=1#hardfork_test" --out-link "$INIT_DIR/hardfork_test"
100+
# 5. Execute hardfork_test on them.
123101
124102
SLOT_TX_END=${SLOT_TX_END:-$((40))}
125103
SLOT_CHAIN_END=${SLOT_CHAIN_END:-$((SLOT_TX_END+5))}
126104
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" \
105+
hardfork_test/bin/hardfork_test \
106+
--main-mina-exe prefork-devnet/bin/mina \
107+
--main-runtime-genesis-ledger prefork-devnet/bin/runtime_genesis_ledger \
108+
--fork-mina-exe postfork-devnet/bin/mina \
109+
--fork-runtime-genesis-ledger postfork-devnet/bin/runtime_genesis_ledger \
134110
--slot-tx-end "$SLOT_TX_END" \
135111
--slot-chain-end "$SLOT_CHAIN_END" \
136112
--script-dir "$SCRIPT_DIR" \
137113
&& echo "HF test completed successfully"
114+
115+
popd

0 commit comments

Comments
 (0)