Skip to main content
3 of 6
added 7175 characters in body
JShoe
  • 75
  • 8

How do I integrate Unity and CodeCov?

I'm working on a new project using TDD, and I remember on an old project with a friend I used CodeCov, and loved it.

Right now I'm generating coverage reports using Unity's Code Coverage package. I'm not, however, super well-versed in things like random .ymls and build instructions.

What do I have to do in order to send my coverage reports to CodeCov? I see my auth token I have to include, I see my coverage reports when I generate them, I just can't find any simple and entry-level documentation on how to smack the two together.

Edit, Current Update (2):

GitHub actions now attempts to upload my coverage reports to CodeCov, but I get an error. Below is my most recent GitHub Action code, and the error I'm receiving from CodeCov. Please let me know if there is any more information I cam provide.

CodeCov Error

GitHub Action

name: Build

on: 
  push:
    branches: [master]
  pull_request:
    branches: [master]

env:
  UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}

jobs:
  testRunner:
    name: Test in ${{ matrix.testMode }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        testMode:
          - EditMode
          - PlayMode
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-test-project-${{ matrix.targetPlatform }}
          restore-keys: |
            Library-test-project-
            Library-

      - uses: game-ci/[email protected]
        id: testRunner
        with:
          testMode: ${{ matrix.testMode }}
          checkName: ${{ matrix.testMode }} test results
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          customParameters: -debugCodeOptimization -enableCodeCoverage -coverageResultsPath ./coverage-results -coverageOptions generateAdditionalMetrics


      - uses: actions/upload-artifact@v2
        with:
          name: Test results (${{ matrix.testMode }})
          path: ${{ steps.testRunner.outputs.artifactsPath }}
          
  codeCov:
    needs: testRunner
    name: Submit to CodeCov
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Upload XML report to Codecov
        uses: codecov/codecov-action@v2
        with:
          name: CodeCov
          flags: automated
          token: ${{ secrets.CODECOV_TOKEN }}
          files: coverage-results/**/*.xml
          


  buildWebGL:
    needs: codeCov
    name: Build for WebGL
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-build-WebGL
          restore-keys: |
            Library-build-
            Library-

      - uses: game-ci/unity-builder@v2
        with:
          targetPlatform: WebGL

      - uses: actions/upload-artifact@v2
        with:
          name: build-WebGL
          path: build/WebGL

  buildWindows:
    needs: codeCov
    name: Build for Windows
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-build-StandaloneWindows64
          restore-keys: |
            Library-build-
            Library-

      - uses: game-ci/unity-builder@v2
        with:
          targetPlatform: StandaloneWindows64

      - uses: actions/upload-artifact@v2
        with:
          name: build-StandaloneWindows64
          path: build/StandaloneWindows64

  buildAndroid:
    needs: codeCov
    name: Build for Android
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-build-Android
          restore-keys: |
            Library-build-
            Library-

      - uses: game-ci/unity-builder@v2
        with:
          targetPlatform: Android

      - uses: actions/upload-artifact@v2
        with:
          name: build-Android
          path: build/Android


  deployPages:
    needs: buildWebGL
    name: Deploy to Github Pages
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - uses: actions/download-artifact@v2
        with:
          name: build-WebGL
          path: build

      - name: Deploy
        uses: JamesIves/[email protected]
        with:
          branch: gh-pages
          folder: build/WebGL

Edit, Update (old):

I now have Github Actions fully configured to test and build my project. I've included that code below. Just above that is a bit of code that I found that should (I think?) submit my report to codecov. I haven't quite figured out how to put them together, neither had great resources on formatting the .yml correctly.

The Snippet

   - name: Upload XML report to Codecov
     uses: codecov/codecov-action@v2
     with:
       name: PlayMode
       flags: automated
       token: ${{ secrets.CODECOV_TOKEN }}
       files: coverage-results/**/*.xml

My build.yml

name: Build

on: push

env:
  UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}

jobs:
  testRunner:
    name: Test in ${{ matrix.testMode }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        testMode:
          - EditMode
          - PlayMode
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-test-project-${{ matrix.targetPlatform }}
          restore-keys: |
            Library-test-project-
            Library-

      - uses: game-ci/[email protected]
        id: testRunner
        with:
          testMode: ${{ matrix.testMode }}
          checkName: ${{ matrix.testMode }} test results
          githubToken: ${{ secrets.GITHUB_TOKEN }}

      - uses: actions/upload-artifact@v2
        with:
          name: Test results (${{ matrix.testMode }})
          path: ${{ steps.testRunner.outputs.artifactsPath }}

  buildWebGL:
    needs: testRunner
    name: Build for WebGL
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-build-WebGL
          restore-keys: |
            Library-build-
            Library-

      - uses: game-ci/unity-builder@v2
        with:
          targetPlatform: WebGL

      - uses: actions/upload-artifact@v2
        with:
          name: build-WebGL
          path: build/WebGL

  buildWindows:
    needs: testRunner
    name: Build for Windows
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-build-StandaloneWindows64
          restore-keys: |
            Library-build-
            Library-

      - uses: game-ci/unity-builder@v2
        with:
          targetPlatform: StandaloneWindows64

      - uses: actions/upload-artifact@v2
        with:
          name: build-StandaloneWindows64
          path: build/StandaloneWindows64

  buildAndroid:
    needs: testRunner
    name: Build for Android
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create LFS file list
        run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

      - name: Restore LFS cache
        uses: actions/cache@v2
        id: lfs-cache
        with:
          path: .git/lfs
          key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}

      - name: Git LFS Pull
        run: |
          git lfs pull
          git add .
          git reset --hard

      - name: Restore Library cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-build-Android
          restore-keys: |
            Library-build-
            Library-

      - uses: game-ci/unity-builder@v2
        with:
          targetPlatform: Android

      - uses: actions/upload-artifact@v2
        with:
          name: build-Android
          path: build/Android


  deployPages:
    needs: buildWebGL
    name: Deploy to Github Pages
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - uses: actions/download-artifact@v2
        with:
          name: build-WebGL
          path: build

      - name: Deploy
        uses: JamesIves/[email protected]
        with:
          branch: gh-pages
          folder: build/WebGL
JShoe
  • 75
  • 8