Skip to content

Commit 8cbc0af

Browse files
Update c-cpp.yml
1 parent 5eee265 commit 8cbc0af

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

.github/workflows/c-cpp.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: Checkout repository
15-
uses: actions/checkout@v4
16-
17-
- name: Compile and Run all C programs recursively
18-
run: |
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."
25-
exit 0
26-
fi
27-
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
34-
35-
echo "---"
36-
echo "Compiling: $c_file"
37-
gcc "$c_file" -o "$executable_name"
38-
39-
echo "Running: ./${executable_name}"
40-
./"$executable_name"
41-
echo "---"
42-
done
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Compile and Run all C programs in programs/
18+
run: |
19+
# Enable recursive globbing
20+
shopt -s globstar
21+
22+
cd programs
23+
24+
# Check if any .c files exist under this folder
25+
if ! ls **/*.c 1> /dev/null 2>&1; then
26+
echo "No .c files found in 'programs'. Skipping."
27+
exit 0
28+
fi
29+
30+
# Loop through each .c file
31+
for c_file in **/*.c; do
32+
# Create a unique executable name from the relative path
33+
executable_name=$(echo "$c_file" | sed 's|/|_|g; s|\.c$||')_exec
34+
35+
echo "---"
36+
echo "Compiling: $c_file"
37+
gcc "$c_file" -o "$executable_name"
38+
39+
echo "Running: ./${executable_name}"
40+
./"$executable_name"
41+
echo "---"
42+
done

0 commit comments

Comments
 (0)