3

Introduction

I have written a Swift Package and would like to integrate Codecov as a part of my CI (set up with Github Actions).

Here is my .yml file:

name: Swift  
  
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v3
    - name: Build
      run: swift build -v
    - name: Run tests
      run: swift test -v --enable-code-coverage
    - name: Upload to Codecov
      uses: codecov/codecov-action@v3.1.0

The Problem

The problem is that Codecov doesn't work with the report files generated by xcodebuild or swift commands. Here is the doc.

Github action log


Possible Solution

Codecov suggests using other third-party tools, such as Slather, to convert the reported files into expected formats (.xml, .json, etc.), but Slather is not compatible with Swift Packages (works only with .xcodeproj or .xcworkspace projects).


Could you please help here or suggest alternative approaches? Thanks.

narek.sv
  • 845
  • 5
  • 22

1 Answers1

0

I hit the same thing recently, but noted that the JSON code coverage files are generated, the uploader just doesn't know where they are or how to search for them.

You can specify them by explicit location, and there's a JSON file that's generated. However, it seems that CodeCov can't deal with the JSON format, so you need to do additional work to convert the darned setup into lcov format.

My stanza to do this conversion is based on a thread in CodeCov's support forums - which is slightly out of date, but the gist of converting with llvm-cov was there.

    - name: Prepare Code Coverage
      run: xcrun llvm-cov export -format="lcov" .build/debug/AutomergeSwiftAdditionsPackageTests.xctest/Contents/MacOS/AutomergeSwiftAdditionsPackageTests  -instr-profile .build/debug/codecov/default.profdata > info.lcov

    - name: Upload coverage reports to Codecov
      uses: codecov/codecov-action@v3
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        files: info.lcov

heckj
  • 7,136
  • 3
  • 39
  • 50