1818 - name : Checkout Repos
1919 uses : actions/checkout@v4
2020 with :
21- token : ${{ secrets.PERSONAL_ACCESS_TOKEN }}
21+ token : ${{ secrets.API_TOKEN_GITHUB }}
2222 fetch-depth : 0
2323 ref : DOP-5399-CB
2424
@@ -30,51 +30,14 @@ jobs:
3030 run : sudo apt-get update && sudo apt-get install -y wget
3131
3232 - name : Clone Osiris
33- run : git clone https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/10gen/osiris.git cloned-osiris-repo
33+ run : git clone https://x-access-token:${{ secrets.API_TOKEN_GITHUB }}@github.com/10gen/osiris.git cloned-osiris-repo
3434
3535 - name : Run Coverage Check
3636 id : run_coverage
37- run : |
38- cd cloned-osiris-repo
39- npm ci
40- COVERAGE_OUTPUT=$(npm run dev -- -c "$GITHUB_WORKSPACE" -v --sp 95)
41-
42- REQUIRED_COVERAGE=100.0
43-
44- # Extract all Average Coverage values below the threshold
45- SITE_COVERAGE_LIST=$(echo "$COVERAGE_OUTPUT" | awk -v threshold=$REQUIRED_COVERAGE '
46- /Average Coverage:/ {
47- coverage = $3 + 0;
48- if (coverage < threshold) {
49- low_coverage_detected = 1;
50- last_coverage = coverage;
51- } else {
52- low_coverage_detected = 0;
53- }
54- }
55- /Finished processing site "/ {
56- if (low_coverage_detected) {
57- site = $4;
58- gsub(/"/, "", site); # Extract site name
59- print site ":" last_coverage; # Store as site:coverage
60- }
61- }
62- ' | paste -sd ',' - )
63-
64- # Print detected values
65- echo "Detected Coverage Below Threshold: $SITE_COVERAGE_LIST"
66-
67- echo "Required Coverage: $REQUIRED_COVERAGE"
68-
69- # Check if SITE_COVERAGE_LIST is empty or not
70- if [ -n "$SITE_COVERAGE_LIST" ]; then
71- echo "Test coverage is below the required threshold ($REQUIRED_COVERAGE%)."
72- echo "coverage_below_threshold=true" >> $GITHUB_ENV
73- echo "SITE_COVERAGE_LIST=$SITE_COVERAGE_LIST" >> $GITHUB_ENV
74- else
75- echo "Test coverage meets the required threshold."
76- echo "coverage_below_threshold=false" >> $GITHUB_ENV
77- fi
37+ uses : mongodb/docs-worker-actions/coverage-check@DOP-5399
38+ with :
39+ repo-path : cloned-osiris-repo
40+ required-coverage : ' 100'
7841
7942 - name : Set Workflow Outputs
8043 id : set_coverage
@@ -97,24 +60,13 @@ jobs:
9760 PR_NUMBER : ${{ github.event.pull_request.number }}
9861 PR_URL : ${{ github.event.pull_request.html_url }}
9962 PR_SHA : ${{ github.event.pull_request.head.sha }}
100- run : |
101- TEXT_MESSAGE="⚠️ *Test Coverage Alert* ⚠️\n\nThe test coverage is below the required threshold of 90%.\n\n*Sites with Low Coverage:* \n"
102-
103- IFS=',' read -r -a SITE_COVERAGE_ARRAY <<< "$SITE_COVERAGE_LIST"
104-
105- for item in "${SITE_COVERAGE_ARRAY[@]}"; do
106- site_name="${item%%:*}"
107- coverage_value="${item##*:}"
108- TEXT_MESSAGE+="• ${site_name}: ${coverage_value}%\n"
109- done
110-
111- TEXT_MESSAGE+="\n*Repository:* <https://github.com/$REPOSITORY|$REPOSITORY>\n"
112- TEXT_MESSAGE+="*PR Title:* $PR_TITLE\n"
113- TEXT_MESSAGE+="*PR Number:* #$PR_NUMBER\n"
114- TEXT_MESSAGE+="*PR URL:* <$PR_URL|View PR>\n"
115- TEXT_MESSAGE+="*Commit SHA:* \`$PR_SHA\`\n\n"
116- TEXT_MESSAGE+="Please review the test coverage and take action if necessary."
117-
118- curl -v -X POST -H 'Content-type: application/json' \
119- --data '{"text": "'"$TEXT_MESSAGE"'"}' \
120- $SLACK_WEBHOOK_URL
63+ uses : mongodb/docs-worker-actions/coverage-report-to-slack@DOP-5399
64+ with :
65+ required-coverage : ' 100'
66+ site-coverage-list : $SITE_COVERAGE_LIST
67+ slack-webhook-url : $SLACK_WEBHOOK_URL
68+ repository : $REPOSITORY
69+ pr-title : $PR_TITLE
70+ pr-number : $PR_NUMBER
71+ pr-url : $PR_URL
72+ pr-sha : $PR_SHA
0 commit comments