|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + |
| 9 | +env: |
| 10 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 |
| 11 | + DOTNET_NOLOGO: true |
| 12 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-test: |
| 16 | + name: Build and Test (${{ matrix.os }}, ${{ matrix.framework }}) |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 23 | + framework: [net8.0, net9.0] |
| 24 | + include: |
| 25 | + - os: windows-latest |
| 26 | + framework: net462 |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Setup .NET |
| 35 | + uses: actions/setup-dotnet@v4 |
| 36 | + with: |
| 37 | + dotnet-version: | |
| 38 | + 8.0.x |
| 39 | + 9.0.x |
| 40 | +
|
| 41 | + - name: Restore dependencies |
| 42 | + run: dotnet restore |
| 43 | + |
| 44 | + - name: Build |
| 45 | + run: dotnet build --no-restore --configuration Release |
| 46 | + |
| 47 | + - name: Test with Coverage |
| 48 | + run: | |
| 49 | + dotnet test --no-build --configuration Release \ |
| 50 | + --verbosity normal \ |
| 51 | + --collect:"XPlat Code Coverage" \ |
| 52 | + --results-directory ./coverage \ |
| 53 | + --logger trx \ |
| 54 | + --logger "console;verbosity=detailed" \ |
| 55 | + --settings tests/TaglibSharp.Tests/MSTest.runsettings \ |
| 56 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover |
| 57 | +
|
| 58 | + - name: Install ReportGenerator |
| 59 | + if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net8.0' |
| 60 | + run: dotnet tool install -g dotnet-reportgenerator-globaltool |
| 61 | + |
| 62 | + - name: Generate Coverage Report |
| 63 | + if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net8.0' |
| 64 | + run: | |
| 65 | + reportgenerator \ |
| 66 | + -reports:"coverage/**/coverage.opencover.xml" \ |
| 67 | + -targetdir:"coverage/report" \ |
| 68 | + -reporttypes:"Html;TextSummary;Badges;Cobertura;JsonSummary" \ |
| 69 | + -verbosity:Info \ |
| 70 | + -classfilters:"-*.Tests*;-*.Benchmarks*" \ |
| 71 | + -filefilters:"-**/bin/**;-**/obj/**" |
| 72 | +
|
| 73 | + - name: Coverage Summary |
| 74 | + if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net8.0' |
| 75 | + run: | |
| 76 | + echo "📊 Coverage Summary:" |
| 77 | + cat coverage/report/Summary.txt |
| 78 | + echo "" |
| 79 | +
|
| 80 | + # Extract coverage percentage for status check |
| 81 | + if [ -f "coverage/report/Summary.json" ]; then |
| 82 | + echo "📈 Detailed Coverage Metrics:" |
| 83 | + cat coverage/report/Summary.json | jq '.summary' |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Coverage Threshold Check |
| 87 | + if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net8.0' |
| 88 | + run: | |
| 89 | + # Run the coverage validation tests |
| 90 | + dotnet test --no-build --configuration Release \ |
| 91 | + --filter "TestCategory=Coverage" \ |
| 92 | + --logger "console;verbosity=detailed" |
| 93 | +
|
| 94 | + - name: Upload coverage reports to Codecov |
| 95 | + if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net8.0' |
| 96 | + uses: codecov/codecov-action@v4 |
| 97 | + with: |
| 98 | + directory: ./coverage |
| 99 | + files: ./coverage/report/Cobertura.xml |
| 100 | + fail_ci_if_error: true |
| 101 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 102 | + flags: unittests |
| 103 | + name: taglib-sharp-coverage |
| 104 | + |
| 105 | + - name: Upload Coverage Artifacts |
| 106 | + if: matrix.os == 'ubuntu-latest' && matrix.framework == 'net8.0' |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: coverage-report |
| 110 | + path: coverage/report/ |
| 111 | + |
| 112 | + - name: Test Result Analysis |
| 113 | + if: always() |
| 114 | + run: | |
| 115 | + echo "📋 Test Results Summary:" |
| 116 | + find ./coverage -name "*.trx" -exec echo "Processing {}" \; |
| 117 | +
|
| 118 | + # Count test results |
| 119 | + if [ -d "./coverage" ]; then |
| 120 | + echo "✅ Test artifacts generated successfully" |
| 121 | + find ./coverage -name "*.xml" -o -name "*.trx" | wc -l | xargs echo "Coverage files found:" |
| 122 | + fi |
| 123 | +
|
| 124 | + quality-gates: |
| 125 | + name: Quality Gates |
| 126 | + runs-on: ubuntu-latest |
| 127 | + needs: build-and-test |
| 128 | + |
| 129 | + steps: |
| 130 | + - name: Checkout |
| 131 | + uses: actions/checkout@v4 |
| 132 | + |
| 133 | + - name: Setup .NET |
| 134 | + uses: actions/setup-dotnet@v4 |
| 135 | + with: |
| 136 | + dotnet-version: | |
| 137 | + 8.0.x |
| 138 | + 9.0.x |
| 139 | +
|
| 140 | + - name: Download Coverage Report |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + name: coverage-report |
| 144 | + path: ./coverage-report |
| 145 | + |
| 146 | + - name: Quality Gate - Coverage Threshold |
| 147 | + run: | |
| 148 | + if [ -f "./coverage-report/Summary.txt" ]; then |
| 149 | + echo "📊 Coverage Summary:" |
| 150 | + cat ./coverage-report/Summary.txt |
| 151 | +
|
| 152 | + # Extract line coverage percentage using more robust regex |
| 153 | + COVERAGE=$(grep -oP 'Line coverage:\s*\K[\d.]+' ./coverage-report/Summary.txt || echo "0") |
| 154 | + echo "📈 Line Coverage: ${COVERAGE}%" |
| 155 | +
|
| 156 | + # Extract branch coverage if available |
| 157 | + BRANCH_COVERAGE=$(grep -oP 'Branch coverage:\s*\K[\d.]+' ./coverage-report/Summary.txt || echo "0") |
| 158 | + echo "🌿 Branch Coverage: ${BRANCH_COVERAGE}%" |
| 159 | +
|
| 160 | + # Set thresholds |
| 161 | + LINE_THRESHOLD=80 |
| 162 | + BRANCH_THRESHOLD=70 |
| 163 | +
|
| 164 | + # Validate coverage thresholds |
| 165 | + if (( $(echo "$COVERAGE >= $LINE_THRESHOLD" | bc -l) )); then |
| 166 | + echo "✅ Line coverage ${COVERAGE}% meets ${LINE_THRESHOLD}% threshold" |
| 167 | + else |
| 168 | + echo "❌ Line coverage ${COVERAGE}% is below ${LINE_THRESHOLD}% threshold" |
| 169 | + exit 1 |
| 170 | + fi |
| 171 | +
|
| 172 | + if (( $(echo "$BRANCH_COVERAGE >= $BRANCH_THRESHOLD" | bc -l) )); then |
| 173 | + echo "✅ Branch coverage ${BRANCH_COVERAGE}% meets ${BRANCH_THRESHOLD}% threshold" |
| 174 | + else |
| 175 | + echo "⚠️ Branch coverage ${BRANCH_COVERAGE}% is below ${BRANCH_THRESHOLD}% threshold (warning only)" |
| 176 | + fi |
| 177 | + else |
| 178 | + echo "❌ Coverage report not found" |
| 179 | + exit 1 |
| 180 | + fi |
| 181 | +
|
| 182 | + - name: Generate Coverage Badge |
| 183 | + run: | |
| 184 | + if [ -f "./coverage-report/Summary.json" ]; then |
| 185 | + echo "🏷️ Coverage badge data available" |
| 186 | + # This could be used to update a coverage badge |
| 187 | + fi |
| 188 | +
|
| 189 | + package: |
| 190 | + name: Package |
| 191 | + runs-on: ubuntu-latest |
| 192 | + needs: [build-and-test, quality-gates] |
| 193 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 194 | + |
| 195 | + steps: |
| 196 | + - name: Checkout |
| 197 | + uses: actions/checkout@v4 |
| 198 | + with: |
| 199 | + fetch-depth: 0 |
| 200 | + |
| 201 | + - name: Setup .NET |
| 202 | + uses: actions/setup-dotnet@v4 |
| 203 | + with: |
| 204 | + dotnet-version: | |
| 205 | + 8.0.x |
| 206 | + 9.0.x |
| 207 | +
|
| 208 | + - name: Restore dependencies |
| 209 | + run: dotnet restore |
| 210 | + |
| 211 | + - name: Pack |
| 212 | + run: dotnet pack --configuration Release --no-restore --output ./packages |
| 213 | + |
| 214 | + - name: Upload packages |
| 215 | + uses: actions/upload-artifact@v4 |
| 216 | + with: |
| 217 | + name: nuget-packages |
| 218 | + path: ./packages/*.nupkg |
0 commit comments