Skip to content
Closed
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
131 changes: 131 additions & 0 deletions scripts/load-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/bin/bash
# Load versions for tools from either a tutorial's versions.yml or the repo root versions.yml
# Exports: RUST_VERSION, OMNI_NODE_VERSION, CHAIN_SPEC_BUILDER_VERSION

set -e

# Detect repo root from this script's location
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)

# Inputs (optional):
# - TUTORIAL_DIR: absolute path to tutorial directory (containing versions.yml)
# - TUTORIAL_KEY: key in root versions.yml for per-tutorial overrides (e.g., zero_to_hero)

_parse_flat_yaml() {
# Very simple YAML parser for flat key: value pairs (no nesting)
# Args: file_path, key
local file_path="$1"; shift
local key="$1"; shift
awk -v k="$key" '
BEGIN { FS=":" }
/^[[:space:]]*#/ { next } # skip comments
NF==0 { next } # skip empty
{
# capture lines like: key: value or key: "value"
gsub(/^[[:space:]]+|[[:space:]]+$/, "", $1)
if ($1 == k) {
sub(/^[^:]*:[[:space:]]*/, "", $0)
# trim quotes and whitespace
gsub(/^[\"\'\s]+|[\"\'\s]+$/, "", $0)
print $0
exit 0
}
}
' "$file_path"
}

_extract_block_value() {
# Extract a value for a subkey inside a top-level block in root versions.yml
# Args: file_path, block_key (e.g., zero_to_hero), sub_key (e.g., rust)
local file_path="$1"; shift
local block_key="$1"; shift
local sub_key="$1"; shift
awk -v block="$block_key" -v subk="$sub_key" '
/^[[:space:]]*#/ { next }
/^\s*$/ { next }
{
# Enter block when line is exactly: block:
if ($0 ~ "^" block ":[[:space:]]*$") { in_block=1; next }
# Leave block when a new top-level key is encountered
if ($0 ~ /^[^[:space:]].*:[[:space:]]*$/ && $0 !~ "^" block ":[[:space:]]*$") { in_block=0 }
if (in_block==1) {
# lines inside block: two or more spaces then key: value
if ($0 ~ /^[[:space:]]{2,}[^[:space:]]+:[[:space:]]*.+$/) {
line=$0
sub(/^\s+/, "", line)
split(line, parts, ":")
key=parts[1]
gsub(/^\s+|\s+$/, "", key)
if (key == subk) {
val=line
sub(/^[^:]*:[[:space:]]*/, "", val)
gsub(/^[\"\'\s]+|[\"\'\s]+$/, "", val)
print val
exit 0
}
}
}
}
' "$file_path"
}

load_versions() {
local tutorial_dir="${TUTORIAL_DIR:-}"
local tutorial_key="${TUTORIAL_KEY:-}"

if [[ -n "$tutorial_dir" && -f "$tutorial_dir/versions.yml" ]]; then
# Prefer tutorial-local versions.yml (flat keys)
local rust=$(_parse_flat_yaml "$tutorial_dir/versions.yml" rust)
local omni=$(_parse_flat_yaml "$tutorial_dir/versions.yml" polkadot_omni_node)
local csb=$(_parse_flat_yaml "$tutorial_dir/versions.yml" chain_spec_builder)
if [[ -n "$rust" ]]; then export RUST_VERSION="$rust"; fi
if [[ -n "$omni" ]]; then export OMNI_NODE_VERSION="$omni"; fi
if [[ -n "$csb" ]]; then export CHAIN_SPEC_BUILDER_VERSION="$csb"; fi
return 0
fi

# Fallback to root versions.yml
local root_file="$REPO_ROOT/versions.yml"
if [[ ! -f "$root_file" ]]; then
echo "versions.yml not found at $REPO_ROOT" >&2
return 1
fi

# Defaults under versions:
local def_rust=$(_extract_block_value "$root_file" versions rust)
local def_omni=$(_extract_block_value "$root_file" versions polkadot_omni_node)
local def_csb=$(_extract_block_value "$root_file" versions chain_spec_builder)

export RUST_VERSION="$def_rust"
export OMNI_NODE_VERSION="$def_omni"
export CHAIN_SPEC_BUILDER_VERSION="$def_csb"

# Optional overrides by tutorial key
if [[ -z "$tutorial_key" && -n "$tutorial_dir" ]]; then
# Derive key from dir name: replace dashes with underscores
local slug
slug=$(basename "$tutorial_dir")
tutorial_key=${slug//-/_}
fi

if [[ -n "$tutorial_key" ]]; then
local ov_rust=$(_extract_block_value "$root_file" "$tutorial_key" rust)
local ov_omni=$(_extract_block_value "$root_file" "$tutorial_key" polkadot_omni_node)
local ov_csb=$(_extract_block_value "$root_file" "$tutorial_key" chain_spec_builder)
if [[ -n "$ov_rust" ]]; then export RUST_VERSION="$ov_rust"; fi
if [[ -n "$ov_omni" ]]; then export OMNI_NODE_VERSION="$ov_omni"; fi
if [[ -n "$ov_csb" ]]; then export CHAIN_SPEC_BUILDER_VERSION="$ov_csb"; fi
fi
}

# If the script is sourced, export variables; if executed, print them JSON-ish
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
load_versions
echo "RUST_VERSION=$RUST_VERSION"
echo "OMNI_NODE_VERSION=$OMNI_NODE_VERSION"
echo "CHAIN_SPEC_BUILDER_VERSION=$CHAIN_SPEC_BUILDER_VERSION"
else
load_versions
fi


45 changes: 45 additions & 0 deletions scripts/prepare-node-for-tutorial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# Build kitchensink-parachain and generate chain spec for a tutorial
# Usage: scripts/prepare-node-for-tutorial.sh <tutorial-slug>

set -euo pipefail

if [[ $# -lt 1 ]]; then
echo "Usage: $0 <tutorial-slug>" >&2
exit 2
fi

SLUG="$1"
REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd)
TUTORIAL_DIR="$REPO_ROOT/tutorials/$SLUG"

if [[ ! -d "$TUTORIAL_DIR" ]]; then
echo "Tutorial directory not found: $TUTORIAL_DIR" >&2
exit 3
fi

export TUTORIAL_DIR
source "$REPO_ROOT/scripts/load-versions.sh"

echo "Preparing node for tutorial '$SLUG'"
echo "Using Rust ${RUST_VERSION}"

# Ensure rust toolchain and targets
pushd "$TUTORIAL_DIR/scripts" >/dev/null
bash ./setup-rust.sh
popd >/dev/null

# Build kitchensink-parachain runtime
pushd "$REPO_ROOT/kitchensink-parachain" >/dev/null
echo "Building kitchensink-parachain runtime..."
cargo build --release
popd >/dev/null

# Generate chain spec into kitchensink-parachain/chain_spec.json
pushd "$TUTORIAL_DIR/scripts" >/dev/null
bash ./generate-chain-spec.sh
popd >/dev/null

echo "Node preparation completed for '$SLUG'"


44 changes: 44 additions & 0 deletions scripts/setup-tutorial-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Setup environment for a given tutorial using its versions.yml
# Usage: scripts/setup-tutorial-env.sh <tutorial-slug>

set -euo pipefail

if [[ $# -lt 1 ]]; then
echo "Usage: $0 <tutorial-slug>" >&2
exit 2
fi

SLUG="$1"
REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd)
TUTORIAL_DIR="$REPO_ROOT/tutorials/$SLUG"

if [[ ! -d "$TUTORIAL_DIR" ]]; then
echo "Tutorial directory not found: $TUTORIAL_DIR" >&2
exit 3
fi

# Load versions with preference to tutorial-local versions.yml
export TUTORIAL_DIR
source "$REPO_ROOT/scripts/load-versions.sh"

echo "Setting up tutorial '$SLUG' with versions:" \
"RUST=${RUST_VERSION}, OMNI=${OMNI_NODE_VERSION}, CSB=${CHAIN_SPEC_BUILDER_VERSION}"

# Run tutorial-specific installers
pushd "$TUTORIAL_DIR/scripts" >/dev/null

echo "Installing Rust toolchain..."
bash ./setup-rust.sh

echo "Installing chain-spec-builder..."
bash ./install-chain-spec-builder.sh

echo "Installing polkadot-omni-node..."
bash ./install-omni-node.sh

popd >/dev/null

echo "Environment setup completed for '$SLUG'"


37 changes: 18 additions & 19 deletions tutorials/zero-to-hero/scripts/generate-chain-spec.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#!/bin/bash
# Chain Specification Generation Script
# This script generates a development chain specification for the parachain

set -e

PARA_ID="1000"
RELAY_CHAIN="paseo"
RUNTIME_PATH="./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm"
# Load versions and work under kitchensink-parachain
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR"/../../.. && pwd)
TUTORIAL_DIR=$(cd "$SCRIPT_DIR"/.. && pwd)
source "$REPO_ROOT/scripts/load-versions.sh"
cd "$REPO_ROOT/kitchensink-parachain"

PARA_ID="${PARA_ID:-1000}"
RELAY_CHAIN="${RELAY_CHAIN:-paseo}"
RUNTIME_PATH="${RUNTIME_PATH:-./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm}"

echo "⛓️ Generating chain specification..."
echo "📋 Configuration:"
echo " - Para ID: 1000"
echo " - Relay Chain: paseo"
echo " - Runtime: ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm"
echo " - Para ID: ${PARA_ID}"
echo " - Relay Chain: ${RELAY_CHAIN}"
echo " - Runtime: ${RUNTIME_PATH}"

# Check if runtime exists
if [ ! -f "./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm" ]; then
echo "❌ Runtime WASM file not found: ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm"
if [ ! -f "${RUNTIME_PATH}" ]; then
echo "❌ Runtime WASM file not found: ${RUNTIME_PATH}"
echo "💡 Make sure you have built the parachain runtime first"
echo "💡 Try running: cargo build --release"
exit 1
fi

# Generate chain specification
chain-spec-builder create \
-t development \
--relay-chain paseo \
--para-id 1000 \
--runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm \
--relay-chain "${RELAY_CHAIN}" \
--para-id "${PARA_ID}" \
--runtime "${RUNTIME_PATH}" \
named-preset development

# Verify chain spec was created
if [ ! -f "chain_spec.json" ]; then
echo "❌ Chain specification generation failed"
exit 1
Expand All @@ -40,13 +42,10 @@ echo "✅ Chain specification generated successfully!"
echo "📄 Output file: chain_spec.json"
echo "📊 File size: $(du -h chain_spec.json | cut -f1)"

# Validate JSON
if command -v jq >/dev/null 2>&1; then
echo "🔍 Validating JSON structure..."
if jq empty chain_spec.json; then
echo "✅ Chain specification is valid JSON"

# Extract key information
CHAIN_NAME=$(jq -r '.name // "unknown"' chain_spec.json)
echo "📋 Chain Name: $CHAIN_NAME"
else
Expand Down
16 changes: 8 additions & 8 deletions tutorials/zero-to-hero/scripts/install-chain-spec-builder.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/bash
# Chain Spec Builder Installation Script
# This script installs the staging-chain-spec-builder tool

set -e

CHAIN_SPEC_VERSION="10.0.0"
# Load versions
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR"/../../.. && pwd)
TUTORIAL_DIR=$(cd "$SCRIPT_DIR"/.. && pwd)
source "$REPO_ROOT/scripts/load-versions.sh"

echo "🔧 Installing staging-chain-spec-builder 10.0.0..."
echo "🔧 Installing staging-chain-spec-builder ${CHAIN_SPEC_BUILDER_VERSION}..."

# Install chain-spec-builder with locked dependencies
cargo install --locked [email protected]
cargo install --locked staging-chain-spec-builder@"${CHAIN_SPEC_BUILDER_VERSION}"

echo "✅ Chain spec builder installation completed!"
echo "📋 Installed version: 10.0.0"
echo "📋 Installed version: ${CHAIN_SPEC_BUILDER_VERSION}"

# Verify installation
echo "🔍 Verifying installation..."
chain-spec-builder --version
18 changes: 9 additions & 9 deletions tutorials/zero-to-hero/scripts/install-omni-node.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/bash
# Omni Node Installation Script
# This script installs the polkadot-omni-node

# Omni Node Installation Script
set -e

OMNI_NODE_VERSION="0.5.0"
# Load versions
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR"/../../.. && pwd)
TUTORIAL_DIR=$(cd "$SCRIPT_DIR"/.. && pwd)
source "$REPO_ROOT/scripts/load-versions.sh"

echo "🚀 Installing polkadot-omni-node 0.5.0..."
echo "🚀 Installing polkadot-omni-node ${OMNI_NODE_VERSION}..."

# Install omni-node with locked dependencies
cargo install --locked [email protected]
cargo install --locked polkadot-omni-node@"${OMNI_NODE_VERSION}"

echo "✅ Omni node installation completed!"
echo "📋 Installed version: 0.5.0"
echo "📋 Installed version: ${OMNI_NODE_VERSION}"

# Verify installation
echo "🔍 Verifying installation..."
polkadot-omni-node --version
24 changes: 10 additions & 14 deletions tutorials/zero-to-hero/scripts/setup-rust.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
#!/bin/bash
# Rust Setup Script
# This script sets up Rust with the required version and components

set -e

RUST_VERSION="1.86"
# Load versions from tutorial-local or root config
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR"/../../.. && pwd)
TUTORIAL_DIR=$(cd "$SCRIPT_DIR"/.. && pwd)
source "$REPO_ROOT/scripts/load-versions.sh"

echo "🦀 Setting up Rust 1.86..."
echo "🦀 Setting up Rust ${RUST_VERSION}..."
echo "📦 Installing Rust toolchain and components..."

# Set default Rust version
rustup default 1.86

# Add WASM target for the current platform
rustup target add wasm32-unknown-unknown --toolchain 1.86

# Add rust source for the current platform
rustup component add rust-src --toolchain 1.86
rustup default "${RUST_VERSION}"
rustup target add wasm32-unknown-unknown --toolchain "${RUST_VERSION}"
rustup component add rust-src --toolchain "${RUST_VERSION}"

echo "✅ Rust setup completed successfully!"
echo "📋 Installed components:"
echo " - Rust toolchain: 1.86"
echo " - Rust toolchain: ${RUST_VERSION}"
echo " - WASM target: wasm32-unknown-unknown"
echo " - Rust source component"

# Verify installation
echo "🔍 Verifying installation..."
rustup show
Loading
Loading