@@ -25,17 +25,65 @@ jobs:
2525 env :
2626 COMPOSER_AUTH : ${{ secrets.COMPOSER_AUTH }}
2727 run : composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
28+
29+ - name : Restore Baseline Coverage Cache
30+ uses : actions/cache/restore@v4
31+ id : cache-baseline
32+ with :
33+ path : baseline-type-coverage.txt
34+ key : type-coverage-baseline-master
35+
2836 - name : Run Type Coverage
2937 run : |
3038 ./vendor/bin/pest --type-coverage --min=0 > type-coverage.txt
3139 cat type-coverage.txt
40+
3241 - name : Extract Coverage Percentage
3342 id : coverage
3443 run : |
3544 COVERAGE=$(grep -oP 'Total: \K[0-9.]+' type-coverage.txt || echo "0")
3645 echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
3746 echo "Type Coverage: $COVERAGE%"
47+
48+ - name : Compare Coverage Against Baseline
49+ if : github.event_name == 'pull_request'
50+ run : |
51+ CURRENT_COVERAGE=${{ steps.coverage.outputs.percentage }}
52+
53+ if [ -f baseline-type-coverage.txt ]; then
54+ BASELINE_COVERAGE=$(cat baseline-type-coverage.txt)
55+ echo "📊 Current Coverage: $CURRENT_COVERAGE%"
56+ echo "📈 Baseline Coverage: $BASELINE_COVERAGE%"
57+
58+ # Use bc for floating point comparison
59+ if (( $(echo "$CURRENT_COVERAGE < $BASELINE_COVERAGE" | bc -l) )); then
60+ DIFF=$(echo "$BASELINE_COVERAGE - $CURRENT_COVERAGE" | bc -l)
61+ echo "❌ Type coverage decreased by $DIFF%"
62+ echo "::error::Type coverage dropped from $BASELINE_COVERAGE% to $CURRENT_COVERAGE%. Please add type declarations."
63+ exit 1
64+ else
65+ DIFF=$(echo "$CURRENT_COVERAGE - $BASELINE_COVERAGE" | bc -l)
66+ echo "✅ Type coverage maintained or improved (+$DIFF%)"
67+ fi
68+ else
69+ echo "⚠️ No baseline coverage found. Skipping comparison."
70+ echo "::warning::No baseline type coverage found. Baseline will be established when merged to master."
71+ fi
72+
73+ - name : Save Baseline Coverage to File
74+ if : github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'HDInnovations/UNIT3D'
75+ run : |
76+ echo "${{ steps.coverage.outputs.percentage }}" > baseline-type-coverage.txt
77+
78+ - name : Save Baseline Coverage Cache
79+ if : github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'HDInnovations/UNIT3D'
80+ uses : actions/cache/save@v4
81+ with :
82+ path : baseline-type-coverage.txt
83+ key : type-coverage-baseline-master
84+
3885 - name : Create Coverage Badge
86+ if : github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'HDInnovations/UNIT3D'
3987 uses : schneegans/dynamic-badges-action@v1.7.0
4088 with :
4189 auth : ${{ secrets.GIST_SECRET }}
0 commit comments