File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Unit Tests
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ permissions :
9+ contents : write
10+
11+ jobs :
12+ test :
13+ runs-on : ubuntu-latest
14+ steps :
15+ - uses : actions/checkout@v3
16+ - name : Install dependencies
17+ run : sudo apt-get update && sudo apt-get install -y make gcc build-essential
18+ - name : Build and run tests
19+ id : runtest
20+ run : |
21+ cd Lab1
22+ make test_checksum
23+ OUTPUT=$(./Lab1 2>&1)
24+ echo "$OUTPUT"
25+ # Parse Unity output: "X Tests Y Failures Z Ignored"
26+ TESTS=$(echo "$OUTPUT" | grep -oP '(?<=\-\-\-\-\-\s)\d+(?=\sTests)' || echo "0")
27+ FAILURES=$(echo "$OUTPUT" | grep -oP '\d+(?= Failures)' || echo "0")
28+ PASSED=$((TESTS - FAILURES))
29+ echo "tests=$TESTS" >> $GITHUB_OUTPUT
30+ echo "passed=$PASSED" >> $GITHUB_OUTPUT
31+ echo "failed=$FAILURES" >> $GITHUB_OUTPUT
32+ - name : Update README badge
33+ if : success()
34+ run : |
35+ TESTS=${{ steps.runtest.outputs.tests }}
36+ PASSED=${{ steps.runtest.outputs.passed }}
37+ FAILED=${{ steps.runtest.outputs.failed }}
38+
39+ # Determine color based on test results
40+ if [ "$FAILED" -eq 0 ] && [ "$PASSED" -gt 0 ]; then COLOR="brightgreen"; else COLOR="red"; fi
41+
42+ cd /workspaces/UnitTestinginEmbeddedSystems
43+ sed -i "s|badge/tests-[^-]*-[a-z]*|badge/tests-${PASSED}/${TESTS}-${COLOR}|" README.md
44+
45+ git config user.name "github-actions[bot]"
46+ git config user.email "github-actions[bot]@users.noreply.github.com"
47+ git add README.md
48+ git commit -m "Update test badge to ${PASSED}/${TESTS} passed" || true
49+ git push
Original file line number Diff line number Diff line change 22
33| Build | Unit Test | Coverage |
44| :--:| :--:| :--:|
5- | [ ![ Build] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/build.yml/badge.svg )] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/build.yml ) | [ ![ Unit Test] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/test.yml /badge.svg )] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/test.yml ) | [ ![ Coverage] ( https://img.shields.io/badge/coverage-100.00%25-brightgreen )] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/coverage.yml ) |
5+ | [ ![ Build] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/build.yml/badge.svg )] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/build.yml ) | [ ![ Unit Test] ( https://img.shields.io /badge/tests-0/3-brightgreen )] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/test.yml ) | [ ![ Coverage] ( https://img.shields.io/badge/coverage-100.00%25-brightgreen )] ( https://github.com/TechEvents-FOSS/UnitTestinginEmbeddedSystems/actions/workflows/coverage.yml ) |
66
77### Running the examples locally
88The ` Lab1 ` subproject includes a simple ` Makefile ` that can be used on Linux/WSL:
You can’t perform that action at this time.
0 commit comments