1212 check-coverage :
1313 runs-on : ubuntu-latest
1414 outputs :
15- coverage_percent_list : ${{ steps.set_coverage.outputs.coverage_percent_list }}
15+ site_coverage_list : ${{ steps.set_coverage.outputs.site_coverage_list }}
1616 coverage_below_threshold : ${{ steps.set_coverage.outputs.coverage_below_threshold }}
17- low_coverage_sites : ${{ steps.set_coverage.outputs.low_coverage_sites }}
1817
1918 steps :
2019 - name : Checkout Repos
@@ -36,67 +35,48 @@ jobs:
3635 npm ci
3736 COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE/cloned-docs-java-repo" -v --sp 95)
3837
39- REQUIRED_COVERAGE=90 .0
38+ REQUIRED_COVERAGE=100 .0
4039
4140 # 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/,$//')
49-
50- # Extract site names where Average Coverage is below the required coverage%
51- LOW_COVERAGE_SITES=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
41+ SITE_COVERAGE_LIST=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
5242 /Average Coverage:/ {
53- coverage = $3 + 0; # Convert to number
54- if (coverage < threshold) {
55- low_coverage_detected = 1; # Flag that we have low coverage
56- } else {
57- low_coverage_detected = 0; # Reset if coverage is above threshold
58- }
43+ coverage = $3 + 0;
44+ if (coverage < threshold) {
45+ low_coverage_detected = 1;
46+ last_coverage = coverage;
47+ } else {
48+ low_coverage_detected = 0;
49+ }
5950 }
6051 /Finished processing site "/ {
61- if (low_coverage_detected) {
62- site = $4;
63- gsub(/"/, "", site); # Extract site name
64- sites[ site] = 1 ; # Store site name
65- }
52+ if (low_coverage_detected) {
53+ site = $4;
54+ gsub(/"/, "", site); # Extract site name
55+ print site ":" last_coverage ; # Store as site:coverage
56+ }
6657 }
67- END { for (s in sites) printf "%s,", s }
68- ' | sed 's/,$//')
58+ ' | paste -sd ',' - )
6959
7060 # Print detected values
71- echo "Detected Coverage: $COVERAGE_PERCENT_LIST"
72-
73- echo "Sites with Low Coverage: $LOW_COVERAGE_SITES"
74-
75- # Ensure we have a valid number
76- if [ -z "$COVERAGE_PERCENT_LIST" ]; then
77- echo "Coverage percentage could not be determined."
78- exit 1
79- fi
61+ echo "Detected Coverage Below Threshold: $SITE_COVERAGE_LIST"
8062
8163 echo "Required Coverage: $REQUIRED_COVERAGE"
8264
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%)."
86- echo "coverage_below_threshold=true" >> $GITHUB_ENV
87- echo "COVERAGE_PERCENT_LIST=$COVERAGE_PERCENT_LIST" >> $GITHUB_ENV
88- echo "LOW_COVERAGE_SITES=$LOW_COVERAGE_SITES" >> $GITHUB_ENV
65+ # Check if SITE_COVERAGE_LIST is empty or not
66+ if [ -n "$SITE_COVERAGE_LIST" ]; then
67+ echo "Test coverage is below the required threshold ($REQUIRED_COVERAGE%)."
68+ echo "coverage_below_threshold=true" >> $GITHUB_ENV
69+ echo "SITE_COVERAGE_LIST=$SITE_COVERAGE_LIST" >> $GITHUB_ENV
8970 else
90- echo "Test coverage meets the required threshold."
91- echo "coverage_below_threshold=false" >> $GITHUB_ENV
71+ echo "Test coverage meets the required threshold."
72+ echo "coverage_below_threshold=false" >> $GITHUB_ENV
9273 fi
9374
9475 - name : Set Workflow Outputs
9576 id : set_coverage
9677 run : |
97- echo "coverage_percent_list=${COVERAGE_PERCENT_LIST}" >> $GITHUB_OUTPUT
9878 echo "coverage_below_threshold=${coverage_below_threshold}" >> $GITHUB_OUTPUT
99- echo "low_coverage_sites =${LOW_COVERAGE_SITES }" >> $GITHUB_OUTPUT
79+ echo "site_coverage_list =${SITE_COVERAGE_LIST }" >> $GITHUB_OUTPUT
10080
10181 send-slack-notification :
10282 runs-on : ubuntu-latest
@@ -106,17 +86,31 @@ jobs:
10686 steps :
10787 - name : Send Slack Notification
10888 env :
109- COVERAGE_PERCENT_LIST : ${{ needs.check-coverage.outputs.coverage_percent_list }}
110- LOW_COVERAGE_SITES : ${{ needs.check-coverage.outputs.low_coverage_sites }}
89+ SITE_COVERAGE_LIST : ${{ needs.check-coverage.outputs.site_coverage_list }}
11190 SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
11291 REPOSITORY : ${{ github.repository }}
11392 PR_TITLE : ${{ github.event.pull_request.title }}
11493 PR_NUMBER : ${{ github.event.pull_request.number }}
11594 PR_URL : ${{ github.event.pull_request.html_url }}
11695 PR_SHA : ${{ github.event.pull_request.head.sha }}
11796 run : |
97+ TEXT_MESSAGE="⚠️ *Test Coverage Alert* ⚠️\n\nThe test coverage is below the required threshold of 90%.\n\n*Sites with Low Coverage:* \n"
98+
99+ IFS=',' read -r -a SITE_COVERAGE_ARRAY <<< "$SITE_COVERAGE_LIST"
100+
101+ for item in "${SITE_COVERAGE_ARRAY[@]}"; do
102+ site_name="${item%%:*}"
103+ coverage_value="${item##*:}"
104+ TEXT_MESSAGE+="• ${site_name}: ${coverage_value}%\n"
105+ done
106+
107+ TEXT_MESSAGE+="\n*Repository:* <https://github.com/$REPOSITORY|$REPOSITORY>\n"
108+ TEXT_MESSAGE+="*PR Title:* $PR_TITLE\n"
109+ TEXT_MESSAGE+="*PR Number:* #$PR_NUMBER\n"
110+ TEXT_MESSAGE+="*PR URL:* <$PR_URL|View PR>\n"
111+ TEXT_MESSAGE+="*Commit SHA:* \`$PR_SHA\`\n\n"
112+ TEXT_MESSAGE+="Please review the test coverage and take action if necessary."
113+
118114 curl -v -X POST -H 'Content-type: application/json' \
119- --data '{
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."
121- }' \
122- $SLACK_WEBHOOK_URL
115+ --data '{"text": "'"$TEXT_MESSAGE"'"}' \
116+ $SLACK_WEBHOOK_URL
0 commit comments