-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathcombine-ymls.sh
executable file
·98 lines (86 loc) · 4.54 KB
/
combine-ymls.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
COMBINATIONS_FOLDER="combinations"
MATRIX_VERSION_FILE="matrix.yml"
MATRIX_VERSION_README="../../CDK_VERSION_MATRIX.MD"
# Extracts the base file name from a full path, removing the directory path and the .yml extension.
# e.g. get_file_name "forks/fork10.yml" should return "fork10".
extract_base_name() {
echo "$1" | sed 's|.*/||; s|\.yml$||'
}
# Convert a YML array into a Markdown table.
yml2md() {
echo "Fork ID|CDK Erigon|ZkEVM Prover|ZkEVM Contracts|Data Availability|Bridge"
echo "---|---|---|---|---|---"
yq -r '
to_entries |
sort_by(.key | tonumber) | reverse |
map(
"\(.key)|[\(.value.cdk_erigon.version)](\(.value.cdk_erigon.source))|[\(.value.zkevm_prover.version)](\(.value.zkevm_prover.source))|[\(.value.zkevm_contracts.version)](\(.value.zkevm_contracts.source))|[\(.value.data_availability.version)](\(.value.data_availability.source))|[\(.value.bridge_service.version)](\(.value.bridge_service.source))"
) |
join("\n")
' "$1"
}
true > "$MATRIX_VERSION_FILE"
echo -e "# Polygon CDK Version Matrix\n\nWhich versions of the CDK stack are meant to work together?\n" > "$MATRIX_VERSION_README"
# File combinations.
forks=(forks/*.yml)
data_availability=(da-modes/*.yml)
components=(components/*.yml)
# Nested loops to create all combinations.
echo "Creating combinations..."
mkdir -p "$COMBINATIONS_FOLDER"
for fork in "${forks[@]}"; do
for da in "${data_availability[@]}"; do
for comp in "${components[@]}"; do
base_fork="$(extract_base_name "$fork")"
base_da="$(extract_base_name "$da")"
base_comp="$(extract_base_name "$comp")"
# The legacy stack doesn't work with fork 12
if [[ "$base_fork" == "fork12" && "$base_comp" == "legacy-zkevm-stack" ]]; then
continue
fi
# The legacy stack also doesn't work with fork 13
if [[ "$base_fork" == "fork13" && "$base_comp" == "legacy-zkevm-stack" ]]; then
continue
fi
# The combination of fork 11 with the zkevm stack with validium mode does not work
if [[ "$base_fork" == "fork11" && "$base_comp" == "legacy-zkevm-stack" && "$base_da" == "cdk-validium" ]]; then
continue
fi
output_file="$COMBINATIONS_FOLDER/$base_fork-$base_comp-$base_da.yml"
yq --slurp ".[0] * .[1] * .[2]" "$fork" "$da" "$comp" --yaml-output > "$output_file"
echo "- $output_file"
# Save version matrix for each fork.
if [[ "$base_da" == "cdk-validium" && "$base_comp" == "new-cdk-stack" ]]; then
fork_id=${base_fork#fork}
# shellcheck disable=SC2016
yq --raw-output --arg fork_id "$fork_id" --yaml-output '{
($fork_id): {
cdk_erigon: {
version: .args.cdk_erigon_node_image | split(":")[1],
source: "https://github.com/0xPolygonHermez/cdk-erigon/releases/tag/\(.args.cdk_erigon_node_image | split(":")[1])",
},
zkevm_prover: {
version: .args.zkevm_prover_image | split(":")[1],
source: "https://github.com/0xPolygonHermez/zkevm-prover/releases/tag/\(.args.zkevm_prover_image | split(":")[1] | split("-fork")[0])",
},
zkevm_contracts: {
version: .args.zkevm_contracts_image | split(":")[1] | split("-patch.")[0],
source: "https://github.com/0xPolygonHermez/zkevm-contracts/releases/tag/\(.args.zkevm_contracts_image | split(":")[1] | split("-patch.")[0])",
},
data_availability: {
version: .args.zkevm_da_image | split(":")[1],
source: "https://github.com/0xPolygon/cdk-data-availability/releases/tag/v\(.args.zkevm_da_image | split(":")[1])",
},
bridge_service: {
version: .args.zkevm_bridge_service_image | split(":")[1],
source: "https://github.com/0xPolygonHermez/zkevm-bridge-service/releases/tag/\(.args.zkevm_bridge_service_image | split(":")[1])",
},
}}
' "$output_file" >> "$MATRIX_VERSION_FILE"
fi
done
done
done
yml2md "$MATRIX_VERSION_FILE" >> "$MATRIX_VERSION_README"
echo "All combinations created!"