#145 Enforce unit test naming to snake case #358
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: Test Coverage | |
| on: | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| branches: | |
| - master | |
| permissions: | |
| actions: write | |
| checks: read | |
| contents: write | |
| deployments: write | |
| issues: read | |
| packages: read | |
| pages: read | |
| pull-requests: write | |
| repository-projects: read | |
| security-events: read | |
| statuses: read | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Clean | |
| run: ./gradlew clean | |
| - name: Build and test | |
| run: ./gradlew build test --parallel | |
| - name: Generate JaCoCo Badge | |
| id: jacoco | |
| uses: cicirello/[email protected] | |
| with: | |
| generate-branches-badge: true | |
| jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv | |
| - name: Log test coverage percentage | |
| run: | | |
| echo "Coverage = ${{ steps.jacoco.outputs.coverage }}" | |
| echo "Branch coverage = ${{ steps.jacoco.outputs.branches }}" | |
| - name: Check coverage delta | |
| id: coverage_check | |
| run: | | |
| # Get current coverage (already a decimal) | |
| CURRENT_COV="${{ steps.jacoco.outputs.coverage }}" | |
| PREVIOUS_COV=$(git show HEAD~1:.coverage_history 2>/dev/null || echo "") | |
| if [ -z "$PREVIOUS_COV" ]; then | |
| echo "No previous coverage found. Skipping delta check." | |
| echo "$CURRENT_COV" > .coverage_history | |
| exit 0 | |
| fi | |
| # Calculate delta using awk for floating point arithmetic | |
| DELTA=$(awk -v current="$CURRENT_COV" -v previous="$PREVIOUS_COV" 'BEGIN { printf "%.4f", (current - previous) * 100 }') | |
| ABS_DELTA=$(awk -v delta="$DELTA" 'BEGIN { print (delta < 0) ? -delta : delta }') | |
| echo "Current coverage: $(awk -v cov="$CURRENT_COV" 'BEGIN { printf "%.2f", cov * 100 }')%" | |
| echo "Previous coverage: $(awk -v cov="$PREVIOUS_COV" 'BEGIN { printf "%.2f", cov * 100 }')%" | |
| echo "Delta: $DELTA%" | |
| # Fail if coverage drops by more than 1% | |
| if [ $(echo "$DELTA < -1.0" | bc -l) -eq 1 ]; then | |
| echo "Coverage dropped by more than 1% (from $(awk -v cov="$PREVIOUS_COV" 'BEGIN { printf "%.2f", cov * 100 }')% to $(awk -v cov="$CURRENT_COV" 'BEGIN { printf "%.2f", cov * 100 }')%)" | |
| exit 1 | |
| fi | |
| # Update history file if not a PR | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| echo "$CURRENT_COV" > .coverage_history | |
| fi | |
| - name: Commit and push the badge and history | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
| uses: EndBug/[email protected] | |
| with: | |
| author_name: github_actions | |
| author_email: 41898282+github-actions[bot]@users.noreply.github.com | |
| message: '#0 Update test coverage badge and history' | |
| add: '*.svg .coverage_history' | |
| - name: Upload JaCoCo coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jacoco-report | |
| path: target/site/jacoco/ |