diff --git a/.circleci/config.yml b/.circleci/config.yml index e88064693..b2a5f6d0d 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,8 @@ workflows: - just_simulate_sc_rehearsal_2 - just_simulate_sc_rehearsal_4 - just_simulate_ink_respected_game_type - # sepolia + # 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/script/utils/check-task-statuses.sh b/script/utils/check-task-statuses.sh index 89c77c55c..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 -VALID_STATUSES=("DRAFT, NOT READY TO SIGN" "CONTINGENCY TASK, SIGN AS NEEDED" "READY TO SIGN" "SIGNED" "EXECUTED" "CANCELLED") +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. @@ -43,8 +46,8 @@ check_status_and_hyperlinks() { } # Find README.md files for all tasks and process them. -files=$(find ./tasks -type f -path './tasks/*/*/README.md') -for file in $files; do +# files read from ./script/utils/get-valid-statuses.sh +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 new file mode 100755 index 000000000..8dfa96a55 --- /dev/null +++ b/script/utils/get-valid-statuses.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +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 new file mode 100755 index 000000000..651ec6001 --- /dev/null +++ b/script/utils/simulate-tasks.sh @@ -0,0 +1,101 @@ +#!/bin/bash +set -euo pipefail + +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=() + +# --- 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() { + local directory + for file in $filtered_files; do + if [[ -f "$file" ]]; then + for status in "${NON_TERMINAL_STATUSES[@]}"; do + if grep -q "$status" "$file"; then + directory=$(dirname "$file") + if [[ -f "$directory/$NESTED_SAFE_TASK_INDICATOR" ]]; then + nested_tasks_to_simulate+=("${file%/README.md}") + else + single_tasks_to_simulate+=("${file%/README.md}") + fi + break + fi + done + fi + done +} + +# 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 +} + +search_non_terminal_tasks + +# --- Simulate Single Tasks --- +if [ ${#single_tasks_to_simulate[@]} -eq 0 ]; then + echo "No single tasks" +else + 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 + + if ! should_skip_directory "$task"; then + just --dotenv-path "$PWD/.env" --justfile "$ROOT_DIR/single.just" simulate 0 + fi + + cd "$current_dir" || exit 1 + done +fi + +# --- Simulate Nested Tasks --- +if [ ${#nested_tasks_to_simulate[@]} -eq 0 ]; then + echo "No nested tasks" +else + 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 ! 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 + 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" || exit 1 + done +fi