Skip to content

Commit e84041f

Browse files
authored
CLOUDP-324670 move coverage to coveralls.io (#4069)
1 parent 9077263 commit e84041f

File tree

3 files changed

+27
-84
lines changed

3 files changed

+27
-84
lines changed

.github/workflows/code-health.yml

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
runs-on: ${{ matrix.os }}
3535
steps:
3636
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
37-
if: ${{ matrix.os=='ubuntu-latest' }}
37+
if: matrix.os == 'ubuntu-latest'
3838
with:
3939
config: ${{ vars.PERMISSIONS_CONFIG }}
4040
- name: Checkout repository
@@ -45,108 +45,40 @@ jobs:
4545
uses: actions/setup-go@v5
4646
with:
4747
go-version-file: 'go.mod'
48-
- run: go install gotest.tools/gotestsum@latest
48+
- run: |
49+
go install gotest.tools/gotestsum@v1.12.3
50+
go install github.com/mattn/goveralls@v0.0.12
4951
- run: make unit-test
52+
- name: Send coverage
53+
env:
54+
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
55+
run: goveralls -parallel -coverprofile="$COVERAGE" -ignore=test/* -service=github
5056
- name: Test Summary
5157
id: test_summary
5258
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
5359
with:
5460
paths: unit-tests.xml
5561
if: always() && matrix.os == 'ubuntu-latest'
56-
- name: Upload coverage file
57-
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
58-
uses: actions/upload-artifact@v4
59-
with:
60-
name: coverage-file
61-
path: coverage.out
6262

63-
code-coverage:
64-
permissions:
65-
pull-requests: write # Required to comment on PRs
66-
needs: unit-tests
67-
if: github.event_name == 'pull_request'
63+
coverage:
6864
runs-on: ubuntu-latest
65+
needs: [unit-tests, e2e-tests]
6966
steps:
7067
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
7168
with:
7269
config: ${{ vars.PERMISSIONS_CONFIG }}
7370
- name: Checkout repository
7471
uses: actions/checkout@v4
75-
with:
76-
fetch-depth: 0
77-
- name: Get merge base
78-
id: merge_base
79-
run: |
80-
MERGE_BASE=$(git merge-base "${{ github.event.pull_request.head.sha }}" "${{ github.event.pull_request.base.sha }}")
81-
echo "merge_base=$MERGE_BASE" >> "$GITHUB_OUTPUT"
82-
echo "Checking coverage against: $MERGE_BASE"
8372
- name: Install Go
8473
uses: actions/setup-go@v5
8574
with:
8675
go-version-file: 'go.mod'
87-
- name: Download coverage file
88-
uses: actions/download-artifact@v4
89-
with:
90-
name: coverage-file
91-
- name: Check coverage cache
92-
id: cache-coverage
93-
uses: actions/cache@v4
94-
with:
95-
path: coverage.base.out
96-
key: coverage-${{ steps.merge_base.outputs.merge_base }}
97-
- name: Generate base coverage
98-
if: steps.cache-coverage.outputs.cache-hit != 'true'
99-
run: |
100-
# Get coverage from base branch
101-
git checkout ${{ steps.merge_base.outputs.merge_base }}
102-
COVERAGE=coverage.base.out make unit-test
103-
- name: Save coverage to cache
104-
if: steps.cache-coverage.outputs.cache-hit != 'true'
105-
uses: actions/cache/save@v4
106-
with:
107-
path: coverage.base.out
108-
key: coverage-${{ steps.merge_base.outputs.merge_base }}
109-
- name: Compare coverage
110-
id: compare
76+
- name: Install goveralls
77+
run: go install github.com/mattn/goveralls@v0.0.12
78+
- name: Send coverage
11179
env:
112-
BASE_REF: ${{ github.base_ref }}
113-
HEAD_REF: ${{ github.head_ref }}
114-
run: |
115-
# use go tool cover to calculate coverage percentage
116-
base_coverage=$(go tool cover -func=coverage.base.out | grep total: | awk '{print $3}' | sed 's/%//')
117-
pr_coverage=$(go tool cover -func=coverage.out | grep total: | awk '{print $3}' | sed 's/%//')
118-
119-
# Calculate difference
120-
diff=$(echo "$pr_coverage - $base_coverage" | bc)
121-
echo "diff=$diff" >> "$GITHUB_OUTPUT"
122-
123-
# Create comment content
124-
if (( $(echo "$diff >= 0" | bc -l) )); then
125-
trend="📈"
126-
else
127-
trend="📉"
128-
fi
129-
130-
{
131-
echo "Coverage Report $trend"
132-
echo "| Branch | Commit | Coverage |"
133-
echo "|--------|--------|----------|"
134-
echo "| ${BASE_REF} | ${{ steps.merge_base.outputs.merge_base }} | ${base_coverage}% |"
135-
echo "| ${HEAD_REF} | ${{ github.event.pull_request.head.sha }} | ${pr_coverage}% |"
136-
echo "| | Difference | ${diff}% |"
137-
} > comment.md
138-
cat "comment.md" >> "$GITHUB_STEP_SUMMARY"
139-
- name: Comment PR
140-
uses: marocchino/sticky-pull-request-comment@d2ad0de260ae8b0235ce059e63f2949ba9e05943
141-
if: github.event.pull_request.head.repo.full_name == github.repository
142-
with:
143-
recreate: true
144-
path: comment.md
145-
- name: Check coverage threshold
146-
run: |
147-
if (( $(echo "${{ steps.compare.outputs.diff }} < 0" | bc -l) )); then
148-
echo "Error: Coverage difference (${{ steps.compare.outputs.diff }}%) is negative"
149-
fi
80+
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
81+
run: goveralls -parallel-finish -ignore=test/* -service=github
15082

15183
libraryOwners:
15284
runs-on: ubuntu-latest
@@ -390,7 +322,9 @@ jobs:
390322
uses: actions/setup-go@v5
391323
with:
392324
go-version-file: 'go.mod'
393-
- run: go install gotest.tools/gotestsum@latest
325+
- run: |
326+
go install gotest.tools/gotestsum@v1.12.3
327+
go install github.com/mattn/goveralls@v0.0.12
394328
- name: set Apix Bot token
395329
id: app-token
396330
uses: mongodb/apix-action/token@3024080388613583e3bd119bfb1ab4b4dbf43c42
@@ -401,6 +335,12 @@ jobs:
401335
env:
402336
GH_TOKEN: ${{ steps.app-token.outputs.token }}
403337
TEST_CMD: gotestsum --junitfile e2e-tests.xml --format standard-verbose --
338+
COVERAGE: coverage.out
339+
- name: Send coverage
340+
env:
341+
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
342+
COVERAGE: coverage.out
343+
run: goveralls -parallel -coverprofile="$COVERAGE" -ignore=test/* -service=github
404344
- name: Test Summary
405345
if: always()
406346
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ e2e-test: build-debug ## Run E2E tests
181181
.PHONY: e2e-test-snapshots
182182
e2e-test-snapshots: build-debug ## Run E2E tests
183183
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)
184+
go tool covdata textfmt -i $(GOCOVERDIR) -o $(COVERAGE)
184185

185186
.PHONY: unit-test
186187
unit-test: build-debug ## Run unit-tests

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![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)
2+
13
## MongoDB Atlas CLI
24

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

0 commit comments

Comments
 (0)