Skip to content

Commit 36ae4fb

Browse files
committed
🔧 DOP-5399 adds the logic and format for Osiris Coverage
1 parent 2890542 commit 36ae4fb

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

.github/workflows/osiris-subpar-coverage.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
check-coverage:
1313
runs-on: ubuntu-latest
1414
outputs:
15-
coverage_percent: ${{ steps.set_coverage.outputs.coverage_percent }}
15+
coverage_percent_list: ${{ steps.set_coverage.outputs.coverage_percent_list }}
1616
coverage_below_threshold: ${{ steps.set_coverage.outputs.coverage_below_threshold }}
1717
low_coverage_sites: ${{ steps.set_coverage.outputs.low_coverage_sites }}
1818

@@ -36,11 +36,16 @@ jobs:
3636
npm ci
3737
COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE/cloned-docs-java-repo" -v --sp 95)
3838
39+
REQUIRED_COVERAGE=90.0
3940
40-
# Extract the last reported overall coverage percentage
41-
COVERAGE_PERCENT=$(echo "$COVERAGE_OUTPUT" | grep -oE 'Average Coverage: [0-9]+(\.[0-9]+)?%' | tail -1 | grep -oE '[0-9]+(\.[0-9]+)?')
42-
43-
REQUIRED_COVERAGE=100.0
41+
# Extract all Average Coverage values below the threshold
42+
COVERAGE_PERCENT_LIST=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
43+
/Average Coverage:/ {
44+
coverage = $3 + 0;
45+
if (coverage < threshold) {
46+
printf "%s,", coverage "%";
47+
}
48+
}' | sed 's/,$//')
4449
4550
# Extract site names where Average Coverage is below the required coverage%
4651
LOW_COVERAGE_SITES=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
@@ -62,31 +67,34 @@ jobs:
6267
END { for (s in sites) printf "%s,", s }
6368
' | sed 's/,$//')
6469
65-
echo "Detected Coverage: $COVERAGE_PERCENT%"
70+
# Print detected values
71+
echo "Detected Coverage: $COVERAGE_PERCENT_LIST"
72+
6673
echo "Sites with Low Coverage: $LOW_COVERAGE_SITES"
6774
6875
# Ensure we have a valid number
69-
if [ -z "$COVERAGE_PERCENT" ]; then
76+
if [ -z "$COVERAGE_PERCENT_LIST" ]; then
7077
echo "Coverage percentage could not be determined."
7178
exit 1
7279
fi
7380
7481
echo "Required Coverage: $REQUIRED_COVERAGE"
7582
76-
if awk "BEGIN {exit !($COVERAGE_PERCENT < $REQUIRED_COVERAGE)}"; then
77-
echo "Test coverage ($COVERAGE_PERCENT%) is below required threshold ($REQUIRED_COVERAGE%)."
83+
# If COVERAGE_PERCENT_LIST is not empty, it means there are coverage values below the threshold
84+
if [ -n "$COVERAGE_PERCENT_LIST" ]; then
85+
echo "Test coverage is below the required threshold ($REQUIRED_COVERAGE%)."
7886
echo "coverage_below_threshold=true" >> $GITHUB_ENV
79-
echo "COVERAGE_PERCENT=$COVERAGE_PERCENT" >> $GITHUB_ENV
87+
echo "COVERAGE_PERCENT_LIST=$COVERAGE_PERCENT_LIST" >> $GITHUB_ENV
8088
echo "LOW_COVERAGE_SITES=$LOW_COVERAGE_SITES" >> $GITHUB_ENV
8189
else
82-
echo "Test coverage ($COVERAGE_PERCENT%) meets the required threshold."
90+
echo "Test coverage meets the required threshold."
8391
echo "coverage_below_threshold=false" >> $GITHUB_ENV
8492
fi
8593
8694
- name: Set Workflow Outputs
8795
id: set_coverage
8896
run: |
89-
echo "coverage_percent=${COVERAGE_PERCENT}" >> $GITHUB_OUTPUT
97+
echo "coverage_percent_list=${COVERAGE_PERCENT_LIST}" >> $GITHUB_OUTPUT
9098
echo "coverage_below_threshold=${coverage_below_threshold}" >> $GITHUB_OUTPUT
9199
echo "low_coverage_sites=${LOW_COVERAGE_SITES}" >> $GITHUB_OUTPUT
92100
@@ -98,7 +106,7 @@ jobs:
98106
steps:
99107
- name: Send Slack Notification
100108
env:
101-
COVERAGE_PERCENT: ${{ needs.check-coverage.outputs.coverage_percent }}
109+
COVERAGE_PERCENT_LIST: ${{ needs.check-coverage.outputs.coverage_percent_list }}
102110
LOW_COVERAGE_SITES: ${{ needs.check-coverage.outputs.low_coverage_sites }}
103111
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
104112
REPOSITORY: ${{ github.repository }}
@@ -109,6 +117,6 @@ jobs:
109117
run: |
110118
curl -v -X POST -H 'Content-type: application/json' \
111119
--data '{
112-
"text": "⚠️ *Test Coverage Alert* ⚠️\n\nThe test coverage is below the required threshold of 90%.\n\n*Detected Coverage:* '"$COVERAGE_PERCENT"%'\n\n*Repository:* <https://github.com/'"$REPOSITORY"'|'"$REPOSITORY"'>\n*PR Title:* '"$PR_TITLE"'\n*PR Number:* #'"$PR_NUMBER"'\n*PR URL:* <'"$PR_URL"'|View PR>\n*Commit SHA:* `'"$PR_SHA"'`\n\n*Sites with Low Coverage:* \n`'"$LOW_COVERAGE_SITES"'`\n\nPlease review the test coverage and take action if necessary."
120+
"text": "⚠️ *Test Coverage Alert* ⚠️\n\nThe test coverage is below the required threshold of 90%.\n\n*Detected Coverage:* \n• '"$(echo "$COVERAGE_PERCENT_LIST" | sed 's/,/\n• /g')"' \n\n*Repository:* <https://github.com/'"$REPOSITORY"'|'"$REPOSITORY"'>\n*PR Title:* '"$PR_TITLE"'\n*PR Number:* #'"$PR_NUMBER"'\n*PR URL:* <'"$PR_URL"'|View PR>\n*Commit SHA:* `'"$PR_SHA"'`\n\n*Sites with Low Coverage:* \n'"$(echo "$LOW_COVERAGE_SITES" | sed 's/,/\n• /g')"' \n\nPlease review the test coverage and take action if necessary."
113121
}' \
114122
$SLACK_WEBHOOK_URL

0 commit comments

Comments
 (0)