Skip to content

👷 DOP-5399 adds Osiris Coverage GHA #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .github/workflows/osiris-subpar-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Coverage Check for Osiris Generated AST files
on:
pull_request:
paths:
- '**/*.ast' # Only trigger if .ast files are changed
branches:
- main
- DOP-5399-CB
workflow_dispatch:

jobs:
check-coverage:
runs-on: ubuntu-latest
outputs:
site_coverage_list: ${{ steps.set_coverage.outputs.site_coverage_list }}
coverage_below_threshold: ${{ steps.set_coverage.outputs.coverage_below_threshold }}

steps:
- name: Checkout Repos
uses: actions/checkout@v4

- name: Install Wget
run: sudo apt-get update && sudo apt-get install -y wget

- name: Clone Docs Java
run: git clone --branch DOP-5399-CB https://github.com/mongodb/docs-java.git cloned-docs-java-repo

- name: Clone Osiris
run: git clone https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/10gen/osiris.git cloned-osiris-repo

- name: Run Coverage Check
id: run_coverage
run: |
cd cloned-osiris-repo
npm ci
COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE/cloned-docs-java-repo" -v --sp 95)

REQUIRED_COVERAGE=90.0

# Extract all Average Coverage values below the threshold
SITE_COVERAGE_LIST=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
/Average Coverage:/ {
coverage = $3 + 0;
if (coverage < threshold) {
low_coverage_detected = 1;
last_coverage = coverage;
} else {
low_coverage_detected = 0;
}
}
/Finished processing site "/ {
if (low_coverage_detected) {
site = $4;
gsub(/"/, "", site); # Extract site name
print site ":" last_coverage; # Store as site:coverage
}
}
' | paste -sd ',' - )

# Print detected values
echo "Detected Coverage Below Threshold: $SITE_COVERAGE_LIST"

echo "Required Coverage: $REQUIRED_COVERAGE"

# Check if SITE_COVERAGE_LIST is empty or not
if [ -n "$SITE_COVERAGE_LIST" ]; then
echo "Test coverage is below the required threshold ($REQUIRED_COVERAGE%)."
echo "coverage_below_threshold=true" >> $GITHUB_ENV
echo "SITE_COVERAGE_LIST=$SITE_COVERAGE_LIST" >> $GITHUB_ENV
else
echo "Test coverage meets the required threshold."
echo "coverage_below_threshold=false" >> $GITHUB_ENV
fi

- name: Set Workflow Outputs
id: set_coverage
run: |
echo "coverage_below_threshold=${coverage_below_threshold}" >> $GITHUB_OUTPUT
echo "site_coverage_list=${SITE_COVERAGE_LIST}" >> $GITHUB_OUTPUT

send-slack-notification:
runs-on: ubuntu-latest
needs: check-coverage
if: needs.check-coverage.outputs.coverage_below_threshold == 'true'

steps:
- name: Send Slack Notification
env:
SITE_COVERAGE_LIST: ${{ needs.check-coverage.outputs.site_coverage_list }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
REPOSITORY: ${{ github.repository }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
run: |
TEXT_MESSAGE="⚠️ *Test Coverage Alert* ⚠️\n\nThe test coverage is below the required threshold of 90%.\n\n*Sites with Low Coverage:* \n"

IFS=',' read -r -a SITE_COVERAGE_ARRAY <<< "$SITE_COVERAGE_LIST"

for item in "${SITE_COVERAGE_ARRAY[@]}"; do
site_name="${item%%:*}"
coverage_value="${item##*:}"
TEXT_MESSAGE+="• ${site_name}: ${coverage_value}%\n"
done

TEXT_MESSAGE+="\n*Repository:* <https://github.com/$REPOSITORY|$REPOSITORY>\n"
TEXT_MESSAGE+="*PR Title:* $PR_TITLE\n"
TEXT_MESSAGE+="*PR Number:* #$PR_NUMBER\n"
TEXT_MESSAGE+="*PR URL:* <$PR_URL|View PR>\n"
TEXT_MESSAGE+="*Commit SHA:* \`$PR_SHA\`\n\n"
TEXT_MESSAGE+="Please review the test coverage and take action if necessary."

curl -v -X POST -H 'Content-type: application/json' \
--data '{"text": "'"$TEXT_MESSAGE"'"}' \
$SLACK_WEBHOOK_URL
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ giza.log
.vscode*
*.swp
*.code-workspace

# GitHub Actions
.secrets
event.json
39 changes: 39 additions & 0 deletions osiris.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[[sites]]
name = "java-sync"
url = "https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-sync/index.html"
site_type = "java"
source_dir = "source"
output = "api-documentation/java-sync"

[sites.href_mapping]
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongodb-driver-sync/" = "/api-documentation/java-sync/"

[[sites]]
name = "core"
url = "https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-core/index.html"
site_type = "java"
source_dir = "source"
output = "api-documentation/core"

[sites.href_mapping]
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongodb-driver-core/" = "/api-documentation/core/"

[[sites]]
name = "scala"
url = "https://mongodb.github.io/mongo-java-driver/5.1/apidocs/mongo-scala-driver/index.html"
site_type = "scala"
source_dir = "source"
output = "api-documentation/scala"

[sites.href_mapping]
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongo-scala-driver/" = "/api-documentation/scala/"

[[sites]]
name = "kotlin"
url = "https://mongodb.github.io/mongo-java-driver/5.3/apidocs/mongodb-driver-kotlin-sync/index.html"
site_type = "kotlin"
source_dir = "source"
output = "api-documentation/kotlin"

[sites.href_mapping]
"*//mongodb.github.io/mongo-java-driver/*/apidocs/mongodb-driver-kotlin-sync/" = "/api-documentation/kotlin/"
Loading