Skip to content

Add Code Coverage GH action #654

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Code Coverage

on:
pull_request:
push:
# trying and staging branches are for BORS config
branches:
- trying
- staging
- main

permissions:
contents: read
issues: write

env:
CARGO_TERM_COLOR: always

jobs:
coverage:
# Will not run if the event is a PR to bump-meilisearch-v* (so a pre-release PR)
# Will still run for each push to bump-meilisearch-v*
# Will not run if the actor is Dependabot (dependabot PRs)
if: github.event_name != 'pull_request' || !startsWith(github.base_ref, 'bump-meilisearch-v') || github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
Comment on lines +21 to +25
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Fix the conditional logic to properly skip bump and Dependabot PRs
The current if uses OR (||) in a way that still runs the job for bump-meilisearch PRs and Dependabot PRs, contrary to the intended behavior. To skip when it's a PR and either the base ref starts with bump-meilisearch-v or the actor is Dependabot, update to:

-    if: github.event_name != 'pull_request' || !startsWith(github.base_ref, 'bump-meilisearch-v') ||  github.actor != 'dependabot[bot]'
+    if: github.event_name != 'pull_request' || ( !startsWith(github.base_ref, 'bump-meilisearch-v') && github.actor != 'dependabot[bot]' )

This ensures only non-PR events or PRs targeting non-bump branches by non-Dependabot actors will run.

🤖 Prompt for AI Agents
In .github/workflows/coverage.yml around lines 21 to 25, the conditional logic
in the `if` statement incorrectly uses OR operators, causing the job to run for
bump-meilisearch PRs and Dependabot PRs when it should skip them. Update the
condition to use AND and OR properly so that the job only runs if the event is
not a pull request or if it is a pull request but the base ref does not start
with 'bump-meilisearch-v' and the actor is not 'dependabot[bot]'. This will
correctly skip the job for bump and Dependabot PRs.

name: Code Coverage
steps:
- uses: actions/checkout@v4
# Nightly Rust is used for cargo llvm-cov --doc below.
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Meilisearch (latest version) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
Comment on lines +37 to +38
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add a health check to ensure Meilisearch is ready before coverage runs
Right now the container is started but there's no wait, which can lead to flaky failures if the service isn't up when tests run. For example:

-      - name: Meilisearch (latest version) setup with Docker
-        run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
+      - name: Meilisearch (latest version) setup with Docker
+        run: |
+          docker run -d --name meilisearch -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
+          # Wait until Meilisearch is healthy
+          until curl --silent --fail http://localhost:7700/health; do
+            sleep 1
+          done

This ensures the service is reachable before coverage collection begins.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Meilisearch (latest version) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
- name: Meilisearch (latest version) setup with Docker
run: |
docker run -d --name meilisearch -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
# Wait until Meilisearch is healthy
until curl --silent --fail http://localhost:7700/health; do
sleep 1
done
🤖 Prompt for AI Agents
In .github/workflows/coverage.yml at lines 37 to 38, the Meilisearch Docker
container is started without a health check, which can cause flaky test failures
if the service isn't ready. Add a step after starting the container that waits
for Meilisearch to be reachable, such as using a loop with curl or a similar
command to poll the service endpoint until it responds successfully before
proceeding with coverage collection.

- name: Collect coverage data
# Generate separate reports for tests and doctests, and combine them.
run: |
cargo llvm-cov --no-report --all-features --workspace
cargo llvm-cov --no-report --doc --all-features --workspace
cargo llvm-cov report --doctests --codecov --output-path codecov.json
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: codecov.json
fail_ci_if_error: true
Loading