Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions dist/platforms/mac/steps/return_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ UNITY_LICENSE_RETURN_TRANSIENT_PATTERN='TimeoutPolicy did not complete|Access to
# Permanent by construction - see the guards below.
UNITY_LICENSE_RETURN_PERMANENT_PATTERN="Machine bindings don't match"

# Unity returns the licence and THEN exits non-zero. Measured on 2022.3.62f3,
# same container, matching machine id:
#
# [Licensing::Module] Error: Access token is unavailable; failed to update
# [Licensing::Module] Error: Failed to return entitlement license
# [Licensing::Client] Successfully returned ULF license with serial number: "..."
# exit=1
#
# The seat really is returned - a following --return-ulf reports "Ulf license
# file not found". But the exit code says failure and the log carries "Access
# token is unavailable", which is in the transient list, so this retried four
# times against an already-returned licence and then warned that the return had
# failed. Reported by a user still seeing "attempt 3/4" on v0.1.64, whose own
# log showed the same machine id throughout - which ruled out the binding
# mismatch that release had fixed.
#
# So success is read from the log, not the exit code, exactly as activation
# already does for the same reason in the opposite direction.
UNITY_LICENSE_RETURN_SUCCESS_PATTERN='Successfully returned ULF license|Successfully returned floating license|License has been returned'

if [[ "$RETURN_STRATEGY" == "floating" ]]; then
#
# Return any floating license used.
Expand All @@ -51,6 +71,11 @@ if [[ "$RETURN_STRATEGY" == "floating" ]]; then
--return-floating "$FLOATING_LICENSE" 2>&1 | tee "$RETURN_LOG"
RETURN_EXIT_CODE=${PIPESTATUS[0]}

if grep -qE "$UNITY_LICENSE_RETURN_SUCCESS_PATTERN" "$RETURN_LOG"; then
RETURN_EXIT_CODE=0
break
fi

if [ "$RETURN_EXIT_CODE" -eq 0 ]; then
break
fi
Expand Down Expand Up @@ -96,6 +121,11 @@ elif [[ "$RETURN_STRATEGY" == "personal" ]]; then
"$(unity_licensing_client_path)" --return-ulf 2>&1 | tee "$RETURN_LOG"
RETURN_EXIT_CODE=${PIPESTATUS[0]}

if grep -qE "$UNITY_LICENSE_RETURN_SUCCESS_PATTERN" "$RETURN_LOG"; then
RETURN_EXIT_CODE=0
break
fi

if [ "$RETURN_EXIT_CODE" -eq 0 ]; then
break
fi
Expand Down Expand Up @@ -149,6 +179,11 @@ elif [[ "$RETURN_STRATEGY" == "serial" ]]; then
-projectPath "$ACTIVATE_LICENSE_PATH" 2>&1 | tee "$RETURN_LOG"
RETURN_EXIT_CODE=${PIPESTATUS[0]}

if grep -qE "$UNITY_LICENSE_RETURN_SUCCESS_PATTERN" "$RETURN_LOG"; then
RETURN_EXIT_CODE=0
break
fi

if [ "$RETURN_EXIT_CODE" -eq 0 ]; then
break
fi
Expand Down
35 changes: 35 additions & 0 deletions dist/platforms/ubuntu/steps/return_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ UNITY_LICENSE_RETURN_TRANSIENT_PATTERN='TimeoutPolicy did not complete|Access to
# Permanent by construction - see the guards below.
UNITY_LICENSE_RETURN_PERMANENT_PATTERN="Machine bindings don't match"

# Unity returns the licence and THEN exits non-zero. Measured on 2022.3.62f3,
# same container, matching machine id:
#
# [Licensing::Module] Error: Access token is unavailable; failed to update
# [Licensing::Module] Error: Failed to return entitlement license
# [Licensing::Client] Successfully returned ULF license with serial number: "..."
# exit=1
#
# The seat really is returned - a following --return-ulf reports "Ulf license
# file not found". But the exit code says failure and the log carries "Access
# token is unavailable", which is in the transient list, so this retried four
# times against an already-returned licence and then warned that the return had
# failed. Reported by a user still seeing "attempt 3/4" on v0.1.64, whose own
# log showed the same machine id throughout - which ruled out the binding
# mismatch that release had fixed.
#
# So success is read from the log, not the exit code, exactly as activation
# already does for the same reason in the opposite direction.
UNITY_LICENSE_RETURN_SUCCESS_PATTERN='Successfully returned ULF license|Successfully returned floating license|License has been returned'

if [[ "$RETURN_STRATEGY" == "floating" ]]; then
#
# Return any floating license used.
Expand All @@ -42,6 +62,11 @@ if [[ "$RETURN_STRATEGY" == "floating" ]]; then
"$(unity_licensing_client_path)" --return-floating "$FLOATING_LICENSE" 2>&1 | tee "$RETURN_LOG"
RETURN_EXIT_CODE=${PIPESTATUS[0]}

if grep -qE "$UNITY_LICENSE_RETURN_SUCCESS_PATTERN" "$RETURN_LOG"; then
RETURN_EXIT_CODE=0
break
fi

if [ "$RETURN_EXIT_CODE" -eq 0 ]; then
break
fi
Expand Down Expand Up @@ -91,6 +116,11 @@ elif [[ "$RETURN_STRATEGY" == "personal" ]]; then
"$(unity_licensing_client_path)" --return-ulf 2>&1 | tee "$RETURN_LOG"
RETURN_EXIT_CODE=${PIPESTATUS[0]}

if grep -qE "$UNITY_LICENSE_RETURN_SUCCESS_PATTERN" "$RETURN_LOG"; then
RETURN_EXIT_CODE=0
break
fi

if [ "$RETURN_EXIT_CODE" -eq 0 ]; then
break
fi
Expand Down Expand Up @@ -144,6 +174,11 @@ elif [[ "$RETURN_STRATEGY" == "serial" ]]; then
-projectPath "$ACTIVATE_LICENSE_PATH" 2>&1 | tee "$RETURN_LOG"
RETURN_EXIT_CODE=${PIPESTATUS[0]}

if grep -qE "$UNITY_LICENSE_RETURN_SUCCESS_PATTERN" "$RETURN_LOG"; then
RETURN_EXIT_CODE=0
break
fi

if [ "$RETURN_EXIT_CODE" -eq 0 ]; then
break
fi
Expand Down
9 changes: 9 additions & 0 deletions dist/platforms/windows/return_license.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ $TransientPattern = 'TimeoutPolicy did not complete|Access token is unavailable|
# transient list above - see ubuntu/steps/return_license.sh.
$PermanentPattern = "Machine bindings don't match"

# Unity returns the licence and THEN exits non-zero - the seat really is
# returned, but the exit code says failure and the log carries "Access token is
# unavailable", which is in the transient list above. See the matching comment
# in ubuntu/steps/return_license.sh for the measurement.
$SuccessPattern = 'Successfully returned ULF license|Successfully returned floating license|License has been returned'

if ($ReturnStrategy -eq 'floating') {
#
# Return any floating license used.
Expand All @@ -50,6 +56,7 @@ if ($ReturnStrategy -eq 'floating') {
$ReturnExitCode = $LASTEXITCODE
$ReturnText = ($ReturnOutputVar | Out-String)

if ($ReturnText -match $SuccessPattern) { break }
if ($ReturnExitCode -eq 0) { break }

if ($ReturnText -match $PermanentPattern) { break }
Expand Down Expand Up @@ -83,6 +90,7 @@ elseif ($ReturnStrategy -eq 'personal') {
$ReturnExitCode = $LASTEXITCODE
$ReturnText = ($ReturnOutputVar | Out-String)

if ($ReturnText -match $SuccessPattern) { break }
if ($ReturnExitCode -eq 0) { break }

if ($ReturnText -match $PermanentPattern) { break }
Expand Down Expand Up @@ -121,6 +129,7 @@ elseif ($ReturnStrategy -eq 'serial') {
$LogContent = if (Test-Path $LogPath) { Get-Content $LogPath -Raw } else { '' }
if ($LogContent) { Get-Content $LogPath | Out-Host }

if ($LogContent -match $SuccessPattern) { break }
if ($ReturnExitCode -eq 0) { break }

if ($LogContent -match $PermanentPattern) { break }
Expand Down
9 changes: 9 additions & 0 deletions dist/platforms/windows/steps/return_license.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ $TransientPattern = 'TimeoutPolicy did not complete|Access token is unavailable|
# transient list above - see ubuntu/steps/return_license.sh.
$PermanentPattern = "Machine bindings don't match"

# Unity returns the licence and THEN exits non-zero - the seat really is
# returned, but the exit code says failure and the log carries "Access token is
# unavailable", which is in the transient list above. See the matching comment
# in ubuntu/steps/return_license.sh for the measurement.
$SuccessPattern = 'Successfully returned ULF license|Successfully returned floating license|License has been returned'

try {
if ($ReturnStrategy -eq 'floating') {
#
Expand All @@ -46,6 +52,7 @@ try {
$ReturnExitCode = $LASTEXITCODE
$ReturnText = ($ReturnOutputVar | Out-String)

if ($ReturnText -match $SuccessPattern) { break }
if ($ReturnExitCode -eq 0) { break }

if ($ReturnText -match $PermanentPattern) { break }
Expand Down Expand Up @@ -81,6 +88,7 @@ try {
$ReturnExitCode = $LASTEXITCODE
$ReturnText = ($ReturnOutputVar | Out-String)

if ($ReturnText -match $SuccessPattern) { break }
if ($ReturnExitCode -eq 0) { break }

if ($ReturnText -match $PermanentPattern) { break }
Expand Down Expand Up @@ -122,6 +130,7 @@ try {
$LogContent = if (Test-Path $LogPath) { Get-Content $LogPath -Raw } else { '' }
if ($LogContent) { Get-Content $LogPath | Out-Host }

if ($LogContent -match $SuccessPattern) { break }
if ($ReturnExitCode -eq 0) { break }

if ($LogContent -match $PermanentPattern) { break }
Expand Down
45 changes: 41 additions & 4 deletions scripts/test-licensing-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,20 @@ check "still reports success when a seat was assigned" "$OUT" "Activation comple
# .github/workflows/licensing-diagnostic.yml - the route had never been tried,
# and 2020.3 was nearly documented as unable to use Personal seats at all.
: > "$ARGV_LOG"
OUT=$(run_step UNITY_EMAIL="ci\example.com" UNITY_PASSWORD="pw123456" \
OUT=$(run_step UNITY_EMAIL="ci@example.com" UNITY_PASSWORD="pw123456" \
STUB_CLIENT_NO_INCLUDE_PERSONAL=1 \
bash -c 'source "$STEPS_DIR/activate.sh"' 2>&1)
check "uses the editor when the client cannot request a Personal seat" "$OUT" \
"activating through the editor instead"
check "and the editor call carries no serial" "$(cat "$ARGV_LOG")" \
"EDITOR -logFile /dev/stdout -quit -username ci\example.com -password pw123456"
"EDITOR -logFile /dev/stdout -quit -username ci@example.com -password pw123456"
refute "and really passes no -serial" "$(cat "$ARGV_LOG")" "-serial"
check "and reports success" "$OUT" "Activation complete."

# The modern client must keep using the client route, not regress onto the
# editor - the editor route exists only for editors that cannot do it.
: > "$ARGV_LOG"
OUT=$(run_step UNITY_EMAIL="ci\example.com" UNITY_PASSWORD="pw123456" \
OUT=$(run_step UNITY_EMAIL="ci@example.com" UNITY_PASSWORD="pw123456" \
bash -c 'source "$STEPS_DIR/activate.sh"' 2>&1)
refute "still prefers the licensing client where it is capable" "$OUT" \
"activating through the editor instead"
Expand Down Expand Up @@ -529,14 +529,51 @@ exit 1
STUB
chmod +x "$WORK/unity-editor"

# Unity returns the licence and THEN exits non-zero. The seat really is
# returned ("Successfully returned ULF license"), but the exit code says
# failure and the log carries "Access token is unavailable", which is in the
# transient list - so this retried four times against an already-returned
# licence and warned that the return had failed. Measured on 2022.3.62f3 in
# .github/workflows/licensing-diagnostic.yml, same container, matching machine
# id, and reported by a user still seeing "attempt 3/4" on v0.1.64.
cat > "$WORK/unity-editor" <<'STUB'
#!/usr/bin/env bash
echo "EDITOR $*" >> "$ARGV_LOG"
echo "[Licensing::Module] Error: Access token is unavailable; failed to update"
echo "[Licensing::Module] Error: Failed to return entitlement license"
echo "[Licensing::Client] Successfully returned ULF license with serial number : \"F4-XXXX\""
exit 1
STUB
chmod +x "$WORK/unity-editor"

: > "$ARGV_LOG"
OUT=$(run_step UNITY_EMAIL="ci@example.com" UNITY_PASSWORD="pw123456" UNITY_SERIAL="F4-XXXX-XXXX-XXXX-XXXX-XXXX" \
UNITY_LICENSE_RETRY_MAX_ATTEMPTS=4 \
bash -c 'source "$STEPS_DIR/return_license.sh"' 2>&1)
refute "treats a logged successful return as success despite a non-zero exit" "$OUT" \
"known-transient licensing error"
refute "and does not warn that the return failed" "$OUT" "Failed to return the Unity license after"
check "and only calls the editor once" "$(grep -c '^EDITOR' "$ARGV_LOG")" "1"

# Re-declared here because the case above redefines the shared editor stub.
cat > "$WORK/unity-editor" <<'STUB'
#!/usr/bin/env bash
echo "EDITOR $*" >> "$ARGV_LOG"
echo "[Licensing::Module] Error: Access token is unavailable; failed to update"
echo "[Licensing::Module] Error: Failed to return entitlement license"
echo "[Licensing::Client] An error occurred attempting to return the ULF license (status code: 1400, message: \"Machine bindings don't match\")"
exit 1
STUB
chmod +x "$WORK/unity-editor"

# A machine-binding mismatch on RETURN is permanent - the entitlement is bound
# to the machine that activated it. It was being retried because the same
# failing return also emits "Access token is unavailable; failed to update",
# which IS a transient signature, so the real reason was masked and the run
# burned all four attempts (~2.5 minutes) before warning anyway. Reported by a
# user, and reproduced in this repo's own licensing capability matrix.
: > "$ARGV_LOG"
OUT=$(run_step UNITY_EMAIL="ci\example.com" UNITY_PASSWORD="pw123456" UNITY_SERIAL="F4-XXXX-XXXX-XXXX-XXXX-XXXX" \
OUT=$(run_step UNITY_EMAIL="ci@example.com" UNITY_PASSWORD="pw123456" UNITY_SERIAL="F4-XXXX-XXXX-XXXX-XXXX-XXXX" \
UNITY_LICENSE_RETRY_MAX_ATTEMPTS=4 \
bash -c 'source "$STEPS_DIR/return_license.sh"' 2>&1)
refute "does not retry a machine-binding mismatch on return" "$OUT" \
Expand Down
Loading
Loading