From ce78ae631f947884c62423cf75f4a22f368522a4 Mon Sep 17 00:00:00 2001 From: Taehoon Moon Date: Tue, 7 Oct 2025 21:30:13 +0900 Subject: [PATCH 1/3] Add coverage summary to coverage bot comment --- .github/workflows/publish-coverage.yml | 62 +++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-coverage.yml b/.github/workflows/publish-coverage.yml index cdc3db0c..cafb7786 100644 --- a/.github/workflows/publish-coverage.yml +++ b/.github/workflows/publish-coverage.yml @@ -77,6 +77,56 @@ jobs: path: coverage github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Extract coverage summary + run: | + xz -dc coverage/lcov.info.xz > coverage/lcov.info + python3 - <<'PY' +import os + +lf_hits = 0 +lf_found = 0 +da_hits = 0 +da_found = 0 + +with open("coverage/lcov.info") as handle: + for raw_line in handle: + line = raw_line.strip() + if line.startswith("LF:"): + try: + lf_found += int(line[3:]) + except ValueError: + pass + elif line.startswith("LH:"): + try: + lf_hits += int(line[3:]) + except ValueError: + pass + elif line.startswith("DA:"): + parts = line[3:].split(",") + if len(parts) >= 2: + da_found += 1 + try: + count = int(parts[1]) + except ValueError: + count = 0 + if count > 0: + da_hits += 1 + +if lf_found == 0: + lf_found, lf_hits = da_found, da_hits + +coverage = 0.0 if lf_found == 0 else (lf_hits / lf_found) * 100.0 + +env_path = os.environ.get("GITHUB_ENV") +if env_path: + with open(env_path, "a") as env_file: + env_file.write(f"LINE_COVERAGE={coverage:.2f}\n") + env_file.write(f"LINE_HITS={lf_hits}\n") + env_file.write(f"LINE_FOUND={lf_found}\n") + +print(f"Line coverage: {coverage:.2f}% ({lf_hits}/{lf_found})") +PY + - name: Set timestamp run: echo "TIMESTAMP=$(date -u +'%Y-%m-%dT%H%M%SZ')" >> $GITHUB_ENV @@ -99,13 +149,23 @@ jobs: script: | const prNumber = process.env.PR_NUMBER; const url = `https://gluesql.org/coverage/?path=glues/pr/${prNumber}/${process.env.TIMESTAMP}.${process.env.COMMIT_SHA}.lcov.info.xz`; - const body = [ + let body = [ '### Glues Coverage Report', '', `- **Commit:** \`${process.env.COMMIT_SHA}\``, `- **Timestamp:** \`${process.env.TIMESTAMP}\``, `- **Report:** [View report](${url})` ].join('\n'); + const lineCoverage = process.env.LINE_COVERAGE; + const lineHits = process.env.LINE_HITS; + const lineFound = process.env.LINE_FOUND; + if (lineCoverage) { + const coverageLine = `- **Line Coverage:** ${lineCoverage}% (${lineHits}/${lineFound})`; + if (!body.includes(coverageLine)) { + // Append coverage details once per update + body = [body, coverageLine].join('\n'); + } + } const comments = await github.paginate( github.rest.issues.listComments, { From a1410e0a6726bb99129836bfd748c1e70f72b62c Mon Sep 17 00:00:00 2001 From: Taehoon Moon Date: Tue, 7 Oct 2025 21:57:16 +0900 Subject: [PATCH 2/3] Fix publish coverage workflow indentation --- .github/workflows/publish-coverage.yml | 90 +++++++++++++------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/.github/workflows/publish-coverage.yml b/.github/workflows/publish-coverage.yml index cafb7786..0e4d6cfd 100644 --- a/.github/workflows/publish-coverage.yml +++ b/.github/workflows/publish-coverage.yml @@ -81,51 +81,51 @@ jobs: run: | xz -dc coverage/lcov.info.xz > coverage/lcov.info python3 - <<'PY' -import os - -lf_hits = 0 -lf_found = 0 -da_hits = 0 -da_found = 0 - -with open("coverage/lcov.info") as handle: - for raw_line in handle: - line = raw_line.strip() - if line.startswith("LF:"): - try: - lf_found += int(line[3:]) - except ValueError: - pass - elif line.startswith("LH:"): - try: - lf_hits += int(line[3:]) - except ValueError: - pass - elif line.startswith("DA:"): - parts = line[3:].split(",") - if len(parts) >= 2: - da_found += 1 - try: - count = int(parts[1]) - except ValueError: - count = 0 - if count > 0: - da_hits += 1 - -if lf_found == 0: - lf_found, lf_hits = da_found, da_hits - -coverage = 0.0 if lf_found == 0 else (lf_hits / lf_found) * 100.0 - -env_path = os.environ.get("GITHUB_ENV") -if env_path: - with open(env_path, "a") as env_file: - env_file.write(f"LINE_COVERAGE={coverage:.2f}\n") - env_file.write(f"LINE_HITS={lf_hits}\n") - env_file.write(f"LINE_FOUND={lf_found}\n") - -print(f"Line coverage: {coverage:.2f}% ({lf_hits}/{lf_found})") -PY + import os + + lf_hits = 0 + lf_found = 0 + da_hits = 0 + da_found = 0 + + with open("coverage/lcov.info") as handle: + for raw_line in handle: + line = raw_line.strip() + if line.startswith("LF:"): + try: + lf_found += int(line[3:]) + except ValueError: + pass + elif line.startswith("LH:"): + try: + lf_hits += int(line[3:]) + except ValueError: + pass + elif line.startswith("DA:"): + parts = line[3:].split(",") + if len(parts) >= 2: + da_found += 1 + try: + count = int(parts[1]) + except ValueError: + count = 0 + if count > 0: + da_hits += 1 + + if lf_found == 0: + lf_found, lf_hits = da_found, da_hits + + coverage = 0.0 if lf_found == 0 else (lf_hits / lf_found) * 100.0 + + env_path = os.environ.get("GITHUB_ENV") + if env_path: + with open(env_path, "a") as env_file: + env_file.write(f"LINE_COVERAGE={coverage:.2f}\n") + env_file.write(f"LINE_HITS={lf_hits}\n") + env_file.write(f"LINE_FOUND={lf_found}\n") + + print(f"Line coverage: {coverage:.2f}% ({lf_hits}/{lf_found})") + PY - name: Set timestamp run: echo "TIMESTAMP=$(date -u +'%Y-%m-%dT%H%M%SZ')" >> $GITHUB_ENV From 9b397ff0dd0aa14c3a1de7ee6eb55f315fad59be Mon Sep 17 00:00:00 2001 From: Taehoon Moon Date: Sat, 11 Oct 2025 18:04:59 +0900 Subject: [PATCH 3/3] Reorder line coverage summary --- .github/workflows/publish-coverage.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish-coverage.yml b/.github/workflows/publish-coverage.yml index 0e4d6cfd..f3f0f5d8 100644 --- a/.github/workflows/publish-coverage.yml +++ b/.github/workflows/publish-coverage.yml @@ -149,23 +149,23 @@ jobs: script: | const prNumber = process.env.PR_NUMBER; const url = `https://gluesql.org/coverage/?path=glues/pr/${prNumber}/${process.env.TIMESTAMP}.${process.env.COMMIT_SHA}.lcov.info.xz`; - let body = [ - '### Glues Coverage Report', - '', - `- **Commit:** \`${process.env.COMMIT_SHA}\``, - `- **Timestamp:** \`${process.env.TIMESTAMP}\``, - `- **Report:** [View report](${url})` - ].join('\n'); const lineCoverage = process.env.LINE_COVERAGE; const lineHits = process.env.LINE_HITS; const lineFound = process.env.LINE_FOUND; + const lines = [ + '### Glues Coverage Report', + '', + ]; if (lineCoverage) { - const coverageLine = `- **Line Coverage:** ${lineCoverage}% (${lineHits}/${lineFound})`; - if (!body.includes(coverageLine)) { - // Append coverage details once per update - body = [body, coverageLine].join('\n'); - } + // Surface coverage stats before the rest of the metadata. + lines.push(`- **Line Coverage:** ${lineCoverage}% (${lineHits}/${lineFound})`); } + lines.push( + `- **Commit:** \`${process.env.COMMIT_SHA}\``, + `- **Timestamp:** \`${process.env.TIMESTAMP}\``, + `- **Report:** [View report](${url})`, + ); + const body = lines.join('\n'); const comments = await github.paginate( github.rest.issues.listComments, {