Skip to content

CLOUDP-324670 move coverage to coveralls.io #4069

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 11 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from 10 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
108 changes: 24 additions & 84 deletions .github/workflows/code-health.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
if: ${{ matrix.os=='ubuntu-latest' }}
if: matrix.os == 'ubuntu-latest'
with:
config: ${{ vars.PERMISSIONS_CONFIG }}
- name: Checkout repository
Expand All @@ -45,108 +45,40 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: go install gotest.tools/gotestsum@latest
- run: |
go install gotest.tools/gotestsum@latest
go install github.com/mattn/goveralls@latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we ping to a specific version? This could prevent the action to fails because of some changes to the latest release

- run: make unit-test
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: goveralls -parallel -coverprofile="$COVERAGE" -ignore=test/* -service=github
- name: Test Summary
id: test_summary
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
with:
paths: unit-tests.xml
if: always() && matrix.os == 'ubuntu-latest'
- name: Upload coverage file
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: coverage-file
path: coverage.out

code-coverage:
permissions:
pull-requests: write # Required to comment on PRs
needs: unit-tests
if: github.event_name == 'pull_request'
coverage:
runs-on: ubuntu-latest
needs: [unit-tests, e2e-tests]
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
with:
config: ${{ vars.PERMISSIONS_CONFIG }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get merge base
id: merge_base
run: |
MERGE_BASE=$(git merge-base "${{ github.event.pull_request.head.sha }}" "${{ github.event.pull_request.base.sha }}")
echo "merge_base=$MERGE_BASE" >> "$GITHUB_OUTPUT"
echo "Checking coverage against: $MERGE_BASE"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Download coverage file
uses: actions/download-artifact@v4
with:
name: coverage-file
- name: Check coverage cache
id: cache-coverage
uses: actions/cache@v4
with:
path: coverage.base.out
key: coverage-${{ steps.merge_base.outputs.merge_base }}
- name: Generate base coverage
if: steps.cache-coverage.outputs.cache-hit != 'true'
run: |
# Get coverage from base branch
git checkout ${{ steps.merge_base.outputs.merge_base }}
COVERAGE=coverage.base.out make unit-test
- name: Save coverage to cache
if: steps.cache-coverage.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: coverage.base.out
key: coverage-${{ steps.merge_base.outputs.merge_base }}
- name: Compare coverage
id: compare
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
BASE_REF: ${{ github.base_ref }}
HEAD_REF: ${{ github.head_ref }}
run: |
# use go tool cover to calculate coverage percentage
base_coverage=$(go tool cover -func=coverage.base.out | grep total: | awk '{print $3}' | sed 's/%//')
pr_coverage=$(go tool cover -func=coverage.out | grep total: | awk '{print $3}' | sed 's/%//')

# Calculate difference
diff=$(echo "$pr_coverage - $base_coverage" | bc)
echo "diff=$diff" >> "$GITHUB_OUTPUT"

# Create comment content
if (( $(echo "$diff >= 0" | bc -l) )); then
trend="📈"
else
trend="📉"
fi

{
echo "Coverage Report $trend"
echo "| Branch | Commit | Coverage |"
echo "|--------|--------|----------|"
echo "| ${BASE_REF} | ${{ steps.merge_base.outputs.merge_base }} | ${base_coverage}% |"
echo "| ${HEAD_REF} | ${{ github.event.pull_request.head.sha }} | ${pr_coverage}% |"
echo "| | Difference | ${diff}% |"
} > comment.md
cat "comment.md" >> "$GITHUB_STEP_SUMMARY"
- name: Comment PR
uses: marocchino/sticky-pull-request-comment@d2ad0de260ae8b0235ce059e63f2949ba9e05943
if: github.event.pull_request.head.repo.full_name == github.repository
with:
recreate: true
path: comment.md
- name: Check coverage threshold
run: |
if (( $(echo "${{ steps.compare.outputs.diff }} < 0" | bc -l) )); then
echo "Error: Coverage difference (${{ steps.compare.outputs.diff }}%) is negative"
fi
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: goveralls -parallel-finish -ignore=test/* -service=github

libraryOwners:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -390,7 +322,9 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: go install gotest.tools/gotestsum@latest
- run: |
go install gotest.tools/gotestsum@latest
go install github.com/mattn/goveralls@latest
- name: set Apix Bot token
id: app-token
uses: mongodb/apix-action/token@3024080388613583e3bd119bfb1ab4b4dbf43c42
Expand All @@ -401,6 +335,12 @@ jobs:
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
TEST_CMD: gotestsum --junitfile e2e-tests.xml --format standard-verbose --
COVERAGE: coverage.out
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERAGE: coverage.out
run: goveralls -parallel -coverprofile="$COVERAGE" -ignore=test/* -service=github
- name: Test Summary
if: always()
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ e2e-test: build-debug ## Run E2E tests
.PHONY: e2e-test-snapshots
e2e-test-snapshots: build-debug ## Run E2E tests
UPDATE_SNAPSHOTS=false E2E_SKIP_CLEANUP=true DO_NOT_TRACK=1 $(TEST_CMD) -v -timeout $(E2E_TIMEOUT) -tags="e2eSnap" ${E2E_TEST_PACKAGES}. $(E2E_EXTRA_ARGS)
go tool covdata textfmt -i $(GOCOVERDIR) -o $(COVERAGE)

.PHONY: unit-test
unit-test: build-debug ## Run unit-tests
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Coverage Status](https://coveralls.io/repos/github/mongodb/mongodb-atlas-cli/badge.svg?branch=master)](https://coveralls.io/github/mongodb/mongodb-atlas-cli?branch=master)

## MongoDB Atlas CLI

The MongoDB Atlas CLI is a modern command line interface that enables you to manage MongoDB Atlas from the terminal.
Expand Down
Loading