Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/upload-private-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ jobs:
- name: Build private registry artifact
env:
PRIVATE_BASE_RPC_URLS: ${{ secrets.PRIVATE_BASE_RPC_URLS }}
PRIVATE_ROBINHOOD_RPC_URLS: ${{ secrets.PRIVATE_ROBINHOOD_RPC_URLS }}
run: |
set -euo pipefail

if [ -z "${PRIVATE_BASE_RPC_URLS}" ]; then
echo "PRIVATE_BASE_RPC_URLS secret is required" >&2
exit 1
fi
if [ -z "${PRIVATE_ROBINHOOD_RPC_URLS}" ]; then
echo "PRIVATE_ROBINHOOD_RPC_URLS secret is required" >&2
exit 1
fi

scripts/build-private-registry-artifact.sh \
--private-base-rpc-urls "${PRIVATE_BASE_RPC_URLS}" \
--private-robinhood-rpc-urls "${PRIVATE_ROBINHOOD_RPC_URLS}" \
--output "${RUNNER_TEMP}/private-registry-artifact.b64"

registry_artifact_b64="$(cat "${RUNNER_TEMP}/private-registry-artifact.b64")"
Expand Down
84 changes: 63 additions & 21 deletions scripts/build-private-registry-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ settings_path="settings.yaml"
registry_path="registry"
output_path=""
settings_output_path=""
private_rpc_csv=""
private_rpc_urls=()
private_base_rpc_csv=""
private_base_rpc_urls=()
private_robinhood_rpc_csv=""
private_robinhood_rpc_urls=()
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

usage() {
Expand All @@ -19,7 +21,10 @@ Options:
--settings PATH settings YAML path (default: settings.yaml)
--registry PATH registry path (default: registry)
--private-base-rpc-url URL private Base RPC URL; can be passed more than once
--private-base-rpc-urls URLS comma-separated private Base RPC URLs
--private-base-rpc-urls URLS comma- or newline-separated private Base RPC URLs
--private-robinhood-rpc-url URL private Robinhood RPC URL; can be passed more than once
--private-robinhood-rpc-urls URLS
comma- or newline-separated private Robinhood RPC URLs
--output PATH write registry artifact base64 to PATH instead of stdout
--settings-output PATH write updated settings YAML to PATH for inspection
-h, --help show this help
Expand All @@ -38,11 +43,19 @@ trim() {
printf '%s' "$value"
}

add_private_url() {
add_private_base_url() {
local url
url="$(trim "$1")"
if [[ -n "$url" ]]; then
private_rpc_urls+=("$url")
private_base_rpc_urls+=("$url")
fi
}

add_private_robinhood_url() {
local url
url="$(trim "$1")"
if [[ -n "$url" ]]; then
private_robinhood_rpc_urls+=("$url")
fi
}

Expand All @@ -60,12 +73,22 @@ while [[ $# -gt 0 ]]; do
;;
--private-base-rpc-url)
[[ $# -ge 2 ]] || die "--private-base-rpc-url requires a URL"
add_private_url "$2"
add_private_base_url "$2"
shift 2
;;
--private-base-rpc-urls)
[[ $# -ge 2 ]] || die "--private-base-rpc-urls requires a comma-separated list"
private_rpc_csv="$2"
private_base_rpc_csv="$2"
shift 2
;;
--private-robinhood-rpc-url)
[[ $# -ge 2 ]] || die "--private-robinhood-rpc-url requires a URL"
add_private_robinhood_url "$2"
shift 2
;;
--private-robinhood-rpc-urls)
[[ $# -ge 2 ]] || die "--private-robinhood-rpc-urls requires a comma-separated list"
private_robinhood_rpc_csv="$2"
shift 2
;;
--output)
Expand All @@ -88,37 +111,56 @@ while [[ $# -gt 0 ]]; do
esac
done

if [[ -n "$private_rpc_csv" ]]; then
IFS=',' read -r -a csv_urls <<< "$private_rpc_csv"
for url in "${csv_urls[@]}"; do
add_private_url "$url"
done
if [[ -n "$private_base_rpc_csv" ]]; then
while IFS= read -r url; do
add_private_base_url "$url"
done <<< "${private_base_rpc_csv//,/$'\n'}"
fi

if [[ -n "$private_robinhood_rpc_csv" ]]; then
while IFS= read -r url; do
add_private_robinhood_url "$url"
done <<< "${private_robinhood_rpc_csv//,/$'\n'}"
fi

[[ -f "$settings_path" ]] || die "settings file not found: $settings_path"
[[ -f "$registry_path" ]] || die "registry file not found: $registry_path"
[[ ${#private_rpc_urls[@]} -gt 0 ]] || die "at least one private Base RPC URL is required"
[[ ${#private_base_rpc_urls[@]} -gt 0 ]] || die "at least one private Base RPC URL is required"
[[ ${#private_robinhood_rpc_urls[@]} -gt 0 ]] || die "at least one private Robinhood RPC URL is required"

work_dir="$(mktemp -d)"
cleanup() {
rm -rf "$work_dir"
}
trap cleanup EXIT

private_urls_file="$work_dir/private-rpc-urls.txt"
private_base_urls_file="$work_dir/private-base-rpc-urls.txt"
private_robinhood_urls_file="$work_dir/private-robinhood-rpc-urls.txt"
base_settings_file="$work_dir/settings-base-rpcs.yaml"
updated_settings_file="$work_dir/settings.yaml"
final_registry_file="$work_dir/registry"

touch "$private_urls_file"
for url in "${private_rpc_urls[@]}"; do
if ! grep -Fxq "$url" "$private_urls_file"; then
printf '%s\n' "$url" >> "$private_urls_file"
touch "$private_base_urls_file" "$private_robinhood_urls_file"
for url in "${private_base_rpc_urls[@]}"; do
if ! grep -Fxq "$url" "$private_base_urls_file"; then
printf '%s\n' "$url" >> "$private_base_urls_file"
fi
done
for url in "${private_robinhood_rpc_urls[@]}"; do
if ! grep -Fxq "$url" "$private_robinhood_urls_file"; then
printf '%s\n' "$url" >> "$private_robinhood_urls_file"
fi
done

awk -v target_network="base" \
-v private_urls_file="$private_base_urls_file" \
-f "$script_dir/prepend-network-rpcs.awk" \
"$settings_path" > "$base_settings_file"

awk -v private_urls_file="$private_urls_file" \
-f "$script_dir/prepend-base-rpcs.awk" \
"$settings_path" > "$updated_settings_file"
awk -v target_network="robinhood" \
-v private_urls_file="$private_robinhood_urls_file" \
-f "$script_dir/prepend-network-rpcs.awk" \
"$base_settings_file" > "$updated_settings_file"

if [[ -n "$settings_output_path" ]]; then
mkdir -p "$(dirname "$settings_output_path")"
Expand Down
18 changes: 11 additions & 7 deletions scripts/prepend-base-rpcs.awk → scripts/prepend-network-rpcs.awk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function quote_yaml(value) {
}

BEGIN {
if (target_network == "") {
print "target_network is required" > "/dev/stderr"
exit 1
}
while ((getline url < private_urls_file) > 0) {
add_url(url)
}
Expand All @@ -80,25 +84,25 @@ END {

networks_end = block_end(networks_idx, 0)
for (idx = networks_idx + 1; idx < networks_end; idx++) {
if (key_at(lines[idx], "base", 2)) {
base_idx = idx
if (key_at(lines[idx], target_network, 2)) {
network_idx = idx
break
}
}
if (!base_idx) {
print "could not find networks.base key" > "/dev/stderr"
if (!network_idx) {
print "could not find networks." target_network " key" > "/dev/stderr"
exit 1
}

base_end = block_end(base_idx, 2)
for (idx = base_idx + 1; idx < base_end; idx++) {
network_end = block_end(network_idx, 2)
for (idx = network_idx + 1; idx < network_end; idx++) {
if (key_at(lines[idx], "rpcs", 4)) {
rpcs_idx = idx
break
}
}
if (!rpcs_idx) {
print "could not find networks.base.rpcs key" > "/dev/stderr"
print "could not find networks." target_network ".rpcs key" > "/dev/stderr"
exit 1
}

Expand Down
Loading