Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 37 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
test:
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write # Required to post comments on PRs

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -45,6 +49,7 @@ jobs:
- name: Install dependencies
run: |
uv pip install --system -r pyproject.toml --group dev
uv pip install --system pytest-cov # Ensure pytest-cov is installed

- name: Generate protobuf files
run: make generate
Expand All @@ -54,8 +59,39 @@ jobs:
PYTHONPATH: ./src
run: make test

- name: Post Coverage Comment
if: github.event_name == 'pull_request' # Only run on PRs
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment => comment.user.type === 'Bot' && comment.body.includes('**Total Test Coverage:**'));
const totalCoverage = process.env.total_coverage;
const commentBody = `**Total Test Coverage:** ${totalCoverage}%`;

if (botComment) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
});
}

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});

- name: Cleanup
if: always()
run: |
docker-compose down -v
rm -rf __pycache__ tests/__pycache__
rm -rf __pycache__ tests/__pycache__ coverage.out .coverage
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies = [
[dependency-groups]
dev = [
"pytest>=8.3.5",
"pytest-cov>=6.1.1",
]
20 changes: 18 additions & 2 deletions tools/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ cleanup() {
echo -e "<= Cleaning up resources..."
print_emoji_line "<=" "${BLUE}"
docker-compose down -v mongodb-test
rm -rf __pycache__ tests/__pycache__
rm -rf __pycache__ tests/__pycache__ coverage.out .coverage
# Only remove coverage.xml if it exists
[ -f coverage.xml ] && rm -f coverage.xml
}

# Set trap to call cleanup on exit (success or failure)
Expand All @@ -40,8 +42,22 @@ echo -e "=> Starting test environment..."
print_emoji_line "=>" "${YELLOW}"
docker-compose up -d mongodb-test
uv run tools/tests/wait_for_mongo.py
PYTHONPATH=./src python -m pytest src/tests/

# Conditionally set coverage report options based on CI environment
if [ "$CI" = "true" ]; then
cov_report="--cov-report=term-missing --cov-report=xml"
else
cov_report="--cov-report=term-missing"
fi

# Run pytest with coverage
PYTHONPATH=./src uv run pytest src/tests/ --cov=src $cov_report -v
pytest_exit_code=$?
# Extract total coverage percentage
total_coverage=$(uv run coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//')
echo "Total Coverage: $total_coverage%"
echo "total_coverage=$total_coverage" >> $GITHUB_ENV

if [ $pytest_exit_code -eq 0 ]; then
echo -e "${GREEN}🎉 Tests passed successfully!"
exit 0
Expand Down
Loading