Fixed unit test action path issues #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Unit Tests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install dependencies | |
| run: sudo apt-get update && sudo apt-get install -y make gcc build-essential | |
| - name: Build and run tests | |
| id: runtest | |
| run: | | |
| cd Lab1 | |
| make test_checksum | |
| OUTPUT=$(./Lab1 2>&1) | |
| echo "$OUTPUT" | |
| # Parse Unity output: "X Tests Y Failures Z Ignored" | |
| TESTS=$(echo "$OUTPUT" | grep -oP '(?<=\-\-\-\-\-\s)\d+(?=\sTests)' || echo "0") | |
| FAILURES=$(echo "$OUTPUT" | grep -oP '\d+(?= Failures)' || echo "0") | |
| PASSED=$((TESTS - FAILURES)) | |
| echo "tests=$TESTS" >> $GITHUB_OUTPUT | |
| echo "passed=$PASSED" >> $GITHUB_OUTPUT | |
| echo "failed=$FAILURES" >> $GITHUB_OUTPUT | |
| - name: Update README badge | |
| if: success() | |
| run: | | |
| TESTS=${{ steps.runtest.outputs.tests }} | |
| PASSED=${{ steps.runtest.outputs.passed }} | |
| FAILED=${{ steps.runtest.outputs.failed }} | |
| # Determine color based on test results | |
| if [ "$FAILED" -eq 0 ] && [ "$PASSED" -gt 0 ]; then COLOR="brightgreen"; else COLOR="red"; fi | |
| sed -i "s|badge/tests-[^-]*-[a-z]*|badge/tests-${PASSED}/${TESTS}-${COLOR}|" README.md | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add README.md | |
| git commit -m "Update test badge to ${PASSED}/${TESTS} passed" || true | |
| git push |