|
| 1 | +name: Code-Coverage LCOV |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: [ master, 'v*-branch' ] |
| 7 | + merge_group: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.ref }}-coverage-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +env: |
| 19 | + CHIP_NO_LOG_TIMESTAMPS: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + linux-coverage: |
| 23 | + name: Coverage |
| 24 | + if: github.actor != 'restyled-io[bot]' |
| 25 | + |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + container: |
| 29 | + image: ghcr.io/project-chip/chip-build:167 |
| 30 | + volumes: |
| 31 | + - "/:/runner-root-volume" |
| 32 | + - "/tmp/log_output:/tmp/test_logs" |
| 33 | + options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1" |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: | |
| 41 | + apt-get update |
| 42 | + apt-get install -y jq lcov |
| 43 | + apt-get install -y libglib2.0-dev libdbus-1-dev |
| 44 | + |
| 45 | + - name: Checkout submodules & Bootstrap |
| 46 | + uses: ./.github/actions/checkout-submodules-and-bootstrap |
| 47 | + with: |
| 48 | + platform: linux |
| 49 | + bootstrap-log-name: bootstrap-logs-codecov-${{ matrix.type }} |
| 50 | + |
| 51 | + - name: Run Build Coverage |
| 52 | + run: ./scripts/build_coverage.sh --yaml --xml |
| 53 | + |
| 54 | + - name: Generate Coverage Summary |
| 55 | + run: | |
| 56 | + # Generate a human-readable coverage summary |
| 57 | + lcov --summary out/coverage/coverage/coverage.info > coverage-summary.txt 2>&1 || true |
| 58 | + |
| 59 | + # Extract key metrics from the XML file |
| 60 | + if [ -f "out/coverage/coverage/coverage.xml" ]; then |
| 61 | + python3 -c ' |
| 62 | + import xml.etree.ElementTree as ET |
| 63 | + import sys |
| 64 | + |
| 65 | + try: |
| 66 | + tree = ET.parse("out/coverage/coverage/coverage.xml") |
| 67 | + root = tree.getroot() |
| 68 | + |
| 69 | + # Find coverage metrics |
| 70 | + for coverage in root.findall(".//coverage"): |
| 71 | + line_rate = coverage.get("line-rate", "0") |
| 72 | + branch_rate = coverage.get("branch-rate", "0") |
| 73 | + lines_covered = coverage.get("lines-covered", "0") |
| 74 | + lines_valid = coverage.get("lines-valid", "0") |
| 75 | + branches_covered = coverage.get("branches-covered", "0") |
| 76 | + branches_valid = coverage.get("branches-valid", "0") |
| 77 | + |
| 78 | + print(f"## 📊 Coverage Report") |
| 79 | + print(f"") |
| 80 | + print(f"**Overall Coverage Metrics:**") |
| 81 | + print(f"- **Line Coverage:** {float(line_rate)*100:.1f}% ({lines_covered}/{lines_valid} lines)") |
| 82 | + print(f"- **Branch Coverage:** {float(branch_rate)*100:.1f}% ({branches_covered}/{branches_valid} branches)") |
| 83 | + print(f"") |
| 84 | + print(f"📁 **Available Reports:**") |
| 85 | + print(f"- 📋 Coverage XML (machine-readable)") |
| 86 | + print(f"- 📊 Coverage HTML (interactive report)") |
| 87 | + print(f"- 📄 Coverage Info (LCOV format)") |
| 88 | + print(f"- 📝 Coverage Summary (text)") |
| 89 | + break |
| 90 | + except Exception as e: |
| 91 | + print(f"## 📊 Coverage Report") |
| 92 | + print(f"❌ Error parsing coverage data: {e}") |
| 93 | + ' > coverage-report.md |
| 94 | + fi |
| 95 | +
|
| 96 | + - name: Upload Coverage Artifacts |
| 97 | + uses: actions/upload-artifact@v4 |
| 98 | + with: |
| 99 | + name: coverage-report-${{ matrix.type }} |
| 100 | + path: | |
| 101 | + out/coverage/coverage/coverage.xml |
| 102 | + out/coverage/coverage/coverage.info |
| 103 | + out/coverage/coverage/html/** |
| 104 | + coverage-summary.txt |
| 105 | + coverage-report.md |
| 106 | + retention-days: 30 |
| 107 | + |
| 108 | + - name: Comment Coverage Report on PR |
| 109 | + if: github.event_name == 'pull_request' |
| 110 | + uses: actions/github-script@v7 |
| 111 | + with: |
| 112 | + script: | |
| 113 | + const fs = require('fs'); |
| 114 | + |
| 115 | + let coverageReport = ''; |
| 116 | + try { |
| 117 | + coverageReport = fs.readFileSync('coverage-report.md', 'utf8'); |
| 118 | + } catch (error) { |
| 119 | + coverageReport = '## 📊 Coverage Report\n❌ Could not generate coverage report'; |
| 120 | + } |
| 121 | + |
| 122 | + // Add artifact download instructions |
| 123 | + const artifactMessage = ` |
| 124 | + |
| 125 | + ## 📎 How to Access Coverage Reports: |
| 126 | +
|
| 127 | + 1. **Download Artifacts:** Go to the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) and download \`coverage-report-${{ matrix.type }}\` |
| 128 | + 2. **View HTML Report:** Extract the artifact and open \`html/index.html\` in your browser for interactive coverage analysis |
| 129 | + 3. **Machine Processing:** Use \`coverage.xml\` (Cobertura format) or \`coverage.info\` (LCOV format) for tooling integration |
| 130 | +
|
| 131 | + --- |
| 132 | + *Coverage report updated on: ${new Date().toISOString()}* |
| 133 | + `; |
| 134 | + |
| 135 | + const body = coverageReport + artifactMessage; |
| 136 | + |
| 137 | + // Find existing coverage comment |
| 138 | + const comments = await github.rest.issues.listComments({ |
| 139 | + owner: context.repo.owner, |
| 140 | + repo: context.repo.repo, |
| 141 | + issue_number: context.issue.number, |
| 142 | + }); |
| 143 | + |
| 144 | + const botComment = comments.data.find(comment => |
| 145 | + comment.user.type === 'Bot' && |
| 146 | + comment.body.includes('📊 Coverage Report') |
| 147 | + ); |
| 148 | + |
| 149 | + if (botComment) { |
| 150 | + // Update existing comment |
| 151 | + await github.rest.issues.updateComment({ |
| 152 | + owner: context.repo.owner, |
| 153 | + repo: context.repo.repo, |
| 154 | + comment_id: botComment.id, |
| 155 | + body: body |
| 156 | + }); |
| 157 | + } else { |
| 158 | + // Create new comment |
| 159 | + await github.rest.issues.createComment({ |
| 160 | + owner: context.repo.owner, |
| 161 | + repo: context.repo.repo, |
| 162 | + issue_number: context.issue.number, |
| 163 | + body: body |
| 164 | + }); |
| 165 | + } |
0 commit comments