Skip to content

Commit

Permalink
Fix patch creation for parachains
Browse files Browse the repository at this point in the history
  • Loading branch information
raynaudoe committed Aug 2, 2024
1 parent c656458 commit 627f06b
Showing 1 changed file with 56 additions and 26 deletions.
82 changes: 56 additions & 26 deletions scripts/create_runtime_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,59 @@ print_message() {
echo "${color}${message}${RESET}"
}

# Check if the correct number of arguments is provided
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
echo "Usage: $0 <current_paseo_runtime_version> <new_polkadot_runtime_version> [paseo_branch] [process_parachains]"
echo "paseo_branch: Optional. Specify the branch to clone for Paseo runtime. Defaults to 'main'."
echo "process_parachains: Optional. Set to 'true' to process parachains. Defaults to 'false'."
exit 1
fi

# Define list of parachains to copy
# Format: "parachain_name origin_dir dest_dir"
# parachain_name: name of the parachain
# origin_dir: relative path in polkadot_runtime_next/system-parachains/
# dest_dir: relative path in paseo_runtime/system-parachains/
PARACHAINS=(
"asset_hub asset-hubs/asset-hub-polkadot asset-hub-paseo"
"asset_hub asset-hubs/asset-hub-polkadot asset-hub-paseo"
"bridge_hub bridge-hubs/bridge-hub-polkadot bridge-hub-paseo"
)

# Initialize default values
PASEO_BRANCH="main"
PROCESS_PARACHAINS="false"

# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--paseo-ref-branch)
PASEO_BRANCH="$2"
shift 2
;;
--parachains)
PROCESS_PARACHAINS="true"
shift
;;
*)
if [ -z "$CURRENT_TAG" ]; then
CURRENT_TAG="$1"
elif [ -z "$NEXT_TAG" ]; then
NEXT_TAG="$1"
else
echo "Error: Unexpected argument '$1'"
exit 1
fi
shift
;;
esac
done

# Check if required arguments are provided
if [ -z "$CURRENT_TAG" ] || [ -z "$NEXT_TAG" ]; then
echo "Usage: $0 <current_paseo_runtime_version> <new_polkadot_runtime_version> [--paseo-ref-branch <branch>] [--parachains]"
echo "--paseo-ref-branch: Optional. Specify the branch to clone for Paseo runtime. Defaults to 'main'."
echo "--parachains: Optional. Process parachains if specified."
exit 1
fi

CURRENT_TAG=$1
NEXT_TAG=$2
PASEO_BRANCH=${3:-main}
PROCESS_PARACHAINS=${4:-false}
POLKADOT_CURRENT_TAG=v${CURRENT_TAG}
POLKADOT_NEXT_TAG=v${NEXT_TAG}


print_message "========================================" "${GREEN}"
print_message "Creating patches from tag ${POLKADOT_CURRENT_TAG} to ${POLKADOT_NEXT_TAG}" "${GREEN}"
print_message "Paseo reference branch: ${PASEO_BRANCH}" "${GREEN}"
print_message "Parachains processing: ${PROCESS_PARACHAINS}" "${GREEN}"
print_message "========================================" "${GREEN}"

Expand Down Expand Up @@ -98,7 +123,7 @@ if [ "$PROCESS_PARACHAINS" = "true" ]; then

print_message "----- Copying specified parachains -----" "${BLUE}"
for parachain in "${PARACHAINS[@]}"; do
read -r parachain_name source_dir dest_dir <<< "$parachain"
read -r parachain_name _ dest_dir <<< "$parachain"
source_dir="../polkadot_runtime_next/system-parachains/${source_dir}"
dest_dir="system-parachains/${dest_dir}"
if [ -d "$source_dir" ]; then
Expand All @@ -120,34 +145,39 @@ fi
print_message "----- Creating patch files for Polkadot ${NEXT_TAG} runtime -----" "${WHITE}"
mkdir -p ${PATCH_DIR}

# Create patches for relay/paseo and Cargo.toml
if git format-patch -o ${PATCH_DIR} ${LATEST_COMMIT}..HEAD -- relay/paseo Cargo.toml; then
print_message "Successfully created relay patch files in: ${PATCH_DIR}" "${WHITE}"
if git format-patch -1 --stdout ${LATEST_COMMIT}..HEAD -- relay/paseo Cargo.toml > "${PATCH_DIR}/0001-Update-to-polkadot-relay-${NEXT_TAG}.patch"; then
print_message "Successfully created relay patch file: ${PATCH_DIR}/0001-Update-to-polkadot-relay-${NEXT_TAG}.patch" "${WHITE}"
else
print_message "Failed to create relay patch files" "${RED}"
print_message "Failed to create relay patch file" "${RED}"
fi

if [ "$PROCESS_PARACHAINS" = "true" ]; then
# Create patches for each parachain
for parachain in "${PARACHAINS[@]}"; do
read -r parachain_name _ dest_dir <<< "$parachain"
parachain_dir="system-parachains/${dest_dir}"
patch_output_dir="${PATCH_DIR}/system-parachains/${parachain_name}"
patch_file="${patch_output_dir}/0001-update-to-${parachain_name}-${NEXT_TAG}.patch"

if [ -d "$parachain_dir" ]; then
if git format-patch -o ${PATCH_DIR} --prefix="${parachain_name}/" ${LATEST_COMMIT}..HEAD -- "$parachain_dir"; then
print_message "Created patches for ${parachain_name}" "${WHITE}"
mkdir -p "$patch_output_dir"
if git format-patch -1 --stdout ${LATEST_COMMIT}..HEAD -- "$parachain_dir" > "$patch_file"; then
print_message "Created patch for ${parachain_name}: ${patch_file}" "${WHITE}"
else
print_message "Failed to create patches for ${parachain_name}" "${RED}"
print_message "Failed to create patch for ${parachain_name}" "${RED}"
fi
else
print_message "Warning: ${dest_dir} not found for ${parachain_name}, skipping patch creation" "${RED}"
fi
done

# Create patches for system-parachains/constants and system-parachains/Cargo.toml
if git format-patch -o ${PATCH_DIR} --prefix="system-parachains/" ${LATEST_COMMIT}..HEAD -- system-parachains/constants system-parachains/Cargo.toml; then
print_message "Created patches for system-parachains/constants" "${WHITE}"
# Create patch for system-parachains/constants and system-parachains/Cargo.toml
parachains_patch_file="${PATCH_DIR}/system-parachains/0001-update-to-parachains-${NEXT_TAG}.patch"
mkdir -p "${PATCH_DIR}/system-parachains"
if git format-patch -1 --stdout ${LATEST_COMMIT}..HEAD -- system-parachains/constants system-parachains/Cargo.toml > "$parachains_patch_file"; then
print_message "Created patch for system-parachains: ${parachains_patch_file}" "${WHITE}"
else
print_message "Failed to create patches for system-parachains/constants" "${RED}"
print_message "Failed to create patch for system-parachains" "${RED}"
fi
fi

Expand Down

0 comments on commit 627f06b

Please sign in to comment.