Skip to content

Commit 1af9b07

Browse files
committed
fix: generate coverage once in deploy_docs, add PR comment with stats
1 parent adb7b22 commit 1af9b07

2 files changed

Lines changed: 45 additions & 23 deletions

File tree

.github/workflows/deploy_docs.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ on:
2020
branches: [main]
2121
paths:
2222
- 'bazel/rules/rules_score/docs/**'
23+
- 'coverage/**'
2324
- '.github/workflows/deploy_docs.yml'
2425
workflow_dispatch:
2526
permissions:
2627
contents: write # needed for uploading release assets
2728
pages: write
2829
id-token: write
30+
pull-requests: write # needed for posting PR comments
2931
concurrency:
3032
group: "pages"
3133
cancel-in-progress: false
@@ -64,7 +66,14 @@ jobs:
6466
- name: Build Sphinx documentation
6567
run: bazel build //bazel/rules/rules_score:rules_score_doc
6668
- name: Generate combined coverage report
67-
run: bazel run //coverage:combined_report -- --out-dir coverage-html
69+
id: coverage
70+
run: |
71+
COVERAGE_OUTPUT=$(bazel run //coverage:combined_report -- --out-dir coverage-html 2>&1)
72+
echo "${COVERAGE_OUTPUT}"
73+
LINES=$(echo "${COVERAGE_OUTPUT}" | grep -oP 'lines\.+: \K[\d.]+%' | head -1 | tr -d '\n' || echo 'N/A')
74+
FUNCTIONS=$(echo "${COVERAGE_OUTPUT}" | grep -oP 'functions\.+: \K[\d.]+%' | head -1 | tr -d '\n' || echo 'N/A')
75+
echo "lines=${LINES}" >> "$GITHUB_OUTPUT"
76+
echo "functions=${FUNCTIONS}" >> "$GITHUB_OUTPUT"
6877
- name: Prepare documentation output
6978
run: |
7079
BAZEL_BIN="$(bazel info bazel-bin)"
@@ -102,6 +111,41 @@ jobs:
102111
fi
103112
echo "Documentation built successfully"
104113
find docs_output -type f | wc -l | xargs -I{} echo "Total files: {}"
114+
- name: Upload coverage report artifact
115+
if: always()
116+
id: upload-coverage
117+
uses: actions/upload-artifact@v4
118+
with:
119+
name: coverage-report
120+
path: coverage-html/
121+
- name: Post coverage summary to PR
122+
if: github.event_name == 'pull_request'
123+
continue-on-error: true
124+
uses: actions/github-script@v7
125+
with:
126+
script: |
127+
const lines = '${{ steps.coverage.outputs.lines }}';
128+
const functions = '${{ steps.coverage.outputs.functions }}';
129+
const runUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`;
130+
const body = [
131+
'## Coverage Report',
132+
'',
133+
'Coverage report was generated.',
134+
'',
135+
`**Full report** can be downloaded from the [CI artifacts](${runUrl}) (expand **Artifacts** at the bottom of the run).`,
136+
'',
137+
'**Overall coverage rate:**',
138+
'```',
139+
`lines......: ${lines}`,
140+
`functions......: ${functions}`,
141+
'```'
142+
].join('\n');
143+
github.rest.issues.createComment({
144+
issue_number: context.issue.number,
145+
owner: context.repo.owner,
146+
repo: context.repo.repo,
147+
body: body
148+
});
105149
- name: Upload docs to release
106150
if: startsWith(github.ref, 'refs/tags/v')
107151
env:

.github/workflows/tests.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,3 @@ jobs:
5757
- name: Ensure correct dependency resolution
5858
run: |
5959
bazel mod deps --lockfile_mode=update
60-
coverage:
61-
runs-on: ubuntu-latest
62-
steps:
63-
- name: Checkout repository
64-
uses: actions/checkout@v6.0.2
65-
- name: Setup Bazel with cache
66-
uses: bazel-contrib/setup-bazel@0.19.0
67-
with:
68-
disk-cache: true
69-
repository-cache: true
70-
bazelisk-cache: true
71-
- name: Install lcov
72-
run: |
73-
sudo apt-get update
74-
sudo apt-get install -y lcov
75-
- name: Generate combined coverage report
76-
run: bazel run //coverage:combined_report -- --out-dir coverage-html
77-
- name: Upload coverage report artifact
78-
uses: actions/upload-artifact@v4
79-
with:
80-
name: coverage-report
81-
path: coverage-html/

0 commit comments

Comments
 (0)