macxred / cashctrl_ledger

Implementation of the abstract pyledger.LegderEngine interface with CashCtrl accounting service.
MIT License
0 stars 0 forks source link

Add Codecov Integration #56

Closed lasuk closed 1 month ago

lasuk commented 3 months ago

Summary

This issue aims to integrate Codecov to improve our code coverage reporting and visibility and add badge to our README file.

Codecov is a tool that helps developers measure and analyze the percentage of source code that is executed during testing. By using Codecov, developers can identify which parts of their codebase are not covered by tests and take steps to improve their test coverage.

Steps

  1. Setup Codecov:

    • Add Codecov to the project by updating the CI configuration (e.g., GitHub Actions, Travis CI, etc.) to include Codecov in the test workflow.
    • Ensure the coverage reports are generated using a tool like pytest-cov.
  2. Add Codecov Badge:

    • After setting up Codecov, obtain the Codecov badge URL from the Codecov dashboard.
    • Update the README.md file to include the Codecov badge at the top of the file for visibility.
Example GitHub Actions Configuration

```yaml name: CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest pytest-cov codecov - name: Run tests run: | pytest --cov=./ - name: Upload coverage to Codecov run: | codecov env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} ```

Example README.md Badge

After setting up Codecov, add the following line to the top of your README.md to display the Codecov badge: ```markdown [![codecov](https://codecov.io/gh/USERNAME/REPOSITORY/branch/main/graph/badge.svg?token=YOURTOKEN)](https://codecov.io/gh/USERNAME/REPOSITORY) ``` Replace `USERNAME`, `REPOSITORY`, `main`, and `YOURTOKEN` with your respective GitHub username, repository name, branch name, and Codecov token.

Additional Resources

lasuk commented 3 months ago

Here's a more detailed explanation by CHatGPT. (Use if helpful. Ignore otherwise.)

Click to expand

# How to Use Codecov with a Python Package Hosted on GitHub ## 1. Create a Codecov Account - Sign up for a Codecov account if you haven't already. You can sign in using your GitHub account for easier integration. ## 2. Install Codecov in Your Project - Ensure you have `pytest` and `coverage` installed in your project. You can install them using pip: ```bash pip install pytest pytest-cov ``` - Install Codecov: ```bash pip install codecov ``` ## 3. Configure Your Tests - Update your `pytest` configuration to generate a coverage report. You can do this by adding a configuration file (`pytest.ini`, `setup.cfg`, or directly in the command line). Example using `pytest.ini`: ```ini [pytest] addopts = --cov=your_package_name --cov-report=xml ``` ## 4. Update Your GitHub Actions Workflow - Create or update your GitHub Actions workflow file (e.g., `.github/workflows/ci.yml`) to include steps for running tests and uploading the coverage report to Codecov. Example workflow file: ```yaml name: CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest strategy: matrix: python-version: [3.7, 3.8, 3.9, 3.10] steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest pytest-cov codecov - name: Run tests with coverage run: | pytest - name: Upload coverage to Codecov run: | bash <(curl -s https://codecov.io/bash) env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} ``` ## 5. Add Codecov Token to GitHub Secrets - Go to your repository on GitHub. - Navigate to `Settings` > `Secrets and variables` > `Actions`. - Click on `New repository secret` and add a secret named `CODECOV_TOKEN` with your Codecov token. ## 6. Push Changes and Verify - Commit and push your changes to GitHub. This will trigger the GitHub Actions workflow. - Check the workflow run in the `Actions` tab of your GitHub repository to ensure that the tests and Codecov upload steps are successful. - Visit your Codecov dashboard to verify that the coverage report has been uploaded correctly. By following these steps, you will integrate Codecov with your GitHub-hosted Python package, enabling automated coverage reporting and insights directly within your GitHub repository. # Do open source python projects usually add a codecov badge somewhere? **User:** Do open source python projects usually add a codecov badge somewhere? **Assistant:** Yes, open-source Python projects often add a Codecov badge to their README file. The badge provides a quick visual indicator of the project's test coverage status, making it easy for contributors and users to see the health of the codebase at a glance. Here's how you can add a Codecov badge to your project: 1. **Get the Codecov Badge URL:** - After setting up Codecov for your project, go to your project's dashboard on Codecov. - Look for the badge URL, which is usually in the settings or displayed on the project overview page. 2. **Add the Badge to Your README:** - Edit your project's `README.md` file. - Add the Markdown code for the badge at the top of the README file. Here is an example of how to add the badge: ```markdown # Your Project Name [![codecov](https://codecov.io/gh/username/repo/branch/main/graph/badge.svg)](https://codecov.io/gh/username/repo) ## Description Your project description goes here. ``` Replace `username`, `repo`, and `branch` with your GitHub username, repository name, and the branch you want to track, respectively. ### Example GitHub Issue to Add Codecov Badge You can create a GitHub issue to add the Codecov badge to your README file: --- **Title:** Add Codecov Badge to README **Description:** To provide a quick visual indicator of our project's test coverage, we should add a Codecov badge to the README file. This will help contributors and users to easily see the coverage status and maintain code quality. **Tasks:** 1. **Get the Codecov Badge URL:** - Go to the project's dashboard on Codecov. - Copy the badge URL provided by Codecov. 2. **Edit the README File:** - Open `README.md` in your project's root directory. - Add the following Markdown code at the top of the file, replacing `username`, `repo`, and `branch` with the appropriate values: ```markdown # Your Project Name [![codecov](https://codecov.io/gh/username/repo/branch/main/graph/badge.svg)](https://codecov.io/gh/username/repo) ## Description Your project description goes here. ``` 3. **Commit and Push Changes:** - Commit the changes to the README file. - Push the changes to the repository. **Benefits:** - Provides a quick visual indicator of test coverage. - Encourages contributors to maintain and improve test coverage. - Enhances the project's documentation by showing coverage status. **Resources:** - [Codecov Documentation](https://docs.codecov.com/docs) - [Codecov Badge](https://docs.codecov.com/docs/status-badges) --- Adding the Codecov badge is a simple but effective way to communicate the health of your project's codebase.