-
-
Notifications
You must be signed in to change notification settings - Fork 29
[#2183] Added posting of coverage to PR. #2184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,6 +381,31 @@ jobs: | |
| include-hidden-files: true | ||
| if-no-files-found: error | ||
|
|
||
| #;< TOOL_PHPUNIT | ||
| - name: Check code coverage threshold | ||
| if: ${{ matrix.instance == 0 || strategy.job-total == 1 }} | ||
| run: | | ||
| RATE=$(grep -o 'line-rate="[0-9.]*"' .logs/coverage/phpunit/cobertura.xml | head -1 | tr -cd '0-9.') | ||
| PERCENT=$(awk "BEGIN {printf \"%.2f\", $RATE*100}") | ||
| echo "Coverage: $PERCENT% (threshold: $VORTEX_CI_CODE_COVERAGE_THRESHOLD%)" | ||
| if [ "${PERCENT//./}" -lt "$((VORTEX_CI_CODE_COVERAGE_THRESHOLD*100))" ]; then | ||
| echo "FAIL: coverage too low" | ||
| exit 1 | ||
| fi | ||
| { echo "COVERAGE_CONTENT<<EOF"; sed '/./,$!d' .logs/coverage/phpunit/coverage.txt; echo "EOF"; } >> "$GITHUB_ENV" | ||
| env: | ||
| VORTEX_CI_CODE_COVERAGE_THRESHOLD: ${{ vars.VORTEX_CI_CODE_COVERAGE_THRESHOLD || '90' }} | ||
|
|
||
|
Comment on lines
+384
to
+398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden coverage parsing/compare: handle missing RATE/files and avoid fragile string math. - name: Check code coverage threshold
if: ${{ matrix.instance == 0 || strategy.job-total == 1 }}
run: |
- RATE=$(grep -o 'line-rate="[0-9.]*"' .logs/coverage/phpunit/cobertura.xml | head -1 | tr -cd '0-9.')
- PERCENT=$(awk "BEGIN {printf \"%.2f\", $RATE*100}")
- echo "Coverage: $PERCENT% (threshold: $VORTEX_CI_CODE_COVERAGE_THRESHOLD%)"
- if [ "${PERCENT//./}" -lt "$((VORTEX_CI_CODE_COVERAGE_THRESHOLD*100))" ]; then
- echo "FAIL: coverage too low"
- exit 1
- fi
- { echo "COVERAGE_CONTENT<<EOF"; sed '/./,$!d' .logs/coverage/phpunit/coverage.txt; echo "EOF"; } >> "$GITHUB_ENV"
+ set -euo pipefail
+
+ COBERTURA=".logs/coverage/phpunit/cobertura.xml"
+ TEXT_REPORT=".logs/coverage/phpunit/coverage.txt"
+ test -s "${COBERTURA}" || { echo "FAIL: missing Cobertura report at ${COBERTURA}"; exit 1; }
+ test -s "${TEXT_REPORT}" || { echo "FAIL: missing text coverage report at ${TEXT_REPORT}"; exit 1; }
+
+ RATE="$(grep -oE 'line-rate="[0-9]+(\.[0-9]+)?"' "${COBERTURA}" | head -n1 | tr -cd '0-9.')"
+ test -n "${RATE}" || { echo "FAIL: could not parse line-rate from ${COBERTURA}"; exit 1; }
+
+ THRESHOLD="${VORTEX_CI_CODE_COVERAGE_THRESHOLD:-90}"
+ [[ "${THRESHOLD}" =~ ^[0-9]+([.][0-9]+)?$ ]] || { echo "FAIL: invalid threshold '${THRESHOLD}'"; exit 1; }
+
+ PERCENT="$(awk -v r="${RATE}" 'BEGIN { printf "%.2f", (r*100) }')"
+ echo "Coverage: ${PERCENT}% (threshold: ${THRESHOLD}%)"
+
+ awk -v p="${PERCENT}" -v t="${THRESHOLD}" 'BEGIN { exit !(p < t) }' && { echo "FAIL: coverage too low"; exit 1; }
+
+ DELIM="COVERAGE_$(date +%s)_$RANDOM"
+ { echo "COVERAGE_CONTENT<<${DELIM}"; sed '/./,$!d' "${TEXT_REPORT}"; echo "${DELIM}"; } >> "$GITHUB_ENV"
env:
VORTEX_CI_CODE_COVERAGE_THRESHOLD: ${{ vars.VORTEX_CI_CODE_COVERAGE_THRESHOLD || '90' }}
<details>
<summary>🤖 Prompt for AI Agents</summary>
.github/workflows/build-test-deploy.yml around lines 384-398: the coverage check |
||
| - name: Post coverage summary as PR comment | ||
| if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }} | ||
| uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2 | ||
| with: | ||
| message: | | ||
| ``` | ||
| ${{ env.COVERAGE_CONTENT }} | ||
| ``` | ||
| hide_and_recreate: true | ||
|
|
||
|
Comment on lines
+399
to
+408
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gate PR comment on having computed content (and keep behavior PR-only). - name: Post coverage summary as PR comment
- if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }}
+ if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' && env.COVERAGE_CONTENT != '' }}
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2
with:
message: |
```
${{ env.COVERAGE_CONTENT }}
```
hide_and_recreate: true
<details>
<summary>🤖 Prompt for AI Agents</summary>
.github/workflows/build-test-deploy.yml around lines 399 to 408: the PR comment |
||
| - name: Upload coverage report to Codecov | ||
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5 | ||
| if: ${{ env.CODECOV_TOKEN != '' }} | ||
|
|
@@ -390,6 +415,7 @@ jobs: | |
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| env: | ||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
| #;> TOOL_PHPUNIT | ||
|
|
||
| - name: Upload exported codebase as an artifact | ||
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,3 +164,16 @@ long-running steps: | |
| command: ./scripts/long-task.sh | ||
| no_output_timeout: 60m # Default is 10m | ||
| ``` | ||
|
|
||
| ### Code coverage threshold | ||
|
|
||
| The workflow enforces a minimum code coverage threshold. If coverage falls below | ||
| the threshold, the build fails. | ||
|
|
||
| Configure the threshold by setting the `VORTEX_CI_CODE_COVERAGE_THRESHOLD` | ||
| environment variable in **Project Settings → Environment Variables**. Default | ||
| is `90` (percent). | ||
|
|
||
| Coverage reports can be posted as PR comments. This requires a `GITHUB_TOKEN` | ||
| environment variable with permission to post comments. To disable PR comments, | ||
| set `VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1`. | ||
|
Comment on lines
+168
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify required |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,3 +158,15 @@ steps: | |
| run: ./scripts/long-task.sh | ||
| timeout-minutes: 60 # Default is 360 (6 hours) | ||
| ``` | ||
|
|
||
| ### Code coverage threshold | ||
|
|
||
| The workflow enforces a minimum code coverage threshold. If coverage falls below | ||
| the threshold, the build fails. | ||
|
|
||
| Configure the threshold by setting the `VORTEX_CI_CODE_COVERAGE_THRESHOLD` | ||
| variable in **Settings → Secrets and variables → Actions → Variables**. Default | ||
| is `90` (percent). | ||
|
|
||
| Coverage reports are automatically posted as PR comments. To disable this, set | ||
| `VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1`. | ||
|
Comment on lines
+162
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs should mention PR-only + single-matrix gating to avoid confusion. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle missing/invalid Cobertura input (avoid false “0%” / awk errors).
If
/tmp/artifacts/coverage/phpunit/cobertura.xmlis missing or doesn’t contain the expected attribute,RATEbecomes empty and the step can misreport coverage or behave inconsistently. Add file/parse validation and fail with a clear message.- run: name: Check code coverage threshold command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 - RATE=$(grep -o 'line-rate="[0-9.]*"' /tmp/artifacts/coverage/phpunit/cobertura.xml | head -1 | tr -cd '0-9.') + COBERTURA=/tmp/artifacts/coverage/phpunit/cobertura.xml + [ -f "${COBERTURA}" ] || { echo "FAIL: missing ${COBERTURA}"; exit 1; } + # Prefer the top-level <coverage line-rate="..."> attribute. + RATE=$(grep -m1 -oE '<coverage[^>]* line-rate="[0-9.]+"' "${COBERTURA}" | grep -oE 'line-rate="[0-9.]+"' | tr -cd '0-9.') + [ -n "${RATE}" ] || { echo "FAIL: could not parse line-rate from ${COBERTURA}"; exit 1; } PERCENT=$(awk "BEGIN {printf \"%.2f\", $RATE*100}") echo "Coverage: $PERCENT% (threshold: ${VORTEX_CI_CODE_COVERAGE_THRESHOLD:-90}%)" if [ "${PERCENT//./}" -lt "$((${VORTEX_CI_CODE_COVERAGE_THRESHOLD:-90}*100))" ]; then echo "FAIL: coverage too low" exit 1 fi🤖 Prompt for AI Agents