在gitlab永久居民部队覆盖率增加

问题描述 投票:1回答:1

在努力通过要求的单元测试我EmberJS托管在gitlab项目每拉要求增加测试覆盖率,我想如果覆盖不增加管道失败。

我可以用istanbul得到覆盖率输出,并获得覆盖徽章显示正确使用正则表达式如下:

Gitlab CI screenshot

并使用该gitlab-ci.yml

image: sergiolepore/ember-cli

before_script:
  - yarn --ignore-engines
  - bower --allow-root install

"Ember Unit Tests":
  script:
    - COVERAGE=true npm test -- --filter=Unit
    - grep -o '"pct":\d*\.\d*' coverage/coverage-summary.json | head -1

我怎样才能得到下一个管道失败,如果覆盖面在PR下降?

ember.js gitlab code-coverage gitlab-ci
1个回答
0
投票

很多通过https://docs.gitlab.com/ee/ci/yaml/挖后,这里是我找到了解决办法:

1. Generate code coverage while executing tests

这条管道将使用coverage/.current存储作业之间下artifacts的覆盖率

"Ember Unit Tests":
  artifacts:
    paths:
      - coverage/.current
  script:
    - COVERAGE=true yarn test --filter=Unit
  after_script:
    - grep -o <regex> coverage.json >> coverage/.current

2. Compare code coverage with stored "max" coverage (0 by default)

如果覆盖率下降,只返回一个非零退出代码(谢谢力士!)

"Increase Coverage":
  before_script:
    - MAX=`if [ -f coverage/.max ] ; then cat coverage/.max ; else echo 00.00 ; fi`
    - CURRENT=`cat coverage/.current`
  script: if [[ $CURRENT < $MAX ]] ; then exit 1 ; fi

3. Update the "max" coverage when merging pull requests

"Update Max Coverage":
  except:
    - pushes
  before_script:
    - NEW_MAX=`cat coverage/.current`
  script: echo $NEW_MAX > coverage/.max

使用stages连续运行这三个管道,不要忘记缓存管线之间的“最大”报道:

cache:
  paths:
    - coverage/.max
© www.soinside.com 2019 - 2024. All rights reserved.