Skip to content

Commit 0592b95

Browse files
committed
refactor(ci): unify node build logic and optimize space
- Remove `.github/nix_override_cardano_node.sh` and replace with `.github/source_cardano_node.sh` for consistent cardano-node binary sourcing and building. - Refactor `node_upgrade.sh` and `regression.sh` to use new node build functions, simplify environment variable handling, and optimize disk usage in CI. - Update dbsync build and path logic in `.github/source_dbsync.sh` for consistency and workspace cleanliness. - Add step to maximize build space in GitHub Actions workflows. - Switch from `venv` to `testenv` for test environments in flake.nix, and clarify shell environments for development and testing. - Update flake.lock to latest cardano-node revision.
1 parent e9c9ffc commit 0592b95

11 files changed

+244
-175
lines changed

.github/nix_override_cardano_node.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/node_upgrade.sh

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
# BASE_TAR_URL - URL of a tarball with binaries for base revision
66
# BASE_REVISION - revision of cardano-node to upgrade from (alternative to BASE_TAR_URL)
77
# UPGRADE_REVISION - revision of cardano-node to upgrade to
8+
# UPGRADE_CLI_REVISION - revision of cardano-cli to upgrade to (optional)
89

910
set -Eeuo pipefail
1011
trap 'echo "Error at line $LINENO"' ERR
1112

12-
if [[ -z "${BASE_TAR_URL:-""}" && -z "${BASE_REVISION:-""}" ]]; then
13+
if [[ -z "${BASE_TAR_URL:-}" && -z "${BASE_REVISION:-}" ]]; then
1314
echo "BASE_TAR_URL or BASE_REVISION must be set"
1415
exit 1
1516
fi
1617

18+
if [ -n "${GITHUB_ACTIONS:-}" ]; then
19+
CI_OPTIMIZE_SPACE="${CI_OPTIMIZE_SPACE:-"true"}"
20+
fi
21+
1722
nix --version
1823
df -h .
1924

@@ -69,31 +74,52 @@ echo "::group::Nix env setup step1"
6974
printf "start: %(%H:%M:%S)T\n" -1
7075

7176
# shellcheck disable=SC1090,SC1091
72-
. .github/nix_override_cardano_node.sh
77+
. .github/source_cardano_node.sh
7378

74-
# update cardano-node to specified revision
79+
# Prepare cardano-node for the base revision.
7580
# If BASE_TAR_URL is set, instead of using nix, download and extract binaries for base revision
76-
# from a published tarball to save disk space, and use the same nix env as will be used for
77-
# UPGRADE_REVISION. We are running out of space on GitHub Actions runners.
78-
if [[ -z "${BASE_TAR_URL:-""}" && -n "${BASE_REVISION:-""}" ]]; then
79-
NODE_OVERRIDE=$(node_override "${BASE_REVISION}")
80-
elif [ -n "${UPGRADE_REVISION:-""}" ]; then
81-
NODE_OVERRIDE=$(node_override "$UPGRADE_REVISION")
82-
else
83-
NODE_OVERRIDE=$(node_override)
81+
# from a published tarball.
82+
PATH_PREPEND_BASE=""
83+
if [ -z "${BASE_TAR_URL:-}" ]; then
84+
if [ -z "${BASE_REVISION:-}" ]; then
85+
echo "Either BASE_TAR_URL or BASE_REVISION must be set"
86+
exit 1
87+
fi
88+
cardano_bins_build_all "$BASE_REVISION" "" "_base"
89+
PATH_PREPEND_BASE="$(cardano_bins_print_path_prepend "" "_base")"
90+
fi
91+
export PATH_PREPEND_BASE
92+
93+
# Prepare cardano-node for the upgrade revision
94+
cardano_bins_build_all "${UPGRADE_REVISION:-"master"}" "${UPGRADE_CLI_REVISION:-}" "_upgrade"
95+
PATH_PREPEND_UPGRADE="$(cardano_bins_print_path_prepend "${UPGRADE_CLI_REVISION:-}" "_upgrade")"
96+
export PATH_PREPEND_UPGRADE
97+
98+
# Prepare cardano-cli for the upgrade revision if UPGRADE_CLI_REVISION is set
99+
if [ -n "${UPGRADE_CLI_REVISION:-}" ]; then
100+
export CARDANO_CLI_REV="$UPGRADE_CLI_REVISION"
101+
# shellcheck disable=SC1090,SC1091
102+
. .github/source_cardano_cli.sh
103+
cardano_cli_build "$UPGRADE_CLI_REVISION" "_upgrade"
104+
PATH_PREPEND_UPGRADE="$(cardano_cli_print_path_prepend "_upgrade")${PATH_PREPEND_UPGRADE}"
105+
export PATH_PREPEND_UPGRADE
106+
fi
107+
108+
# optimize nix store space if requested
109+
if [ "${CI_OPTIMIZE_SPACE:-"false"}" != "false" ]; then
110+
nix store gc || :
84111
fi
85112

86-
# shellcheck disable=SC2086
87-
nix flake update --accept-flake-config $NODE_OVERRIDE
88113
# shellcheck disable=SC2016
89-
nix develop --accept-flake-config .#venv --command bash -c '
114+
nix develop --accept-flake-config .#testenv --command bash -c '
90115
set -euo pipefail
91-
: > "$WORKDIR/.nix_step1"
92-
echo "::endgroup::" # end group for "Nix env setup step1"
116+
: > "$WORKDIR/.nix_setup"
117+
echo "::endgroup::" # end group for "Nix env setup"
93118

94119
echo "::group::Python venv setup step1"
95120
printf "start: %(%H:%M:%S)T\n" -1
96121
. .github/setup_venv.sh clean
122+
export PATH="${PATH_PREPEND_BASE}${PATH}"
97123
echo "::endgroup::" # end group for "Python venv setup step1"
98124

99125
echo "::group::🧪 Testrun Step1"
@@ -102,40 +128,14 @@ nix develop --accept-flake-config .#venv --command bash -c '
102128
# prepare scripts for stating cluster instance, start cluster instance, run smoke tests
103129
retval=0
104130
./.github/node_upgrade_pytest.sh step1 || retval="$?"
105-
exit "$retval"
106-
' || retval="$?"
107-
108-
if [ ! -e "$WORKDIR/.nix_step1" ]; then
109-
echo "Nix env setup failed, exiting"
110-
exit 1
111-
fi
112-
113-
# retval 0 == all tests passed; 1 == some tests failed; > 1 == some runtime error and we don't want to continue
114-
[ "$retval" -le 1 ] || exit "$retval"
115-
116-
echo "::endgroup::" # end group for "Testrun Step1"
117-
118-
echo "::group::Nix env setup steps 2 & 3"
119-
printf "start: %(%H:%M:%S)T\n" -1
120-
121-
# update cardano-node to specified branch and/or revision, or to the latest available revision
122-
if [ -n "${UPGRADE_REVISION:-""}" ]; then
123-
NODE_OVERRIDE=$(node_override "$UPGRADE_REVISION")
124-
else
125-
NODE_OVERRIDE=$(node_override)
126-
fi
127-
128-
# shellcheck disable=SC2086
129-
nix flake update --accept-flake-config $NODE_OVERRIDE
130-
# shellcheck disable=SC2016
131-
nix develop --accept-flake-config .#venv --command bash -c '
132-
set -euo pipefail
133-
: > "$WORKDIR/.nix_step2"
134-
echo "::endgroup::" # end group for "Nix env setup steps 2 & 3"
131+
# retval 0 == all tests passed; 1 == some tests failed; > 1 == some runtime error and we do not want to continue
132+
[ "$retval" -le 1 ] || exit "$retval"
133+
echo "::endgroup::" # end group for "Testrun Step1"
135134

136135
echo "::group::Python venv setup steps 2 & 3"
137136
printf "start: %(%H:%M:%S)T\n" -1
138137
. .github/setup_venv.sh clean
138+
export PATH="${PATH_PREPEND_UPGRADE}${PATH}"
139139
echo "::endgroup::" # end group for "Python venv setup steps 2 & 3"
140140

141141
echo "::group::🧪 Testrun Step2"
@@ -144,27 +144,25 @@ nix develop --accept-flake-config .#venv --command bash -c '
144144
# update cluster nodes, run smoke tests
145145
retval=0
146146
./.github/node_upgrade_pytest.sh step2 || retval="$?"
147-
# retval 0 == all tests passed; 1 == some tests failed; > 1 == some runtime error and we dont want to continue
148147
[ "$retval" -le 1 ] || exit "$retval"
149148
echo "::endgroup::" # end group for "Testrun Step2"
150149

151150
echo "::group::🧪 Testrun Step3"
152151
printf "start: %(%H:%M:%S)T\n" -1
153152
df -h .
154-
# update to Conway, run smoke tests
153+
# update the rest of cluster nodes, run smoke tests
155154
retval=0
156155
./.github/node_upgrade_pytest.sh step3 || retval="$?"
157-
df -h .
158156
echo "::endgroup::" # end group for "Testrun Step3"
159157

160158
echo "::group::Teardown cluster & collect artifacts"
161159
printf "start: %(%H:%M:%S)T\n" -1
162-
# teardown cluster
160+
df -h .
163161
./.github/node_upgrade_pytest.sh finish || :
164162
exit $retval
165163
' || retval="$?"
166164
167-
if [ ! -e "$WORKDIR/.nix_step2" ]; then
165+
if [ ! -e "$WORKDIR/.nix_setup" ]; then
168166
echo "Nix env setup failed, exiting"
169167
exit 1
170168
fi
@@ -175,7 +173,7 @@ fi
175173
_cleanup
176174
177175
# prepare artifacts for upload in GitHub Actions
178-
if [ -n "${GITHUB_ACTIONS:-""}" ]; then
176+
if [ -n "${GITHUB_ACTIONS:-}" ]; then
179177
# save testing artifacts
180178
./.github/save_artifacts.sh
181179

.github/node_upgrade_pytest.sh

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ elif [ "$1" = "step2" ]; then
114114
NETWORK_MAGIC="$(jq '.networkMagic' "$STATE_CLUSTER/shelley/genesis.json")"
115115
export NETWORK_MAGIC
116116

117-
# Setup `cardano-cli` binary
118-
if [ -n "${UPGRADE_CLI_REVISION:-""}" ]; then
119-
export CARDANO_CLI_REV="$UPGRADE_CLI_REVISION"
120-
# shellcheck disable=SC1090,SC1091
121-
. .github/source_cardano_cli.sh
122-
export PATH="$WORKDIR/cardano-cli-build/bin":"$PATH"
123-
fi
124-
125117
# add binaries saved in step1 to the PATH
126118
export PATH="${STEP1_BIN}:${PATH}"
127119

@@ -278,17 +270,6 @@ elif [ "$1" = "step3" ]; then
278270
NETWORK_MAGIC="$(jq '.networkMagic' "$STATE_CLUSTER/shelley/genesis.json")"
279271
export NETWORK_MAGIC
280272

281-
# Setup `cardano-cli` binary
282-
if [ -n "${UPGRADE_CLI_REVISION:-""}" ]; then
283-
export CARDANO_CLI_REV="$UPGRADE_CLI_REVISION"
284-
# the cardano-cli binary is already built in step2
285-
if [ ! -e "$WORKDIR/cardano-cli-build/bin/cardano-cli" ]; then
286-
echo "Failed to find the requested 'cardano-cli' binary" >&2
287-
exit 6
288-
fi
289-
export PATH="$WORKDIR/cardano-cli-build/bin":"$PATH"
290-
fi
291-
292273
# generate config and topology files for p2p mode
293274
CARDANO_NODE_SOCKET_PATH="$WORKDIR/dry_p2p/state-cluster0/bft1.socket" \
294275
DRY_RUN=1 \

0 commit comments

Comments
 (0)