Skip to content

Commit 74158a9

Browse files
authored
Added Automated Test On PR pipeline (#44)
1 parent d036587 commit 74158a9

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

.github/workflows/scripts-test.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Run FEAScript Examples
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
run-examples:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
fail-fast: false # Continue testing other versions even if one fails
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: npm
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Run FEAScript examples
32+
run: |
33+
echo "=========================================="
34+
echo "Running FEAScript examples with Node.js ${{ matrix.node-version }}"
35+
echo "=========================================="
36+
37+
# Counter for tracking test results
38+
PASSED=0
39+
FAILED=0
40+
TOTAL=0
41+
42+
# Array to store failed examples
43+
FAILED_EXAMPLES=()
44+
45+
# Find all .js files in examples directory, excluding generalFormPDEScript
46+
for file in $(find examples -name "*.js" -type f | grep -v "generalFormPDEScript" | sort); do
47+
TOTAL=$((TOTAL + 1))
48+
LOG_FILE="${file%.js}.log"
49+
echo ""
50+
echo "▶ Running: $file"
51+
echo "----------------------------------------"
52+
53+
# Run the example and capture output to log file
54+
if timeout 300 node "$file" > "$LOG_FILE" 2>&1; then
55+
echo "✓ PASSED: $file"
56+
PASSED=$((PASSED + 1))
57+
# Show a preview of the output
58+
echo "Output preview:"
59+
head -n 5 "$LOG_FILE" | sed 's/^/ /'
60+
if [ $(wc -l < "$LOG_FILE") -gt 5 ]; then
61+
echo " ... (see $LOG_FILE for full output)"
62+
fi
63+
else
64+
EXIT_CODE=$?
65+
echo "✗ FAILED: $file (exit code: $EXIT_CODE)"
66+
FAILED=$((FAILED + 1))
67+
FAILED_EXAMPLES+=("$file")
68+
# Show error output for failed tests
69+
echo "Error output:"
70+
tail -n 20 "$LOG_FILE" | sed 's/^/ /'
71+
fi
72+
echo "----------------------------------------"
73+
done
74+
75+
# Print summary
76+
echo ""
77+
echo "=========================================="
78+
echo "Test Summary"
79+
echo "=========================================="
80+
echo "Total examples run: $TOTAL"
81+
echo "Passed: $PASSED"
82+
echo "Failed: $FAILED"
83+
echo ""
84+
85+
# If there are failures, list them
86+
if [ $FAILED -gt 0 ]; then
87+
echo "Failed examples:"
88+
for failed in "${FAILED_EXAMPLES[@]}"; do
89+
echo " - $failed"
90+
done
91+
echo ""
92+
exit 1
93+
else
94+
echo "All examples passed successfully! ✓"
95+
fi
96+
97+
- name: Upload test results on failure
98+
if: failure()
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: test-results-node-${{ matrix.node-version }}
102+
path: |
103+
examples/**/*.log
104+
examples/**/*.out
105+
retention-days: 7
106+
if-no-files-found: ignore

0 commit comments

Comments
 (0)