test-reporter icon indicating copy to clipboard operation
test-reporter copied to clipboard

fatal: Not a git repository

Open PaulDMendoza opened this issue 3 years ago • 14 comments

I'm not sure why but I'm getting this error.

image

My build script is a bit long so copying and pasting it all of here seems uneeded.

name: Tests

on:
  - push
  - pull_request
jobs:  
  test:
    runs-on: ubuntu-latest
    container: node:10.18-jessie
    strategy:
      matrix:
        dotnet-version:
          - 2.1.x
    services:
      postgres:
        image: postgis/postgis:10-2.5
        env:
          POSTGRES_PASSWORD: '111+++'
          POSTGRES_DB: sigparser        
          POSTGRES_USER: postgres
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    env:
      ...
    steps:
      - uses: actions/checkout@v2
      - name: 'Setup .NET Core SDK ${{ matrix.dotnet-version }}'
        uses: actions/[email protected]
        with:
          dotnet-version: '${{ matrix.dotnet-version }}'
      - name: Install dependencies
        run: dotnet restore
      - name: Run Migrations
        run: > 
          dotnet run 
          --project ./DBUpgrader/DBUpgrader.csproj 
          -- migrate  
          --recreate true
          --fillconfigkeytable true 
          --trycreateifnotexists true 
      - name: What directory are we in?
        run: pwd
      - name: Test
        run: dotnet test --logger "trx;LogFileName=test-results.trx"
      - name: Publish Unit Test Results
        uses: dorny/[email protected]
        if: always()
        with:
          name: Test Results
          path: ./**/TestResults/*.trx
          reporter: 'dotnet-trx'
  

PaulDMendoza avatar Jul 13 '21 01:07 PaulDMendoza

Well, this is really weird.

This action uses git to get a list of your tracked source files. For failed tests, it looks at the stack trace and the list of tracked files. The first row in the stack trace that points to any of tracked files is where the annotation will be created.

In your case, I see two possible errors:

  1. Working directory when test-reporter is executed doesn't point to the folder where your repository is checked out
  2. The .git folder got deleted somehow and your working directory is not a git repository.

I would recommend checking the working directory and the existence of the .git folder. In case, the working directory is wrong, you could set it using working-directory input variable.

dorny avatar Jul 13 '21 06:07 dorny

I figured it out. I had to add git init after I checked out the code.

steps:
      - uses: actions/checkout@v2
        with:
          token: '${{ secrets.GITHUB_TOKEN }}'
      - name: Run git init
        run: git init

PaulDMendoza avatar Jul 13 '21 18:07 PaulDMendoza

You found a workaround to make this action pass, but I'm not entirely sure it will work correctly. Looks like the checkout action in some cases downloads the files using GitHub REST API instead of a git. Honestly, I had no idea it could work like that. An example of this is here: https://github.com/actions/checkout/issues/335

Could you please check if you have something similar in your logs from the checkout action?

The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH

I already have a code that can list tracked files from GitHub REST API. However, it's used only when test results are received from artifacts. A proper solution would be to use the REST API also if the working folder is not a git repository.

dorny avatar Jul 17 '21 19:07 dorny

Hi!

Can we have a flag to disable any usage of git? (eg: disableAnnotations: true)

The use case is: I have a job for deployment, where I only need build related artifacts. I run the tests after deployment on the given environment. Ideally I do not want to checkout the source code.

nemad avatar Jul 26 '21 13:07 nemad

Yes, I can add this option. Hopefully next week. Shouldn't be much work

dorny avatar Jul 29 '21 19:07 dorny

@dorny did you have a chance to added this flag? I am also struggeling to just have a workaround git repo on my report summary job. Since I am only checking out code in a build stage but hand over all artifacts over the pipeline. I am doing integration tests I shouldn't need to checkout anything.

SebastianSchuetze avatar Nov 27 '21 12:11 SebastianSchuetze

@SebastianSchuetze you can use working-directory to set the dir where you checkout your code

alonashkenazi avatar Aug 29 '22 07:08 alonashkenazi

I too would love this flag

Also it seems like a weird dependency to have on git. You're building a test-report, not performing git operations. In my process I also discovered it break on some build-images, because git is not installed (which can also explain the usage of the REST API). It's strange having to install an extra unrelated tool for this task

rohde-januar avatar Jan 25 '23 10:01 rohde-januar

For me this flag is crucial for use with e2e tests. I use Detox with React-Native and Jest runner. So the report is getting generated with failed tests. But since the test code is not attached to any real app code, annotations fail to generate. Disabling them would make it possible to include the e2e tests report into PR.

antonandreyev avatar Mar 17 '23 07:03 antonandreyev

@rohde-januar @antonandreyev It's not well-documented, but setting max-annotations: '0' will disable annotations.

conreaux avatar Mar 23 '23 00:03 conreaux

I think the cause is being inside container:

container: node:10.18-jessie

Same for me with Alpine

gladykov avatar Mar 28 '23 23:03 gladykov

@rohde-januar @antonandreyev It's not well-documented, but setting max-annotations: '0' will disable annotations.

Thanks, that worked. Maybe would be nice to update the docs and suggest this until (if) the disableAnnotations: true or alike is implemented

antonandreyev avatar Mar 29 '23 10:03 antonandreyev

If anyone like me checkouts to subfolder, there is a solution, e.g. for a path ./backend/TestResults/*.trx, where git repository initialized by checkout action inside ./backend folder:

with:
   working-directory: backend
   path: ./TestResults/*.trx

It won't work with ./backend folder specified as a part of a path parameter though, as the action checks current working directory itself for being a git repository.

myzamaraev avatar Oct 07 '23 16:10 myzamaraev

Did I miss something? Doesn't this also break the recommended configuration for public repositories, as the Git repository is never cloned when using the configuration?

UPDATE: Looks like the recommended setup as documented isn't affected because there is a special case when the artifact option is provided:

https://github.com/dorny/test-reporter/blob/c40d89d5e987cd80f3a32b3c233556e22bdca958/src/main.ts#L83-L93

However, with Artifacts v4, we can no-longer use the artifact option right now. See #343 and #363.

JojOatXGME avatar May 03 '24 23:05 JojOatXGME