在努力通过要求的单元测试我EmberJS托管在gitlab项目每拉要求增加测试覆盖率,我想如果覆盖不增加管道失败。
我可以用istanbul得到覆盖率输出,并获得覆盖徽章显示正确使用正则表达式如下:
并使用该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下降?
很多通过https://docs.gitlab.com/ee/ci/yaml/挖后,这里是我找到了解决办法:
这条管道将使用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
如果覆盖率下降,只返回一个非零退出代码(谢谢力士!)
"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
"Update Max Coverage":
except:
- pushes
before_script:
- NEW_MAX=`cat coverage/.current`
script: echo $NEW_MAX > coverage/.max
使用stages连续运行这三个管道,不要忘记缓存管线之间的“最大”报道:
cache:
paths:
- coverage/.max