1+ name : Coverage Check for Osiris Generated AST files
2+ on :
3+ pull_request :
4+ paths :
5+ - ' **/*.ast' # Only trigger if .ast files are changed
6+ branches :
7+ - main
8+ - DOP-5399
9+ workflow_dispatch :
10+
11+ jobs :
12+ check-coverage :
13+ runs-on : ubuntu-latest
14+ outputs :
15+ site_coverage_list : ${{ steps.set_coverage.outputs.site_coverage_list }}
16+ coverage_below_threshold : ${{ steps.set_coverage.outputs.coverage_below_threshold }}
17+
18+ steps :
19+ - name : Checkout Repos
20+ uses : actions/checkout@v4
21+
22+ - name : Install Wget
23+ run : sudo apt-get update && sudo apt-get install -y wget
24+
25+ - name : Clone Docs Java
26+ run : git clone --branch DOP-5399 https://github.com/mongodb/docs-java.git cloned-docs-java-repo
27+
28+ - name : Clone Osiris
29+ run : git clone https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/10gen/osiris.git cloned-osiris-repo
30+
31+ - name : Run Coverage Check
32+ id : run_coverage
33+ run : |
34+ cd cloned-osiris-repo
35+ npm ci
36+ COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE/cloned-docs-java-repo" -v --sp 95)
37+
38+ REQUIRED_COVERAGE=100.0
39+
40+ # Extract all Average Coverage values below the threshold
41+ SITE_COVERAGE_LIST=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
42+ /Average Coverage:/ {
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+ }
50+ }
51+ /Finished processing site "/ {
52+ if (low_coverage_detected) {
53+ site = $4;
54+ gsub(/"/, "", site); # Extract site name
55+ print site ":" last_coverage; # Store as site:coverage
56+ }
57+ }
58+ ' | paste -sd ',' - )
59+
60+ # Print detected values
61+ echo "Detected Coverage Below Threshold: $SITE_COVERAGE_LIST"
62+
63+ echo "Required Coverage: $REQUIRED_COVERAGE"
64+
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
70+ else
71+ echo "Test coverage meets the required threshold."
72+ echo "coverage_below_threshold=false" >> $GITHUB_ENV
73+ fi
74+
75+ - name : Set Workflow Outputs
76+ id : set_coverage
77+ run : |
78+ echo "coverage_below_threshold=${coverage_below_threshold}" >> $GITHUB_OUTPUT
79+ echo "site_coverage_list=${SITE_COVERAGE_LIST}" >> $GITHUB_OUTPUT
80+
81+ send-slack-notification :
82+ runs-on : ubuntu-latest
83+ needs : check-coverage
84+ if : needs.check-coverage.outputs.coverage_below_threshold == 'true'
85+
86+ steps :
87+ - name : Send Slack Notification
88+ env :
89+ SITE_COVERAGE_LIST : ${{ needs.check-coverage.outputs.site_coverage_list }}
90+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
91+ REPOSITORY : ${{ github.repository }}
92+ PR_TITLE : ${{ github.event.pull_request.title }}
93+ PR_NUMBER : ${{ github.event.pull_request.number }}
94+ PR_URL : ${{ github.event.pull_request.html_url }}
95+ PR_SHA : ${{ github.event.pull_request.head.sha }}
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+
114+ curl -v -X POST -H 'Content-type: application/json' \
115+ --data '{"text": "'"$TEXT_MESSAGE"'"}' \
116+ $SLACK_WEBHOOK_URL
0 commit comments