Code Coverage for a Swift 3.0 Project in Gitlab CI

I have an iOS project written by Swift 3.0 with CocoaPods. I configured Gitlab CI for this project and it works great. This is my .gitlab-ci.yml file:

stages: - build build_project: stage: build script: - rm -rf Pods;rm -rf MyProject.xcworkspace;rm -rf MyProject.xcodeproj/project.xcworkspace - pod install - xcodebuild clean -workspace MyProject.xcworkspace -scheme MyProject | xcpretty - xcodebuild test -workspace MyProject.xcworkspace -scheme MyProject -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.2' | xcpretty -s tags: - ios - lunchdot 

I do not see code coverage for this project in my Gitlab repo. Currently, the coverage column for all my builds is empty. I tried to set up test coverage parsing in the Gitlab CI / CD Pipelines settings, but this did not affect, because I do not know the regex for Swift. Can I customize code coverage for a Swift project in Gitlab CI? How can i do this?

+6
source share
1 answer

So, I tried a million ways to do this, and the problem turned out to be xcpretty. After I deleted it, I started to get consistent results with my gitlab ci data. If you still do not want to receive tons of data that you do not need, you can use -quiet in the gitlab yams file. I will post it all, so keep reading.

Still need an external tool for analyzing coverage - xcov seems to be no longer available, so I used slather. Worked like a charm.

These are the following steps:

1) Get a slather .

2) Extract the .slather.yml file. My looks like this (obviously your AppApp application is your application):

 # .slather.yml coverage_service: cobertura_xml xcodeproj: ./YourApp.xcodeproj workspace: ./YourApp.xcworkspace scheme: YourApp source_directory: ./YourApp output_directory: path/to/xml_report ignore: - "**/Pods/*" - "thirdparty/*" - "./Scripts/*" - "**/3rdParty/*" - "../**/Developer/*" - "**/libraries/*" - "Module-Core/*" - "Module-Components/*" - "**/AppUnitTests/*" 

You can get the test result as html, xml, in codecov.io, etc., completely up to you. Check out the GitHub slather page for possible ways to do this. But for the current problem, all we need is a slather message on the command line, so gitlab can pick it up. This is where the correct configuration of the gitlab yaml file occurs.

3) Configure the .gitlab-ci.yml file. My looks like this:

 stages: - build build_project_1: stage: build script: - xcodebuild clean -workspace YourApp.xcworkspace -scheme YourApp -quiet - xcodebuild test -workspace YourApp.xcworkspace -scheme YourApp -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.3.1' -enableCodeCoverage YES -quiet after_script: - slather coverage -s only: - master 

4) Next step:

  • Go to the gitlab / profile page or whatever you name

  • Go to Settings and then Pipelines

Settings / piping

  • Scroll down to Test coverage parsing and add this regex expression: \d+\%\s*$

Add a regex expression to the provided space and then save it

And it's all. All you have to do is call assembly.

+5
source

Source: https://habr.com/ru/post/1013812/


All Articles