Skip to content

Commit 199efe7

Browse files
committed
👷 DOP-5399 adds Osiris Coverage GHA
1 parent 32eb1c3 commit 199efe7

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ giza.log
3434
.vscode*
3535
*.swp
3636
*.code-workspace
37+
38+
# GitHub Actions
39+
.secrets
40+
event.json

osiris.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[[sites]]
2+
name = "java-sync"
3+
url = "https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-sync/index.html"
4+
site_type = "java"
5+
source_dir = "source"
6+
output = "api-documentation/java-sync"
7+
8+
[sites.href_mapping]
9+
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongodb-driver-sync/" = "/api-documentation/java-sync/"
10+
11+
[[sites]]
12+
name = "core"
13+
url = "https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-core/index.html"
14+
site_type = "java"
15+
source_dir = "source"
16+
output = "api-documentation/core"
17+
18+
[sites.href_mapping]
19+
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongodb-driver-core/" = "/api-documentation/core/"
20+
21+
[[sites]]
22+
name = "scala"
23+
url = "https://mongodb.github.io/mongo-java-driver/5.1/apidocs/mongo-scala-driver/index.html"
24+
site_type = "scala"
25+
source_dir = "source"
26+
output = "api-documentation/scala"
27+
28+
[sites.href_mapping]
29+
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongo-scala-driver/" = "/api-documentation/scala/"
30+
31+
[[sites]]
32+
name = "kotlin"
33+
url = "https://mongodb.github.io/mongo-java-driver/5.3/apidocs/mongodb-driver-kotlin-sync/index.html"
34+
site_type = "kotlin"
35+
source_dir = "source"
36+
output = "api-documentation/kotlin"
37+
38+
[sites.href_mapping]
39+
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongodb-driver-kotlin-sync/" = "/api-documentation/kotlin/"

0 commit comments

Comments
 (0)