Skip to content

Merge pull request #3 from SanviSeetha4481/enhance-expense-tracker #8

Merge pull request #3 from SanviSeetha4481/enhance-expense-tracker

Merge pull request #3 from SanviSeetha4481/enhance-expense-tracker #8

Workflow file for this run

name: C Project Continuous Integration
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
# Job 1: CI (Build, Test, and Create Artifact)
build_c_project:
runs-on: ubuntu-latest
steps:
- name: Checkout repository code
uses: actions/checkout@v4
- name: Install C compiler tools
run: sudo apt-get update && sudo apt-get install -y build-essential
# CORE FIX: Compile, run with timeout, and handle the 124 exit code
- name: Compile and Test Individual C Programs
run: |
echo "Starting compilation and testing for all C files..."
for c_file in *.c; do
project_name=$(basename $c_file .c)
echo "--- Compiling $c_file to $project_name ---"
gcc -o $project_name $c_file
# Check if COMPILATION succeeded
if [ $? -eq 0 ]; then
echo "SUCCESS: $c_file compiled. Running smoke test with 1s timeout..."
# Run the executable with a 1-second timeout
timeout 1s ./$project_name
# Get the exit code of the 'timeout' command
exit_code=$?
# Check for acceptable exit codes: 0 (normal exit) or 124 (timeout exit)
if [ $exit_code -eq 0 ] || [ $exit_code -eq 124 ]; then
echo "Smoke test passed (Exit code: $exit_code)."
# Optional: Save the 'todo' executable for the CD job
if [ "$project_name" == "todo" ]; then
cp todo todo_app_for_deploy
fi
else
echo "Smoke test FAILED with unexpected exit code: $exit_code"
exit 1 # Fail the job if the program crashed or failed
fi
echo "-----------------------------------"
else
echo "FAILURE: $c_file compilation failed!"
exit 1
fi
done
echo "All C projects successfully compiled and tested!"
- name: Upload one compiled executable as artifact for CD
uses: actions/upload-artifact@v4
with:
name: todo-c-executable
path: todo_app_for_deploy
# Job 2: CD (Deployment) - Only runs if Job 1 succeeds
deploy:
needs: build_c_project
runs-on: ubuntu-latest
steps:
- name: Download the verified artifact
uses: actions/download-artifact@v4
with:
name: todo-c-executable
- name: Verify artifact and simulate deployment
run: |
ls -l
echo "--- Beginning Continuous Deployment ---"
echo "Deploying verified 'todo_app_for_deploy' to staging environment..."
echo "SUCCESS: Deployment simulation complete."