From 8c7c629fadd3a76a12c02551fd1f5c953a54c758 Mon Sep 17 00:00:00 2001 From: bordolot Date: Fri, 6 Dec 2024 14:51:00 +0100 Subject: [PATCH 1/3] Run task simulations in CI(#337) --- .circleci/config.yml | 13 +++- lib/base-contracts | 2 +- lib/forge-std | 2 +- lib/solady | 2 +- lib/superchain-registry | 2 +- script/utils/check-task-statuses.sh | 4 +- script/utils/get-valid-statuses.sh | 15 +++++ script/utils/simulate-tasks.sh | 98 +++++++++++++++++++++++++++++ 8 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 script/utils/get-valid-statuses.sh create mode 100644 script/utils/simulate-tasks.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index e88064693..4fc68488e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -140,6 +140,17 @@ jobs: name: Check nonce overrides command: bash ./script/utils/check-nonce-overrides.sh + simulate_non_terminal_tasks: + docker: + - image: <> + steps: + - checkout + - attach_workspace: + at: . + - run: + name: Simulate non-terminal tasks + command: bash ./script/utils/simulate-tasks.sh + # TODO: remove/replace when there are real consumers of the RPC URLs example_mainnet_job: circleci_ip_ranges: true @@ -295,4 +306,4 @@ workflows: - just_simulate_sc_rehearsal_2 - just_simulate_sc_rehearsal_4 - just_simulate_ink_respected_game_type - # sepolia + - simulate_non_terminal_tasks \ No newline at end of file diff --git a/lib/base-contracts b/lib/base-contracts index 494586571..ed36aac52 160000 --- a/lib/base-contracts +++ b/lib/base-contracts @@ -1 +1 @@ -Subproject commit 494586571e1a4d845ee6f381b65229d63c630986 +Subproject commit ed36aac52a19bdad6dee09c59e7241fe3a194160 diff --git a/lib/forge-std b/lib/forge-std index b93cf4bc3..2d8b7b876 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit b93cf4bc34ff214c099dc970b153f85ade8c9f66 +Subproject commit 2d8b7b876a5b328d6a73e13c4740ed7a0d72d5f4 diff --git a/lib/solady b/lib/solady index 513f58167..a6a95729f 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 513f581675374706dbe947284d6b12d19ce35a2a +Subproject commit a6a95729f947bb2a24e05e862ba9522c10453a70 diff --git a/lib/superchain-registry b/lib/superchain-registry index c08331ab4..ea7e768a0 160000 --- a/lib/superchain-registry +++ b/lib/superchain-registry @@ -1 +1 @@ -Subproject commit c08331ab44a3645608c08d8c94f78d9be46c13c9 +Subproject commit ea7e768a02a6f88a38a1d39d27b9be6c212f4b6e diff --git a/script/utils/check-task-statuses.sh b/script/utils/check-task-statuses.sh index 89c77c55c..26eb78e93 100644 --- a/script/utils/check-task-statuses.sh +++ b/script/utils/check-task-statuses.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -VALID_STATUSES=("DRAFT, NOT READY TO SIGN" "CONTINGENCY TASK, SIGN AS NEEDED" "READY TO SIGN" "SIGNED" "EXECUTED" "CANCELLED") +source ./script/utils/get-valid-statuses.sh errors=() # We collect all errors then print them at the end. # Function to check status and hyperlinks for a single file. @@ -43,7 +43,7 @@ check_status_and_hyperlinks() { } # Find README.md files for all tasks and process them. -files=$(find ./tasks -type f -path './tasks/*/*/README.md') +# files read from ./script/utils/get-valid-statuses.sh for file in $files; do check_status_and_hyperlinks "$file" done diff --git a/script/utils/get-valid-statuses.sh b/script/utils/get-valid-statuses.sh new file mode 100644 index 000000000..f6861cc01 --- /dev/null +++ b/script/utils/get-valid-statuses.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail + +NON_TERMINAL_STATUSES=("DRAFT, NOT READY TO SIGN" "CONTINGENCY TASK, SIGN AS NEEDED" "READY TO SIGN") +TERMINAL_STATUSES=("SIGNED" "EXECUTED" "CANCELLED") +VALID_STATUSES=( "${NON_TERMINAL_STATUSES[@]}" "${TERMINAL_STATUSES[@]}" ) + +# Find README.md files for all tasks and process them. +files=$(find ./tasks -type f -path './tasks/*/*/README.md') + +# Filters: +# Name of a file to exclude from searching for non-terminal tasks. +FOLDER_WITH_NO_TASKS="templates" +# Name of a file in a task directiory that specifies that the task is a nested safe task. +IF_THIS_ITS_NESTED="NestedSignFromJson.s.sol" \ No newline at end of file diff --git a/script/utils/simulate-tasks.sh b/script/utils/simulate-tasks.sh new file mode 100644 index 000000000..978a8fbfc --- /dev/null +++ b/script/utils/simulate-tasks.sh @@ -0,0 +1,98 @@ +#!/bin/bash +set -euo pipefail + +source ./script/utils/get-valid-statuses.sh + +single_tasks_to_simulate=() +nested_tasks_to_simulate=() + +# Find README.md files for all tasks and process them. +# Files read from ./script/utils/get-valid-statuses.sh. +# Exclude tasks defined in folder FOLDER_WITH_NO_TASKS. +filtered_files=$(echo "$files" | grep -v "/${FOLDER_WITH_NO_TASKS}/") + +search_non_terminal_tasks(){ + local directory + for file in $filtered_files; do + # Ensure it's a regular file. + if [[ -f "$file" ]]; then + # Read file content and search for any status in the NON_TERMINAL_STATUSES array. + for status in "${NON_TERMINAL_STATUSES[@]}"; do + if grep -q "$status" "$file"; then + directory=$(dirname "$file") + # Specify if a task is safe or nested. + if [[ -f "$directory/$IF_THIS_ITS_NESTED" ]]; then + nested_tasks_to_simulate+=("${file%/README.md}") + else + single_tasks_to_simulate+=("${file%/README.md}") + fi + break + fi + done + fi + done +} + +search_non_terminal_tasks + +if [ ${#single_tasks_to_simulate[@]} -eq 0 ]; then + echo "No single tasks" +else + echo "Simulating single tasks..." + # Prepared acording to ./SINGLE.md + + export SIMULATE_WITHOUT_LEDGER=1 + + # Option 1: call simulation command here + for task in "${single_tasks_to_simulate[@]}"; do + current_dir=$(pwd) + cd "$task" + echo "Simulating task: $task" + just --dotenv-path $(pwd)/.env --justfile ../../../single.just simulate 0 + cd "$current_dir" + done + + # Option 2: read directly from ./SINGLE.md file + # md_file="./SINGLE.md" + # for task in "${single_tasks_to_simulate[@]}"; do + # current_dir=$(pwd) + # cd "$task" + # echo "Simulating task: $task" + # awk ' + # /```shell/ {block_count++; if (block_count == 2) in_block=1; next} + # /```/ {if (in_block) exit; in_block=0} + # in_block {print} + # ' "$md_file" > extracted.sh + # SIMULATE_WITHOUT_LEDGER=1 + # bash extracted.sh + # cd "$current_dir" + # done +fi + + +if [ ${#nested_tasks_to_simulate[@]} -eq 0 ]; then + echo "No nested tasks" +else + echo "Simulating nested tasks..." + # Prepared acording to ./NESTED.md + + export SIMULATE_WITHOUT_LEDGER=1 + + for task in "${nested_tasks_to_simulate[@]}"; do + current_dir=$(pwd) + cd "$task" + echo "Simulating task: $task" + + just --dotenv-path $(pwd)/.env --justfile ../../../nested.just simulate council + just --dotenv-path $(pwd)/.env --justfile ../../../nested.just approve council + + just --dotenv-path $(pwd)/.env --justfile ../../../nested.just simulate foundation + just --dotenv-path $(pwd)/.env --justfile ../../../nested.just approve foundation + + just --dotenv-path $(pwd)/.env --justfile ../../../nested.just simulate chain-governor + just --dotenv-path $(pwd)/.env --justfile ../../../nested.just approve chain-governor + + cd "$current_dir" + done +fi + From 91049d335ea5d55724f6dc85e832aac1ab852581 Mon Sep 17 00:00:00 2001 From: Blaine Malone Date: Tue, 17 Dec 2024 14:34:01 -0500 Subject: [PATCH 2/3] fix: fixes to original simulate PR. --- script/utils/check-task-statuses.sh | 7 +- script/utils/get-valid-statuses.sh | 26 +++--- script/utils/simulate-tasks.sh | 129 +++++++++++++++------------- 3 files changed, 86 insertions(+), 76 deletions(-) mode change 100644 => 100755 script/utils/get-valid-statuses.sh mode change 100644 => 100755 script/utils/simulate-tasks.sh diff --git a/script/utils/check-task-statuses.sh b/script/utils/check-task-statuses.sh index 26eb78e93..38397a7a3 100644 --- a/script/utils/check-task-statuses.sh +++ b/script/utils/check-task-statuses.sh @@ -1,7 +1,10 @@ #!/bin/bash set -euo pipefail -source ./script/utils/get-valid-statuses.sh +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=script/utils/get-valid-statuses.sh +source "$BASE_DIR/get-valid-statuses.sh" + errors=() # We collect all errors then print them at the end. # Function to check status and hyperlinks for a single file. @@ -44,7 +47,7 @@ check_status_and_hyperlinks() { # Find README.md files for all tasks and process them. # files read from ./script/utils/get-valid-statuses.sh -for file in $files; do +for file in $FILES_FOUND_BY_GET_VALID_STATUSES; do check_status_and_hyperlinks "$file" done diff --git a/script/utils/get-valid-statuses.sh b/script/utils/get-valid-statuses.sh old mode 100644 new mode 100755 index f6861cc01..8dfa96a55 --- a/script/utils/get-valid-statuses.sh +++ b/script/utils/get-valid-statuses.sh @@ -1,15 +1,17 @@ #!/bin/bash set -euo pipefail -NON_TERMINAL_STATUSES=("DRAFT, NOT READY TO SIGN" "CONTINGENCY TASK, SIGN AS NEEDED" "READY TO SIGN") -TERMINAL_STATUSES=("SIGNED" "EXECUTED" "CANCELLED") -VALID_STATUSES=( "${NON_TERMINAL_STATUSES[@]}" "${TERMINAL_STATUSES[@]}" ) - -# Find README.md files for all tasks and process them. -files=$(find ./tasks -type f -path './tasks/*/*/README.md') - -# Filters: -# Name of a file to exclude from searching for non-terminal tasks. -FOLDER_WITH_NO_TASKS="templates" -# Name of a file in a task directiory that specifies that the task is a nested safe task. -IF_THIS_ITS_NESTED="NestedSignFromJson.s.sol" \ No newline at end of file +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +TASKS_DIR="$BASE_DIR/../../tasks" +export TEMPLATES_FOLDER_WITH_NO_TASKS="templates" +export NESTED_SAFE_TASK_INDICATOR="NestedSignFromJson.s.sol" + +# Status arrays +export NON_TERMINAL_STATUSES=("DRAFT, NOT READY TO SIGN" "CONTINGENCY TASK, SIGN AS NEEDED" "READY TO SIGN") +export TERMINAL_STATUSES=("SIGNED" "EXECUTED" "CANCELLED") +export VALID_STATUSES=( "${NON_TERMINAL_STATUSES[@]}" "${TERMINAL_STATUSES[@]}" ) + +# Find README.md files for all tasks +FILES_FOUND_BY_GET_VALID_STATUSES=$(find "$TASKS_DIR" -type f -path "$TASKS_DIR/*/*/README.md") +export FILES_FOUND_BY_GET_VALID_STATUSES diff --git a/script/utils/simulate-tasks.sh b/script/utils/simulate-tasks.sh old mode 100644 new mode 100755 index 978a8fbfc..a229467ca --- a/script/utils/simulate-tasks.sh +++ b/script/utils/simulate-tasks.sh @@ -1,27 +1,27 @@ #!/bin/bash set -euo pipefail -source ./script/utils/get-valid-statuses.sh +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$BASE_DIR/../.." +# shellcheck source=script/utils/get-valid-statuses.sh +source "$BASE_DIR/get-valid-statuses.sh" +# --- Initialize Arrays --- single_tasks_to_simulate=() nested_tasks_to_simulate=() -# Find README.md files for all tasks and process them. -# Files read from ./script/utils/get-valid-statuses.sh. -# Exclude tasks defined in folder FOLDER_WITH_NO_TASKS. -filtered_files=$(echo "$files" | grep -v "/${FOLDER_WITH_NO_TASKS}/") +# --- Filter Files --- +filtered_files=$(echo "$FILES_FOUND_BY_GET_VALID_STATUSES" | grep -v "/${TEMPLATES_FOLDER_WITH_NO_TASKS}/") -search_non_terminal_tasks(){ +# --- Search Non-Terminal Tasks --- +search_non_terminal_tasks() { local directory for file in $filtered_files; do - # Ensure it's a regular file. if [[ -f "$file" ]]; then - # Read file content and search for any status in the NON_TERMINAL_STATUSES array. for status in "${NON_TERMINAL_STATUSES[@]}"; do if grep -q "$status" "$file"; then directory=$(dirname "$file") - # Specify if a task is safe or nested. - if [[ -f "$directory/$IF_THIS_ITS_NESTED" ]]; then + if [[ -f "$directory/$NESTED_SAFE_TASK_INDICATOR" ]]; then nested_tasks_to_simulate+=("${file%/README.md}") else single_tasks_to_simulate+=("${file%/README.md}") @@ -33,66 +33,71 @@ search_non_terminal_tasks(){ done } +# Define directories to skip - you should add reasons why it's being skipped. +directories_to_skip=( + "tasks/sep/base-003-fp-granite-prestate" # investigating why this simulation breaks. + "tasks/sep/013-fp-granite-prestate" # investigating why this simulation breaks. +) + +should_skip_directory() { + local dir="$1" + for skip_dir in "${directories_to_skip[@]}"; do + if [[ "$dir" == *"$skip_dir"* ]]; then + return 0 + fi + done + return 1 +} + search_non_terminal_tasks +# --- Simulate Single Tasks --- if [ ${#single_tasks_to_simulate[@]} -eq 0 ]; then - echo "No single tasks" + echo "No single tasks" else - echo "Simulating single tasks..." - # Prepared acording to ./SINGLE.md - - export SIMULATE_WITHOUT_LEDGER=1 - - # Option 1: call simulation command here - for task in "${single_tasks_to_simulate[@]}"; do - current_dir=$(pwd) - cd "$task" - echo "Simulating task: $task" - just --dotenv-path $(pwd)/.env --justfile ../../../single.just simulate 0 - cd "$current_dir" - done + echo "Simulating single tasks..." + echo "Number of single tasks to simulate: ${#single_tasks_to_simulate[@]}" + export SIMULATE_WITHOUT_LEDGER=1 + for task in "${single_tasks_to_simulate[@]}"; do + echo "Simulating task: $(basename "$task")" + current_dir=$(pwd) + cd "$task" || exit 1 + + # Check if 'justfile' exists in the current directory it's either an old task + # that we can skip or a template task which we should also skip. + if [ -f "justfile" ] || should_skip_directory "$task"; then + echo "Skipping task: $(basename "$task") - please see simultate-tasks.sh for more information." + else + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/single.just" simulate 0 + fi - # Option 2: read directly from ./SINGLE.md file - # md_file="./SINGLE.md" - # for task in "${single_tasks_to_simulate[@]}"; do - # current_dir=$(pwd) - # cd "$task" - # echo "Simulating task: $task" - # awk ' - # /```shell/ {block_count++; if (block_count == 2) in_block=1; next} - # /```/ {if (in_block) exit; in_block=0} - # in_block {print} - # ' "$md_file" > extracted.sh - # SIMULATE_WITHOUT_LEDGER=1 - # bash extracted.sh - # cd "$current_dir" - # done + cd "$current_dir" || exit 1 + done fi - +# --- Simulate Nested Tasks --- if [ ${#nested_tasks_to_simulate[@]} -eq 0 ]; then - echo "No nested tasks" + echo "No nested tasks" else - echo "Simulating nested tasks..." - # Prepared acording to ./NESTED.md - - export SIMULATE_WITHOUT_LEDGER=1 - - for task in "${nested_tasks_to_simulate[@]}"; do - current_dir=$(pwd) - cd "$task" - echo "Simulating task: $task" - - just --dotenv-path $(pwd)/.env --justfile ../../../nested.just simulate council - just --dotenv-path $(pwd)/.env --justfile ../../../nested.just approve council - - just --dotenv-path $(pwd)/.env --justfile ../../../nested.just simulate foundation - just --dotenv-path $(pwd)/.env --justfile ../../../nested.just approve foundation - - just --dotenv-path $(pwd)/.env --justfile ../../../nested.just simulate chain-governor - just --dotenv-path $(pwd)/.env --justfile ../../../nested.just approve chain-governor + echo "Simulating nested tasks..." + echo "Number of nested tasks to simulate: ${#nested_tasks_to_simulate[@]}" + export SIMULATE_WITHOUT_LEDGER=1 + for task in "${nested_tasks_to_simulate[@]}"; do + echo "Simulating task: $(basename "$task")" + current_dir=$(pwd) + cd "$task" || exit 1 + + if [ -f "justfile" ] || should_skip_directory "$task"; then + echo "Skipping task: $(basename "$task") - please see simultate-tasks.sh to see why." + else + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" simulate council + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" approve council + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" simulate foundation + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" approve foundation + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" simulate chain-governor + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" approve chain-governor + fi - cd "$current_dir" - done + cd "$current_dir" || exit 1 + done fi - From 288697a87532de9f0be8c4eeeb7f85d69521c5b5 Mon Sep 17 00:00:00 2001 From: Blaine Malone Date: Tue, 17 Dec 2024 14:41:58 -0500 Subject: [PATCH 3/3] fix: removing executed task from skip list. fix: small updates. fix: simulate enabled in ci. fix: removed libs fix: added submodules back in. --- .circleci/config.yml | 6 +++++- lib/base-contracts | 2 +- lib/forge-std | 2 +- lib/solady | 2 +- lib/superchain-registry | 2 +- script/utils/simulate-tasks.sh | 24 +++++++++++------------- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4fc68488e..b2a5f6d0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -306,4 +306,8 @@ workflows: - just_simulate_sc_rehearsal_2 - just_simulate_sc_rehearsal_4 - just_simulate_ink_respected_game_type - - simulate_non_terminal_tasks \ No newline at end of file + # Simulate non-terminal tasks. + # This process finds all non-terminal tasks that currently + # exist in the task list and simulates them to ensure that + # they are still valid. + - simulate_non_terminal_tasks diff --git a/lib/base-contracts b/lib/base-contracts index ed36aac52..494586571 160000 --- a/lib/base-contracts +++ b/lib/base-contracts @@ -1 +1 @@ -Subproject commit ed36aac52a19bdad6dee09c59e7241fe3a194160 +Subproject commit 494586571e1a4d845ee6f381b65229d63c630986 diff --git a/lib/forge-std b/lib/forge-std index 2d8b7b876..b93cf4bc3 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 2d8b7b876a5b328d6a73e13c4740ed7a0d72d5f4 +Subproject commit b93cf4bc34ff214c099dc970b153f85ade8c9f66 diff --git a/lib/solady b/lib/solady index a6a95729f..513f58167 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit a6a95729f947bb2a24e05e862ba9522c10453a70 +Subproject commit 513f581675374706dbe947284d6b12d19ce35a2a diff --git a/lib/superchain-registry b/lib/superchain-registry index ea7e768a0..c08331ab4 160000 --- a/lib/superchain-registry +++ b/lib/superchain-registry @@ -1 +1 @@ -Subproject commit ea7e768a02a6f88a38a1d39d27b9be6c212f4b6e +Subproject commit c08331ab44a3645608c08d8c94f78d9be46c13c9 diff --git a/script/utils/simulate-tasks.sh b/script/utils/simulate-tasks.sh index a229467ca..651ec6001 100755 --- a/script/utils/simulate-tasks.sh +++ b/script/utils/simulate-tasks.sh @@ -33,19 +33,23 @@ search_non_terminal_tasks() { done } -# Define directories to skip - you should add reasons why it's being skipped. -directories_to_skip=( - "tasks/sep/base-003-fp-granite-prestate" # investigating why this simulation breaks. - "tasks/sep/013-fp-granite-prestate" # investigating why this simulation breaks. -) +# Define directories to skip. If you're adding to this list, please add a comment explaining why. +directories_to_skip=() should_skip_directory() { local dir="$1" for skip_dir in "${directories_to_skip[@]}"; do if [[ "$dir" == *"$skip_dir"* ]]; then + echo "Skipping task: $(basename "$task") because it's been marked as a directory to skip." return 0 fi done + # Check if 'justfile' exists in the current directory. If it exists then it's either an old task + # or a template task that we can skip. + if [ -f "$dir/justfile" ]; then + echo "Skipping task: $(basename "$task") because it contains a 'justfile'." + return 0 + fi return 1 } @@ -63,11 +67,7 @@ else current_dir=$(pwd) cd "$task" || exit 1 - # Check if 'justfile' exists in the current directory it's either an old task - # that we can skip or a template task which we should also skip. - if [ -f "justfile" ] || should_skip_directory "$task"; then - echo "Skipping task: $(basename "$task") - please see simultate-tasks.sh for more information." - else + if ! should_skip_directory "$task"; then just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/single.just" simulate 0 fi @@ -87,9 +87,7 @@ else current_dir=$(pwd) cd "$task" || exit 1 - if [ -f "justfile" ] || should_skip_directory "$task"; then - echo "Skipping task: $(basename "$task") - please see simultate-tasks.sh to see why." - else + if ! should_skip_directory "$task"; then just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" simulate council just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" approve council just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/nested.just" simulate foundation