-
-
Notifications
You must be signed in to change notification settings - Fork 34
84 lines (68 loc) · 2.79 KB
/
pull_request_apicolombia.yml
File metadata and controls
84 lines (68 loc) · 2.79 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Build and test - ApiColombia
on:
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: api.Tests
steps:
- uses: actions/checkout@v4
- name: Set up .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build with dotnet
run: dotnet build --configuration Release --no-restore
- name: Run tests with coverage
run: dotnet test --no-build --configuration Release --settings ./coverlet.runsettings --collect:"XPlat Code Coverage" --logger trx --results-directory ../TestResults /p:CollectCoverage=true /p:CoverletOutput=../TestResults/ /p:CoverletOutputFormat=json
- name: Verify coverage file exists
working-directory: ./
run: |
echo "Current directory: $(pwd)"
echo "Looking for coverage file at: $(pwd)/TestResults/coverage.json"
ls -la TestResults/ || echo "Directory listing failed"
[ -f TestResults/coverage.json ] || (echo "##[error]Coverage file not found in $(pwd)/TestResults/" && exit 1)
- name: Calculate coverage percentage
working-directory: ./
id: coverage
run: |
# Install jq if missing
command -v jq >/dev/null || sudo apt-get install -y jq
# Safely calculate coverage (handles null values)
TOTAL_LINES=$(jq '[.Modules[].Lines? | select(.!=null) | length] | add' TestResults/coverage.json || echo "0")
COVERED_LINES=$(jq '[.Modules[].Lines? | select(.!=null) | map(select(. > 0)) | length] | add' TestResults/coverage.json || echo "0")
# Default to 0 if no valid data
[ -z "$TOTAL_LINES" ] && TOTAL_LINES=0
[ -z "$COVERED_LINES" ] && COVERED_LINES=0
# Calculate percentage (avoid division by zero)
if [ "$TOTAL_LINES" -gt 0 ]; then
PERCENT=$(echo "scale=0; $COVERED_LINES * 100 / $TOTAL_LINES" | bc)
else
PERCENT=0
fi
echo "coverage_percentage=$PERCENT" >> $GITHUB_OUTPUT
echo "Coverage: $PERCENT% ($COVERED_LINES/$TOTAL_LINES lines)"
- name: Upload Coverage Metadata
uses: actions/upload-artifact@v4
with:
name: coverage-meta
path: TestResults/coverage.json
- name: Publish coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: CoverageReport
- name: Publish test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: TestResults