Comparing artifact values for node coverage tests

Hello,

I would like to store the result of running “npx lcov-total coverage/lcov.info” as an artifact to then compare it with the next execution of the pipeline, and if this is a lower value than the previous one it should fail.

I would like to know how to store that value and call it to the new pipeline execution.

My config.yaml:

version: 2.1
orbs:
  node: circleci/node@5.0.2
jobs:
  build_and_test:
    executor: node/default
    steps:
      - checkout
      - save_cache:
          paths:
            - ~/project/node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - node/install-packages:
         cache-path: ~/project/node_modules
         app-dir: ~/project/
      - run: npm run test
      - run: npm run ci-coverage
      - run: npx lcov-total coverage/lcov.info
  
workflows:
  models_pipeline:
    jobs:
      - build_and_test

This is the value I need

Thanks in advance

If I got it right, you want to persist this value between workflow runs, am I right?
Off the top of my head, I think you could use cache here. Store the value in a file, cache it, and then restore the cache in the next workflow. I imagine the config looking something like

jobs:
  build_and_test:
    executor: node/default
    steps:
      - checkout
      - save_cache:
          paths:
            - ~/project/node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - node/install-packages:
         cache-path: ~/project/node_modules
         app-dir: ~/project/
      - run: npm run test
      - run: npm run ci-coverage
      - restore_cache:
          key: v1-result-cache # adjust the key to your needs
       # move cached file to a different location so its not overridden. 
       # First run won't have the file to move, ignore the error
      - run: mv /tmp/result /tmp/result-moved || true
      - run: npx lcov-total coverage/lcov.info > /tmp/result
      - run: compare values between /tmp/result and /tmp/result-moved, throw error if they don't match
       - save_cache:
          paths:
            - /tmp/result
          key:  v1-result-cache # adjust the key to your needs

  
workflows:
  models_pipeline:
    jobs:
      - build_and_test
1 Like

Thank you very much, it works perfectly!!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.