5

I was just wondering what’s the best way to configure codecov for a monorepo setting. For example, let’s say I have packages A and B under my monorepo. The way I’m currently using codecov is by using a github action codecov/codecov-action@v1, by using multiple uses statement in my GitHub workflow YAML file like the following:-

- uses: codecov/codecov-action@v1
  with:
    files: ./packages/A/coverage/lcov.info
    flags: flag_a
    name: A
- uses: codecov/codecov-action@v1
  with:
    files: ./packages/B/coverage/lcov.info
    flags: flag_b
    name: B

I know it's possible to use a comma-separated value to upload multiple files, but I have to set a separate flag for each package, and doing it that way doesn't seem to work. Thank you.

Devorein
  • 1,112
  • 2
  • 15
  • 23

1 Answers1

2

If anyone wants to know my solution, heres what I came up with. I ended up replacing the github action with my own bash script.

final code 
#!/usr/bin/env bash

codecov_file="${GITHUB_WORKSPACE}/scripts/codecov.sh"

curl -s https://codecov.io/bash > $codecov_file
chmod +x $codecov_file

cd "${GITHUB_WORKSPACE}/packages";

for dir in */
  do
    package="${dir/\//}"
    if [ -d "$package/coverage" ]
      then
        file="$PWD/$package/coverage/lcov.info"
        flag="${package/-/_}"
        $codecov_file -f $file -F $flag -v -t $CODECOV_TOKEN
      fi
  done

this is what the above bash script does

  1. Downloading the bash uploader script from codecov
  2. Moving to the packages directory where are the packages are located, and going through all the 1st level directories
  3. Change the package name by removing extra slash
  4. If the directory contains coverage directory only then enter into it, since only those packages have been tested.
  5. Create a file and flag variable (removing hypen with underscore as codecov doesn't support hypen in flag name)
  6. Executed the downloaded codecov script by passing the file and flag variable as argument
Devorein
  • 1,112
  • 2
  • 15
  • 23