Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring in CI pipeline #414

Closed
denravonska opened this issue Sep 1, 2021 · 9 comments
Closed

Restoring in CI pipeline #414

denravonska opened this issue Sep 1, 2021 · 9 comments

Comments

@denravonska
Copy link

denravonska commented Sep 1, 2021

Description

I'm trying to implement a build pipeline for a project which uses NuGetForUnity and Docker. As an initial step I want to install dependencies, following the command from the readme:

unity-editor -batchmode -projectPath /src -executeMethod NugetForUnity.NugetHelper.Restore

However, this seems to try to build my project which fails due to missing dependencies. Nothing in the logs shows that NuGetForUnity is invoked. Is there something I'm missing?

  • NuGet Package: N/A
  • NuGetForUnity Version: 3.0.2
  • Unity Version: 2020.3.17f1
  • Operating System: Linux in Docker
@denravonska denravonska changed the title Updating in CI pipeline Restoring in CI pipeline Sep 1, 2021
@jwittner
Copy link
Collaborator

jwittner commented Sep 1, 2021

We've had good luck with a two pass build method. Start up Unity once, lets N4U restore things, shut down. Then run again and do a real build and check for errors there.

We've had lots of trouble getting Unity to work well in Windows containers, would be cool to hear if you're successful on Linux.

@denravonska
Copy link
Author

denravonska commented Sep 2, 2021

Here's what I've found. If I run the command locally in a checkout where the library has been built once it works, even just by doing unity-editor -batchmode -quit like you suggested. If I remove the Library/ and Temp/ folders I get the same problem as in our pipeline where Unity tries to rebuild the library, failing due to compile errors and then aborts. So it never reaches the package restore.

@denravonska
Copy link
Author

I ended up using regular nuget with a cleanup step. A bit more clunky but it got the job done.

@jwittner
Copy link
Collaborator

jwittner commented Sep 2, 2021

Here's what I've found. If I run the command locally in a checkout where the library has been built once it works, even just by doing unity-editor -batchmode -quit like you suggested. If I remove the Library/ and Temp/ folders I get the same problem as in our pipeline where Unity tries to rebuild the library, failing due to compile errors and then aborts. So it never reaches the package restore.

That's interesting. If you're using the package you should have a dll for NugetForUnity and so the restore should happen even if there are build errors. Perhaps that's not true in newer versions of Unity, e.g. the ones with 'safe mode'? This behavior, where it continues to initialize assemblies even if other code fails to compile is a big reason we build the rather than shipping as code (this was before assembly defs existed of course).

@Strepto
Copy link

Strepto commented Sep 10, 2021

Try adding the -ignoreCompilerErrors flag to disable safe mode. See the very last text on this page: https://docs.unity3d.com/2020.2/Documentation/Manual/SafeMode.html . Its not listed on the standard "CommandLineArguments" docs anywhere, so its kinda hard to find.

unity-editor -batchmode -ignoreCompilerErrors -quit -projectPath /src -executeMethod NugetForUnity.NugetHelper.Restore

Updated with correct commands (based on comment below)

@denravonska
Copy link
Author

Try adding the -ignoreCompilerError flag to disable safe mode. See the very last text on this page: https://docs.unity3d.com/2020.2/Documentation/Manual/SafeMode.html . Its not listed on the standard "CommandLineArguments" docs anywhere, so its kinda hard to find.

unity-editor -batchmode -ignoreCompilerError -projectPath /src -executeMethod NugetForUnity.NugetHelper.Restore

Oh, there's an undocumented flag? I have it running through manual nuget now but I'll try that next week if I can remember.

@NoTuxNoBux
Copy link
Contributor

Just wanted to mention that it's -ignoreCompilerErrors with a trailing s according to the documentation. This makes a difference, the one without s doesn't do anything 😄.

@NoTuxNoBux
Copy link
Contributor

NoTuxNoBux commented Oct 8, 2021

I also needed to add -quit to the command line arguments to prevent CI from endlessly hanging.

If you are using Game CI, this becomes the following in e.g. test.sh, above the unity-editor line that runs Unity:

# Install NuGet packages through NuGetForUnity.
${UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
    -batchmode \
    -quit \
    -ignoreCompilerErrors \
    -projectPath $UNITY_DIR \
    -executeMethod NugetForUnity.NugetHelper.Restore

The only downside is that this makes the already slow pipeline even slower, from about 10 minutes to 15 minutes 😕 . We need NuGet packages, and NuGetForUnity works great, but together with #407 this is making the process of using them pretty painful - which, admittedly, is not entirely NuGetForUnity's fault.

Now I can finally get to fixing my tests, thanks for the help! 😄

@JoC0de
Copy link
Collaborator

JoC0de commented Feb 19, 2023

I finally released the CLI for restoring packages before starting Unity Editor NuGetForUnity.Cli.

@JoC0de JoC0de closed this as completed Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants