Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate non-terminal tasks in CI - @bordolot contribution #420

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ jobs:
name: Check nonce overrides
command: bash ./script/utils/check-nonce-overrides.sh

simulate_non_terminal_tasks:
docker:
- image: <<pipeline.parameters.ci_builder_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
Expand Down Expand Up @@ -302,5 +313,10 @@ workflows:
- just_simulate_sc_rehearsal_1
- just_simulate_sc_rehearsal_2
- just_simulate_sc_rehearsal_4
# 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
- simulate_eth_021
- simulate_eth_022
9 changes: 6 additions & 3 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

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.
Expand Down Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions script/utils/get-valid-statuses.sh
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions script/utils/simulate-tasks.sh
Original file line number Diff line number Diff line change
@@ -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