License activation failure cause exit code 0
Bug description If unity in the container got the wrong license activation file (or credentials, I guess, didn't check) it fails to build / test with exit code 0. Which is threatened as a successful run.
How to reproduce
- Put to secrets wrong license (outdated, another version, etc)
- Run pipeline
Expected behavior
- Docker should exit with non-zero code
Closed. For details - @webbertakken
Thank you for reporting this issue.
This is a bug in Unity editor itself, which doesn't omit a non-zero exit code when hardware ids mismatch or in some cases where invalid licenses are given.
Workaround
Most people move past this by fixing their activation while setting up their project, since the actual build step uses proper exit codes (which you can extend yourself inside the build script).
Additional information
It's a bug that predates this very repository and has been reported in unity-actions, unity-builder and in repository of the preceeding images gableroux/unity3d and the gableroux/unity3d-gitlab-ci-example.
Since we can't rely on exit code (pre-build-time anyway) we would have to either inject something in the binary or somehow extract the right information out of the output. So far nobody has come up with a reliable way to do this.
To anyone reading this, feel free to reopen if you have suggestions on how to solve this in an elegant way.
In some failing cases, the output will be different.
tl; dr
How to check activation result:
unity-editor -quit -logFile activation.log -manualLicenseFile <UNITY_LICENSE_FILE>
[ -z "`grep -e 'Next license update check is after' activation.log`" ] && echo 'error: Failed to load license file'
[ -n "`grep -e 'Failed to load license file from' activation.log`" ] && echo 'error: Failed to load license file'
[ -n "`grep -e 'LICENSE SYSTEM.* != ' activation.log`" ] && echo 'error: Machine ID is different'
Success
$ unity-editor -quit -logFile /dev/stdout -manualLicenseFile success.ulf
...
Load manual activation license file.
LICENSE SYSTEM [2021120 17:25:14] Load license file from: success.ulf
LICENSE SYSTEM [2021120 17:25:14] Next license update check is after 2021-01-21T17:04:09
License file loaded.
Failed: Machine ID is different
$ unity-editor -quit -logFile /dev/stdout -manualLicenseFile unmatched_machine_id.ulf
...
Load manual activation license file.
LICENSE SYSTEM [2021120 17:11:47] Load license file from: unmatched_machine_id.ulf
LICENSE SYSTEM [2021120 17:11:47] Next license update check is after 2021-01-21T17:10:34
LICENSE SYSTEM [2021120 17:11:47] 576562626572264761624c65526f7578 != B2DD8DE7-7E63-5962-95B4-3EEA5A1718C0
LICENSE SYSTEM [2021120 17:11:47] 576562626572264761624c65526f7578 != C02VQ158HTDG
License file loaded.
Failed: The input file is not found
$ unity-editor -quit -logFile /dev/stdout -manualLicenseFile non_exist.ulf
...
Load manual activation license file.
LICENSE SYSTEM [2021120 17:20:50] Load license file from: non_exist.ulf
LICENSE SYSTEM [2021120 17:20:50] Failed to load license file from: non_exist.ulf
License file loaded.
Failed: The input file is empty
$ unity-editor -quit -logFile /dev/stdout -manualLicenseFile empty.ulf
...
Load manual activation license file.
LICENSE SYSTEM [2021120 17:13:55] Load license file from: empty.ulf
LICENSE SYSTEM [2021120 17:13:55] Failed to load license file from: empty.ulf
License file loaded.
Failed: The input file is alf
$ unity-editor -quit -logFile /dev/stdout -manualLicenseFile Unity.alf
...
Load manual activation license file.
LICENSE SYSTEM [2021120 17:17:5] Load license file from: Unity.alf
LICENSE SYSTEM [2021120 17:17:5] Could not find digest XML element in license file.
License file loaded.
Failed: The structure of the input file is different
$ unity-editor -quit -logFile /dev/stdout -manualLicenseFile different_structure.ulf
...
Load manual activation license file.
LICENSE SYSTEM [2021120 17:15:16] Load license file from: different_structure.ulf
License file loaded.
So if we want to support this, we should have some way to parse unity's output to provide more insights on the error. It is probably feasible, but the solution should be discussed as this is definitely something that can make things more complicated in the project (and we want to keep actions as simple as possible here).
Edit: I missed the How to check activation result: part above sorry for confusion.
Should we execute unity command with tee instead? example: | tee unity_stdout.log and after the step, cat unity_stdout.log | grep '<some possible errors>'?
-logFile /dev/stdout should be kept otherwise, output won't be streamed to job's stdout.
Or is it possible (and desired) to run suggested command above and then proceed with a build in the actions?
If we pipe it into an application, it should be something that can also forward non-zero exit codes while still logging to console.
Or perhaps we can use PIPESTATUS[0] as explained in this answer on StackOverflow.
Reopening as it seems we have some ways to move forward. I have attempted it before, back when starting builder action, but I didn't manage to get it to work back then.
PRs are most welcome on this one :)
When a license activation fails, additional context can be output using the solution described above. For example:
- Run Unity with
-createManualActivationFileoption to create and output a new alf file- Users can fix the license activation error without any new workflow (
unity-request-activation-fileaction)
- Users can fix the license activation error without any new workflow (
- Output about "how to activate a license" (i.e. "what should you do next")
- e.g. "See the
Converting into a licensesection in https://game.ci/docs/github/activation"
- e.g. "See the
Do you have any suggestions?
I really like that idea, however I would keep them separate for now. The idea is to fully automate activation.
There's an issue for it https://github.com/game-ci/unity-builder/issues/193.
So I'd keep the scope to activation only for now (thus excluding requesting activation file).