Skip to content

Commit ce7bf31

Browse files
authored
Update ci.yml
1 parent a127f6e commit ce7bf31

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,51 @@ jobs:
1616
uses: actions/checkout@v4
1717

1818
- name: Install C compiler tools
19-
# Ensures that the GCC compiler and related tools are available
2019
run: sudo apt-get update && sudo apt-get install -y build-essential
2120

22-
# CORE FIX: Compile, run with timeout, and test each individual C file
21+
# CORE FIX: Compile, run with timeout, and handle the 124 exit code
2322
- name: Compile and Test Individual C Programs
2423
run: |
2524
echo "Starting compilation and testing for all C files..."
2625
27-
# Loop through every C file in the directory
2826
for c_file in *.c; do
29-
# project_name will be the file name without the .c extension (e.g., 'contact')
3027
project_name=$(basename $c_file .c)
3128
3229
echo "--- Compiling $c_file to $project_name ---"
3330
34-
# Compile the single C file into an executable named after the project
3531
gcc -o $project_name $c_file
3632
37-
# $? holds the exit status of the previous command (gcc). 0 means success.
33+
# Check if COMPILATION succeeded
3834
if [ $? -eq 0 ]; then
3935
echo "SUCCESS: $c_file compiled. Running smoke test with 1s timeout..."
4036
41-
# *** THE KEY FIX ***
42-
# 'timeout 1s' runs the program for 1 second. It will start,
43-
# print its menu, and then be forcefully stopped, preventing it
44-
# from stalling the pipeline while waiting for keyboard input.
37+
# Run the executable with a 1-second timeout
4538
timeout 1s ./$project_name
4639
47-
# Optional: Save the 'todo' executable for the CD job
48-
if [ "$project_name" == "todo" ]; then
49-
cp todo todo_app_for_deploy
40+
# Get the exit code of the 'timeout' command
41+
exit_code=$?
42+
43+
# Check for acceptable exit codes: 0 (normal exit) or 124 (timeout exit)
44+
if [ $exit_code -eq 0 ] || [ $exit_code -eq 124 ]; then
45+
echo "Smoke test passed (Exit code: $exit_code)."
46+
47+
# Optional: Save the 'todo' executable for the CD job
48+
if [ "$project_name" == "todo" ]; then
49+
cp todo todo_app_for_deploy
50+
fi
51+
else
52+
echo "Smoke test FAILED with unexpected exit code: $exit_code"
53+
exit 1 # Fail the job if the program crashed or failed
5054
fi
5155
5256
echo "-----------------------------------"
5357
else
5458
echo "FAILURE: $c_file compilation failed!"
55-
# Crucially, exit with code 1 to fail the GitHub Action job
5659
exit 1
5760
fi
5861
done
5962
echo "All C projects successfully compiled and tested!"
6063
61-
# Upload the selected executable as an artifact for the next job
6264
- name: Upload one compiled executable as artifact for CD
6365
uses: actions/upload-artifact@v4
6466
with:
@@ -68,7 +70,6 @@ jobs:
6870

6971
# Job 2: CD (Deployment) - Only runs if Job 1 succeeds
7072
deploy:
71-
# This ensures deployment only happens with successfully built code
7273
needs: build_c_project
7374
runs-on: ubuntu-latest
7475

0 commit comments

Comments
 (0)