🎨 Add ast files #13
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=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:* <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 |