Skip to content

Commit

Permalink
fix: fixes to original simulate PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
blmalone committed Jan 14, 2025
1 parent 8c7c629 commit 91049d3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 76 deletions.
7 changes: 5 additions & 2 deletions script/utils/check-task-statuses.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

Expand Down
26 changes: 14 additions & 12 deletions script/utils/get-valid-statuses.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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"
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
129 changes: 67 additions & 62 deletions script/utils/simulate-tasks.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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}")
Expand All @@ -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

0 comments on commit 91049d3

Please sign in to comment.