Skip to content

Commit 9d9fea4

Browse files
committed
Add GitHub Actions CI workflow
1 parent 0bccebb commit 9d9fea4

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Philosophers CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install dependencies
17+
run: sudo apt-get update && sudo apt-get install -y make gcc
18+
19+
- name: Compile project
20+
run: |
21+
cd philo
22+
make re
23+
24+
- name: Run basic tests
25+
run: |
26+
cd philo
27+
# Test 1: 4 philosophers
28+
timeout 5s ./philo 4 800 200 200
29+
[ $? -eq 124 ] && echo "✅ Test 1 Passed (4 philo run)" || (echo "❌ Test 1 Failed" && exit 1)
30+
31+
# Test 2: Meal limit
32+
./philo 3 1000 200 200 5 > meals.txt
33+
grep -q "is eating" meals.txt
34+
[ $? -eq 0 ] && echo "✅ Test 2 Passed (meal limit)" || (echo "❌ Test 2 Failed" && exit 1)
35+
36+
# Test 3: Single philosopher
37+
./philo 1 800 200 200 > single.txt
38+
grep -q "died" single.txt
39+
[ $? -eq 0 ] && echo "✅ Test 3 Passed (single philo)" || (echo "❌ Test 3 Failed" && exit 1)

0 commit comments

Comments
 (0)