12
12
check-coverage :
13
13
runs-on : ubuntu-latest
14
14
outputs :
15
- coverage_percent_list : ${{ steps.set_coverage.outputs.coverage_percent_list }}
15
+ site_coverage_list : ${{ steps.set_coverage.outputs.site_coverage_list }}
16
16
coverage_below_threshold : ${{ steps.set_coverage.outputs.coverage_below_threshold }}
17
- low_coverage_sites : ${{ steps.set_coverage.outputs.low_coverage_sites }}
18
17
19
18
steps :
20
19
- name : Checkout Repos
@@ -36,67 +35,48 @@ jobs:
36
35
npm ci
37
36
COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE/cloned-docs-java-repo" -v --sp 95)
38
37
39
- REQUIRED_COVERAGE=90 .0
38
+ REQUIRED_COVERAGE=100 .0
40
39
41
40
# 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 '
52
42
/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
+ }
59
50
}
60
51
/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
+ }
66
57
}
67
- END { for (s in sites) printf "%s,", s }
68
- ' | sed 's/,$//')
58
+ ' | paste -sd ',' - )
69
59
70
60
# 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"
80
62
81
63
echo "Required Coverage: $REQUIRED_COVERAGE"
82
64
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
89
70
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
92
73
fi
93
74
94
75
- name : Set Workflow Outputs
95
76
id : set_coverage
96
77
run : |
97
- echo "coverage_percent_list=${COVERAGE_PERCENT_LIST}" >> $GITHUB_OUTPUT
98
78
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
100
80
101
81
send-slack-notification :
102
82
runs-on : ubuntu-latest
@@ -106,17 +86,31 @@ jobs:
106
86
steps :
107
87
- name : Send Slack Notification
108
88
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 }}
111
90
SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
112
91
REPOSITORY : ${{ github.repository }}
113
92
PR_TITLE : ${{ github.event.pull_request.title }}
114
93
PR_NUMBER : ${{ github.event.pull_request.number }}
115
94
PR_URL : ${{ github.event.pull_request.html_url }}
116
95
PR_SHA : ${{ github.event.pull_request.head.sha }}
117
96
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
+
118
114
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