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
+ coverage_percent : ${{ steps.set_coverage.outputs.coverage_percent }}
16
+ coverage_below_threshold : ${{ steps.set_coverage.outputs.coverage_below_threshold }}
17
+ low_coverage_sites : ${{ steps.set_coverage.outputs.low_coverage_sites }}
18
+
19
+ steps :
20
+ - name : Checkout Repos
21
+ uses : actions/checkout@v4
22
+
23
+ - name : Install Wget
24
+ run : sudo apt-get update && sudo apt-get install -y wget
25
+
26
+ - name : Clone Docs Java
27
+ run : git clone --branch DOP-5399 https://github.com/mongodb/docs-java.git cloned-docs-java-repo
28
+
29
+ - name : Clone Osiris
30
+ run : git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/10gen/osiris.git cloned-osiris-repo
31
+
32
+ - name : Run Coverage Check
33
+ id : run_coverage
34
+ run : |
35
+ cd cloned-osiris-repo
36
+ npm ci
37
+ COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE/cloned-docs-java-repo" -v --sp 95 | tee /dev/tty)
38
+
39
+
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=90.0
44
+
45
+ # Extract site names where Average Coverage is below the required coverage%
46
+ LOW_COVERAGE_SITES=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
47
+ /Average Coverage:/ {
48
+ coverage = $3 + 0; # Convert to number
49
+ if (coverage < threshold) {
50
+ low_coverage_detected = 1; # Flag that we have low coverage
51
+ } else {
52
+ low_coverage_detected = 0; # Reset if coverage is above threshold
53
+ }
54
+ }
55
+ /Finished processing site "/ {
56
+ if (low_coverage_detected) {
57
+ site = $4;
58
+ gsub(/"/, "", site); # Extract site name
59
+ sites[site] = 1; # Store site name
60
+ }
61
+ }
62
+ END { for (s in sites) printf "%s,", s }
63
+ ' | sed 's/,$//')
64
+
65
+ echo "Detected Coverage: $COVERAGE_PERCENT%"
66
+ echo "Sites with Low Coverage: $LOW_COVERAGE_SITES"
67
+
68
+ # Ensure we have a valid number
69
+ if [ -z "$COVERAGE_PERCENT" ]; then
70
+ echo "Coverage percentage could not be determined."
71
+ exit 1
72
+ fi
73
+
74
+ echo "Required Coverage: $REQUIRED_COVERAGE"
75
+
76
+ if awk "BEGIN {exit !($COVERAGE_PERCENT < $REQUIRED_COVERAGE)}"; then
77
+ echo "Test coverage ($COVERAGE_PERCENT%) is below required threshold ($REQUIRED_COVERAGE%)."
78
+ echo "coverage_below_threshold=true" >> $GITHUB_ENV
79
+ echo "COVERAGE_PERCENT=$COVERAGE_PERCENT" >> $GITHUB_ENV
80
+ echo "LOW_COVERAGE_SITES=$LOW_COVERAGE_SITES" >> $GITHUB_ENV
81
+ else
82
+ echo "Test coverage ($COVERAGE_PERCENT%) meets the required threshold."
83
+ echo "coverage_below_threshold=false" >> $GITHUB_ENV
84
+ fi
85
+
86
+ - name : Set Workflow Outputs
87
+ id : set_coverage
88
+ run : |
89
+ echo "coverage_percent=${COVERAGE_PERCENT}" >> $GITHUB_OUTPUT
90
+ echo "coverage_below_threshold=${coverage_below_threshold}" >> $GITHUB_OUTPUT
91
+ echo "low_coverage_sites=${LOW_COVERAGE_SITES}" >> $GITHUB_OUTPUT
92
+
93
+ send-slack-notification :
94
+ runs-on : ubuntu-latest
95
+ needs : check-coverage
96
+ if : needs.check-coverage.outputs.coverage_below_threshold == 'true'
97
+
98
+ steps :
99
+ - name : Send Slack Notification
100
+ env :
101
+ COVERAGE_PERCENT : ${{ needs.check-coverage.outputs.coverage_percent }}
102
+ LOW_COVERAGE_SITES : ${{ needs.check-coverage.outputs.low_coverage_sites }}
103
+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
104
+ REPOSITORY : ${{ github.repository }}
105
+ PR_TITLE : ${{ github.event.pull_request.title }}
106
+ PR_NUMBER : ${{ github.event.pull_request.number }}
107
+ PR_URL : ${{ github.event.pull_request.html_url }}
108
+ PR_SHA : ${{ github.event.pull_request.head.sha }}
109
+ run : |
110
+ curl -v -X POST -H 'Content-type: application/json' \
111
+ --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."
113
+ }' \
114
+ $SLACK_WEBHOOK_URL
0 commit comments