@@ -14,19 +14,23 @@ jobs:
1414 - name : Checkout repository
1515 uses : actions/checkout@v4
1616
17- - name : Compile and Run all C programs in the 'program' folder
17+ - name : Compile and Run all C programs recursively
1818 run : |
19- # Check if any .c files exist to avoid errors
20- if ! ls program/*.c 1> /dev/null 2>&1; then
21- echo "No .c files found in 'program' directory. Skipping."
19+ # Enable recursive globbing (the ** pattern)
20+ shopt -s globstar
21+
22+ # Check if any .c files exist in 'program' or its subdirectories
23+ if ! ls program/**/*.c 1> /dev/null 2>&1; then
24+ echo "No .c files found in 'program' or its subdirectories. Skipping."
2225 exit 0
2326 fi
2427
25- # Loop through each .c file in the 'program' directory
26- for c_file in program/*.c; do
27- # Create a unique name for the executable from the C file name
28- # For example, "program/app.c" becomes "app_executable"
29- executable_name=$(basename "$c_file" .c)_executable
28+ # Loop through each .c file found recursively
29+ for c_file in program/**/*.c; do
30+ # Create a unique executable name from the full file path to prevent
31+ # name collisions if two subfolders have a file with the same name.
32+ # Example: "program/day1/app.c" becomes "program_day1_app_executable"
33+ executable_name=$(echo "$c_file" | sed 's|/|_|g; s|\.c$||')_executable
3034
3135 echo "---"
3236 echo "Compiling: $c_file"
0 commit comments