Skip to content
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

Add option to provide a source filepath for mono repos #11

Open
Raigen opened this issue Feb 10, 2021 · 2 comments
Open

Add option to provide a source filepath for mono repos #11

Raigen opened this issue Feb 10, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Raigen
Copy link

Raigen commented Feb 10, 2021

We have a mono repo with multiple packages working together. The tree looks similar to this

project root
-> packages
  -> package1
  -> package2
  -> package3

Each package has it's own test runs and own coverage files.
When I run cat packages/package1/coverage/lcov.info | coveralls, like the orb does, it can find the lcov informations, but the result is empty. The coverage file contains paths like src/views/App.js, without the package path. So this condition results in false because there is no src/views/App.js in the root directory.
node-coveralls has an option to provide an aditional filepath, see it here: https://github.com/nickmerwin/node-coveralls/blob/master/lib/getOptions.js#L246-L250
But I can not configure the Orb to utilize this option which means I have to manually install and use node-coveralls for my circleci builds like this:

      - run:
          name: Upload coverage reports to Coveralls
          shell: /bin/bash
          command: |
            npx coveralls packages/package1/ < packages/package1/coverage/lcov.info && \
            npx coveralls packages/package2/ < packages/package2/coverage/lcov.info && \
            npx coveralls packages/package3/ < packages/package3/coverage/lcov.info

A filepath option for source files is missing in the orb configuration. Without we are not able to use the orb, which I really would like to do.

@afinetooth afinetooth added the enhancement New feature or request label Mar 31, 2021
@jprice-da15252
Copy link

jprice-da15252 commented Apr 6, 2021

I recently encountered a similar situation with the orb.

Many of the problems I was having were related to the way CircleCI handles variables compounded by the way that our scripts are defined in our package.json files. I eventually abandoned the orb, and instead, I made a CircleCI command based on a slimmed-down version of it. The command uses the parallel feature of coveralls, and it was also executed after all tests had completed to finalize it in a similar way to the orb's method.

The monorepo root package.json script definitions are prepended with cd <package directory> &&. This works okay., but it makes persisting that directory a challenge in CircleCI.

To get around the issues in our fan-out, parallel testing scenario, I prepended this command: echo export test_cwd=$(pwd) > ../../.env.coverage.local && to each package’s npm test script definition. This allowed me to persist the unique working directory path for each test job and allowed each instance of the parallel Coveralls CircleCI command was able to source it for its COVERALLS_FLAG_NAME

Script definition in package1's package.json:

{
    "name": "package1",
    "scripts": {
        ...
        "test": "echo export test_cwd=$(pwd) >  ../../.env.coverage.local && <test command and args>",
        ...
     }
}

Script definition in root package.json:

{
    "name": "monorepoProject",
    "scripts": {
        ...
        "testPackage1": "cd packages/package1 && npm run test",
        ...
     }
}

CircleCI Command:

commands:
    coveralls:
        parameters:
            parallel_finished:
                type: boolean
                default: false
        steps:
            - run:
                  name: Send to Coveralls
                  command: |
                      if << parameters.parallel_finished >>; then
                        curl "https://coveralls.io/webhook?repo_token=${COVERALLS_REPO_TOKEN}" \
                            -d "payload[build_num]=$CIRCLE_WORKFLOW_ID&payload[status]=done"
                        exit 0
                      fi

                      env_file=./.env.coverage.local
                      if [ ! -f "$env_file" ]; then
                          echo "ERROR: ./.env.test.local not persisted.  Prepend this package's npm 'test' script definition with 'echo export test_cwd=$(pwd) >  ../../.env.coverage.local && '"
                          exit 1
                      fi
                      sudo npm i -g coveralls

                      source "$env_file"
                      COVERALLS_FLAG_NAME=$(basename ${test_cwd})
                      PATH_TO_LCOV=${test_cwd}/coverage/lcov.info
                      # Send it
                      cat $PATH_TO_LCOV | coveralls

Test Job:

    test-package1:
        <<: *defaults
        steps:
            ...
            - run: npm run-script testPackage1
            - coveralls

Finalize Job:


    coveralls-finalize:
        <<: *defaults
        steps:
            - coveralls:
                  parallel_finished: true

Workflow jobs:

workflows:
    version: 2
    main-branch-workflow:
        jobs:
            ...
            - test-package1:
                  <<: *filter-only-mains
            - test-package2:
                  <<: *filter-only-mains
            ...
            - coveralls-finalize:
                  <<: *filter-only-mains
                  requires:
                      - test-package1
                      - test-package2
             ...

@mrexox
Copy link
Contributor

mrexox commented Mar 17, 2023

Hey! There is a base_path option now available in latest or version. Please, try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants