|
20 | 20 | branches: [main] |
21 | 21 | paths: |
22 | 22 | - 'bazel/rules/rules_score/docs/**' |
| 23 | + - 'coverage/**' |
23 | 24 | - '.github/workflows/deploy_docs.yml' |
24 | 25 | workflow_dispatch: |
25 | 26 | permissions: |
26 | 27 | contents: write # needed for uploading release assets |
27 | 28 | pages: write |
28 | 29 | id-token: write |
| 30 | + pull-requests: write # needed for posting PR comments |
29 | 31 | concurrency: |
30 | 32 | group: "pages" |
31 | 33 | cancel-in-progress: false |
|
64 | 66 | - name: Build Sphinx documentation |
65 | 67 | run: bazel build //bazel/rules/rules_score:rules_score_doc |
66 | 68 | - 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" |
68 | 77 | - name: Prepare documentation output |
69 | 78 | run: | |
70 | 79 | BAZEL_BIN="$(bazel info bazel-bin)" |
@@ -102,6 +111,41 @@ jobs: |
102 | 111 | fi |
103 | 112 | echo "Documentation built successfully" |
104 | 113 | 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 | + }); |
105 | 149 | - name: Upload docs to release |
106 | 150 | if: startsWith(github.ref, 'refs/tags/v') |
107 | 151 | env: |
|
0 commit comments