forked from multiversx/mx-bridge-eth-go
-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (60 loc) · 2.32 KB
/
code-coverage.yml
File metadata and controls
70 lines (60 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Code-coverage
on:
push:
branches:
- main
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
name: Build
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Go Setup
uses: ./.github/actions/go-setup-action
with:
go-version: ${{vars.GO_VERSION }}
go-private: ${{vars.GO_PRIVATE_REPO }}
git-user: ${{ secrets.GIT_USER }}
git-pass: ${{ secrets.GIT_PASS }}
- name: Run unit tests
id: run-tests
run: |
set +e
make test-coverage
echo "test_exit_code=$?" >> "$GITHUB_OUTPUT"
# Always succeed so that the next step can evaluate the results
exit 0
- name: Process test results
if: always()
id: coverage
run: |
# Generate coverage summary
if [ -f coverage.out ]; then
go tool cover -func=coverage.out > coverage-summary.txt
COVERAGE=$(grep "total:" coverage-summary.txt | awk '{print $3}')
echo "total=$COVERAGE" >> $GITHUB_OUTPUT
else
echo "No coverage data generated" > coverage-summary.txt
echo "total=0.0%" >> $GITHUB_OUTPUT
fi
# Create test summary and check for failures
echo "### Test Results 🧪" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.run-tests.outputs.test_exit_code }}" == "0" ]; then
echo "✅ All tests passed successfully" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Some tests failed" >> $GITHUB_STEP_SUMMARY
echo "::error::🔴 Test failures detected!"
if [ -f test-output.json ]; then
echo "#### Failed Tests" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
jq -r 'select(.Action=="fail") | "- \(.Package) - \(.Test)"' test-output.json | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# Output failures as GitHub annotations
jq -r 'select(.Action=="fail") | "::error file=\(.Package)::❌ \(.Test): \(.Action)"' test-output.json
fi
exit 1
fi
echo "Coverage: $COVERAGE" >> $GITHUB_STEP_SUMMARY