Skip to content

Commit 1ceebe6

Browse files
authored
Retry unity installation in Python script instead of using GHA (#527)
\
1 parent f18e291 commit 1ceebe6

File tree

9 files changed

+46
-27
lines changed

9 files changed

+46
-27
lines changed

.github/workflows/build_android.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ jobs:
103103
pip install -r scripts/gha/requirements.txt
104104
105105
- id: unity_setup
106-
uses: firebase/firebase-unity-sdk/gha/unity@main
106+
uses: ./gha/unity
107+
timeout-minutes: 30
107108
with:
108109
version: ${{ inputs.unity_version }}
109110
platforms: ${{ inputs.unity_platform_name }}

.github/workflows/build_ios.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ jobs:
8282
pip install -r scripts/gha/requirements.txt
8383
8484
- id: unity_setup
85-
uses: firebase/firebase-unity-sdk/gha/unity@main
85+
uses: ./gha/unity
86+
timeout-minutes: 30
8687
with:
8788
version: ${{ inputs.unity_version }}
8889
platforms: ${{ inputs.unity_platform_name }}

.github/workflows/build_linux.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ jobs:
8484
sudo apt install openssl
8585
8686
- id: unity_setup
87-
uses: firebase/firebase-unity-sdk/gha/unity@main
87+
uses: ./gha/unity
88+
timeout-minutes: 30
8889
with:
8990
version: ${{ inputs.unity_version }}
9091
platforms: ${{ inputs.unity_platform_name }}

.github/workflows/build_macos.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ jobs:
9898
echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl --installed)" >> $GITHUB_ENV
9999
100100
- id: unity_setup
101-
uses: firebase/firebase-unity-sdk/gha/unity@main
101+
uses: ./gha/unity
102+
timeout-minutes: 30
102103
with:
103104
version: ${{ inputs.unity_version }}
104105
platforms: ${{ inputs.unity_platform_name }}

.github/workflows/build_tvos.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ jobs:
109109
pod repo add cocoapods https://github.com/CocoaPods/Specs.git
110110
111111
- id: unity_setup
112-
uses: firebase/firebase-unity-sdk/gha/unity@main
112+
uses: ./gha/unity
113+
timeout-minutes: 30
113114
with:
114115
version: ${{ inputs.unity_version }}
115116
platforms: ${{ inputs.unity_platform_name }}

.github/workflows/build_windows.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ jobs:
9090
choco install openssl -r
9191
9292
- id: unity_setup
93-
uses: firebase/firebase-unity-sdk/gha/unity@main
93+
uses: ./gha/unity
94+
timeout-minutes: 30
9495
with:
9596
version: ${{ inputs.unity_version }}
9697
platforms: ${{ inputs.unity_platform_name }}

.github/workflows/integration_tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ jobs:
185185
if: runner.os == 'macOS'
186186
run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer
187187
- id: unity_setup
188-
uses: firebase/firebase-unity-sdk/gha/unity@main
188+
uses: ./gha/unity
189+
timeout-minutes: 30
189190
with:
190191
version: ${{ matrix.unity_version }}
191192
platforms: ${{ matrix.platform }}
@@ -228,7 +229,7 @@ jobs:
228229
- name: Return Unity license
229230
# Always returns true, even when job failed or canceled. But will not run when a critical failure prevents the task from running.
230231
if: always()
231-
uses: firebase/firebase-unity-sdk/gha/unity@main
232+
uses: ./gha/unity
232233
with:
233234
version: ${{ matrix.unity_version }}
234235
release_license: "true"
@@ -358,7 +359,8 @@ jobs:
358359
run: |
359360
pip install -r scripts/gha/requirements.txt
360361
- id: unity_setup
361-
uses: firebase/firebase-unity-sdk/gha/unity@main
362+
uses: ./gha/unity
363+
timeout-minutes: 30
362364
with:
363365
version: ${{ matrix.unity_version }}
364366
username: ${{ secrets.UNITY_USERNAME }}
@@ -397,7 +399,7 @@ jobs:
397399
- name: Return Unity license
398400
# Always returns true, even when job failed or canceled. But will not run when a critical failure prevents the task from running.
399401
if: always()
400-
uses: firebase/firebase-unity-sdk/gha/unity@main
402+
uses: ./gha/unity
401403
with:
402404
version: ${{ matrix.unity_version }}
403405
release_license: "true"

gha/unity/action.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,14 @@ runs:
6565
- id: unity_installation
6666
name: Install Unity
6767
if: inputs.release_license == ''
68-
uses: nick-invision/retry@v2
69-
with:
70-
timeout_minutes: 12
71-
max_attempts: 2
72-
shell: bash
73-
command: |
74-
if [[ -n "${{ inputs.platforms }}" ]]; then
75-
additional_flags+=(--platforms ${{ inputs.platforms }})
76-
fi
77-
unity_info=$( python $GITHUB_ACTION_PATH/unity_installer.py --install --version ${{ inputs.version }} ${additional_flags[*]} )
78-
echo "UNITY_ROOT_DIR=$(cut -d',' -f2 <<< ${unity_info})" >> $GITHUB_ENV
79-
echo "unity_version=$(cut -d',' -f1 <<< ${unity_info})" >> $GITHUB_OUTPUT
68+
shell: bash
69+
run: |
70+
if [[ -n "${{ inputs.platforms }}" ]]; then
71+
additional_flags+=(--platforms ${{ inputs.platforms }})
72+
fi
73+
unity_info=$( python $GITHUB_ACTION_PATH/unity_installer.py --install --version ${{ inputs.version }} ${additional_flags[*]} )
74+
echo "UNITY_ROOT_DIR=$(cut -d',' -f2 <<< ${unity_info})" >> $GITHUB_ENV
75+
echo "unity_version=$(cut -d',' -f1 <<< ${unity_info})" >> $GITHUB_OUTPUT
8076
- name: Activate Unity license
8177
if: inputs.release_license == '' && inputs.username != '' && inputs.password != '' && inputs.serial_ids != ''
8278
shell: bash

gha/unity/unity_installer.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383

8484
_CMD_TIMEOUT = 900
85+
_MAX_ATTEMPTS = 3
8586

8687
_DEFALUT = "Default"
8788
_ANDROID = "Android"
@@ -172,7 +173,6 @@ def main(argv):
172173
raise app.UsageError("Too many command-line arguments.")
173174

174175
if FLAGS.install:
175-
uninstall_unity(FLAGS.version)
176176
install_unity(FLAGS.version, FLAGS.platforms)
177177

178178
if FLAGS.activate_license:
@@ -209,9 +209,24 @@ def install_unity(unity_version, platforms):
209209
u3d = find_u3d()
210210
run([u3d, "available", "-u", unity_version], check=False)
211211
run([u3d, "available", "-u", unity_full_version, "-p"], check=False)
212-
run([u3d, "install", "--trace",
212+
attempt_num = 1
213+
while attempt_num <= _MAX_ATTEMPTS:
214+
uninstall_unity(unity_version)
215+
args = [u3d, "install", "--trace",
213216
"--verbose", unity_full_version,
214-
"-p", package_csv])
217+
"-p", package_csv]
218+
logging.info("run_with_retry: %s (attempt %s of %s)", args, attempt_num, _MAX_ATTEMPTS)
219+
try:
220+
run(args)
221+
except subprocess.SubprocessError:
222+
logging.exception("run_with_retry: %s (attempt %s of %s) FAILED", args, attempt_num, _MAX_ATTEMPTS)
223+
# If retries have been exhausted, just raise the exception
224+
if attempt_num >= _MAX_ATTEMPTS:
225+
raise
226+
else:
227+
break
228+
attempt_num += 1
229+
215230
logging.info("Finished installing Unity.")
216231

217232
unity_path = get_unity_path(unity_version)
@@ -324,8 +339,8 @@ def run(args, check=True, timeout=_CMD_TIMEOUT):
324339
"""Runs args in a subprocess, throwing an error on non-zero return code."""
325340
logging.info("run cmd: %s", " ".join(args))
326341
result = subprocess.run(args=args, check=check, timeout=timeout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
327-
logging.info(result.stdout)
328-
logging.info(result.stderr)
342+
logging.info("cmd result.stdout: %s", result.stdout)
343+
logging.info("cmd result.stderr: %s", result.stderr)
329344

330345

331346
if __name__ == "__main__":

0 commit comments

Comments
 (0)