diff --git a/.github/workflows/osiris-subpar-coverage.yml b/.github/workflows/osiris-subpar-coverage.yml new file mode 100644 index 000000000..5c4428530 --- /dev/null +++ b/.github/workflows/osiris-subpar-coverage.yml @@ -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 + 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 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=100.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:* \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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 49c66f9d2..2a4b4a887 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,7 @@ giza.log .vscode* *.swp *.code-workspace + +# GitHub Actions +.secrets +event.json \ No newline at end of file diff --git a/osiris.toml b/osiris.toml new file mode 100644 index 000000000..5fd8fcd3c --- /dev/null +++ b/osiris.toml @@ -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/" \ No newline at end of file diff --git a/source/api-documentation.txt b/source/api-documentation.txt index 894200ee7..1edcde67b 100644 --- a/source/api-documentation.txt +++ b/source/api-documentation.txt @@ -28,5 +28,4 @@ API Documentation BSON Record Codec <{+api+}/apidocs/bson-record-codec/index.html> Core <{+api+}/apidocs/mongodb-driver-core/index.html> Java Driver (modern API) <{+api+}/apidocs/mongodb-driver-sync/index.html> - Java Driver (legacy API) <{+api+}/apidocs/mongodb-driver-legacy/index.html> - + Java Driver (legacy API) <{+api+}/apidocs/mongodb-driver-legacy/index.html> \ No newline at end of file