Skip to content

Commit

Permalink
temp file to track error in async
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbrs committed Nov 18, 2023
1 parent 3f0ac5a commit 58efc1b
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions scripts/cairo_programs_verifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,65 @@ NC='\033[0m'

# Root directory of the repository
REPO_ROOT="$(git rev-parse --show-toplevel)"

# flag to check if any errors were encountered
has_errors=false

# Array to hold PIDs of background processes
pids=()
error_file=$(mktemp)

# function to list modified cairo files
list_modified_cairo_files() {
git diff --name-only main...HEAD -- listings | grep -E 'listings/ch.*/*.cairo$'
git diff --name-only main...HEAD -- listings | grep -E 'listings/ch.*/*.cairo$'
}

# function to process individual file
process_file() {
local relative_path="$1"
local dir_path="${REPO_ROOT}/$(dirname "${relative_path}")"
local file_name=$(basename "$relative_path")
local relative_path="$1"
local dir_path="${REPO_ROOT}/$(dirname "${relative_path}")"
local file_name=$(basename "$relative_path")

if ! cd "$dir_path"; then
echo "Failed to change to directory: $dir_path"
has_errors=true
return
fi
if ! cd "$dir_path"; then
echo "Failed to change to directory: $dir_path"
echo "1" >> "$error_file"
return
fi

# Run scarb commands
if ! scarb build "$file_name" >error.log 2>&1; then
scarb build >error.log 2>&1
if ! scarb build "$file_name" >error.log 2>&1; then
cat error.log
echo "1" >> "$error_file"
fi

cat error.log
has_errors=true
fi
if ! scarb fmt -c "$file_name" >>error.log 2>&1; then
echo "Error in scarb format check for $file_name"
cat error.log
echo "1" >> "$error_file"
fi

if ! scarb fmt >>error.log 2>&1; then
echo "Error in scarb format check for $file_name"
cat error.log
has_errors=true
fi
if ! scarb test "$file_name" >>error.log 2>&1; then
echo "Error in scarb test for $file_name"
cat error.log
echo "1" >> "$error_file"
fi

if ! scarb test >>error.log 2>&1; then
echo "Error in scarb test for $file_name"
cat error.log
has_errors=true
fi

rm error.log
rm error.log
}

# process each modified file
pids=()
modified_files=$(list_modified_cairo_files)
for file in $modified_files; do
process_file "$file" &
pids+=($!)
process_file "$file" &
pids+=($!)
done

# Wait for all background processes to finish
for pid in ${pids[@]}; do
wait $pid
wait $pid
done

# check if any errors were encountered
if $has_errors; then
echo -e "\n${RED}Some projects have errors, please check the list above.${NC}\n"
exit 1
# Check if any errors were encountered
if grep -q "1" "$error_file"; then
echo -e "\n${RED}Some projects have errors, please check the list above.${NC}\n"
rm "$error_file"
exit 1
else
echo -e "\n${GREEN}All scarb builds were completed successfully${NC}.\n"
exit 0
echo -e "\n${GREEN}All scarb builds were completed successfully${NC}.\n"
rm "$error_file"
exit 0
fi

0 comments on commit 58efc1b

Please sign in to comment.