game-ci / unity-builder

Build Unity projects for different platforms
https://github.com/marketplace/actions/unity-builder
MIT License
845 stars 244 forks source link

Failed to run "git fetch" #622

Open asbjornu opened 8 months ago

asbjornu commented 8 months ago

Bug description

As mentioned in https://github.com/game-ci/unity-builder/issues/564#issuecomment-1892023344, I'm experiencing the following problem when trying to build my Unity project with game-ci/unity-builder@v4:

Warning: Fetch --unshallow caught: Error: Failed to run "git fetch --unshallow".
 In-command error caught: Error: The process '/usr/bin/git' failed with exit code 128
Error: Failed to run "git fetch".
 In-command error caught: Error: The process '/usr/bin/git' failed with exit code 128

How to reproduce

I'm not sure how to reproduce this, but this is a WebGL build if that matters.

Expected behavior

game-ci/unity-builder shouldn't fail to run git fetch. I wonder why it is running git fetch at all. Can anyone please provide details as to why it is and possibly how to avoid it?

Additional information

The GitHub action configuration looks like the following:

      - uses: game-ci/unity-builder@v4
        env:
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
          UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
        with:
          allowDirtyBuild: true
          targetPlatform: WebGL
          versioning: Semantic
asbjornu commented 8 months ago

Adding fetch-depth: 0 to actions/checkout seems to have fixed the problem. As that slows down the build, it would be nice to know why unity-builder is performing git fetch --unshallow and if anything can be done to disable that behavior.

AndrewKahr commented 8 months ago

It's doing this to help it generate the version number in semantic mode. If you don't want to have it run the clone with depth 0 you should be able to set the versioning to custom and pass in your own version number and it should skip the shallow check.

asbjornu commented 8 months ago

I see. Perhaps it should be mentioned in the documentation that versioning: Semantic leads to a git fetch --unshallow? Some logging from within Versioning.isShallow() would also be useful.

https://github.com/game-ci/unity-builder/blob/5ba81971e2e97bbbb807a2621c8e6e79cd739d18/src/model/versioning.ts#L179-L183

It might perhaps be that git rev-parse --is-shallow-repository for some reason doesn't always produce the expected false\n output?

asbjornu commented 8 months ago

Oh, reading the code, I see that first a git fetch --unshallow is invoked. If it fails, it only leads to a warning. However, a regular git fetch is performed right after, and if that fails, it leads to an error.

https://github.com/game-ci/unity-builder/blob/5ba81971e2e97bbbb807a2621c8e6e79cd739d18/src/model/versioning.ts#L192-L199

For some reason, the result from both fetch operations is The process '/usr/bin/git' failed with exit code 128, which isn't very helpful. It seems like the underlying error message is swallowed by the git() method passing shouldLog = false to System.run():

https://github.com/game-ci/unity-builder/blob/5ba81971e2e97bbbb807a2621c8e6e79cd739d18/src/model/versioning.ts#L265-L267

Whether logging should be performed here could possibly be a configurable option on the action, no?