diff --git a/tda/conftest.py b/tda/conftest.py index b1c517cf..41fa26f6 100644 --- a/tda/conftest.py +++ b/tda/conftest.py @@ -351,6 +351,7 @@ def android_react_native_emu_driver(request, set_tags, selenium_endpoint): try: release_version = ReleaseVersion.latest_react_native_github_release() + sentry_sdk.set_tag("github_release_version", release_version) options = UiAutomator2Options().load_capabilities({ 'deviceName': 'Android GoogleAPI Emulator', @@ -386,6 +387,7 @@ def android_emu_driver(request, set_tags, selenium_endpoint): try: release_version = ReleaseVersion.latest_android_github_release() + sentry_sdk.set_tag("github_release_version", release_version) options = UiAutomator2Options().load_capabilities({ 'deviceName': 'Android GoogleAPI Emulator', @@ -422,6 +424,7 @@ def ios_react_native_sim_driver(request, set_tags, selenium_endpoint): try: release_version = ReleaseVersion.latest_react_native_github_release() + sentry_sdk.set_tag("github_release_version", release_version) options = XCUITestOptions().load_capabilities({ 'appium:deviceName': 'iPhone 11 Simulator', @@ -457,6 +460,7 @@ def ios_sim_driver(request, set_tags, selenium_endpoint): try: release_version = ReleaseVersion.latest_ios_github_release() + sentry_sdk.set_tag("github_release_version", release_version) options = XCUITestOptions().load_capabilities({ 'appium:deviceName': 'iPhone 13 Simulator', diff --git a/tda/latest_github_release.py b/tda/latest_github_release.py old mode 100644 new mode 100755 diff --git a/tda/release_version_manager.py b/tda/release_version_manager.py index c0bcdb8b..96d3868a 100644 --- a/tda/release_version_manager.py +++ b/tda/release_version_manager.py @@ -1,11 +1,22 @@ import requests import os +from datetime import datetime + +GITHUB_API_RELEASES_MAX_RESULTS = 30 GITHUB_REPOS = { - # platform: - 'react_native': 'sentry_react_native', - 'android': 'android', - 'ios': 'ios' + 'react_native': { + 'repo': 'sentry_react_native', + 'use_prefix': False + }, + 'android': { + 'repo': 'android', + 'use_prefix': False + }, + 'ios': { + 'repo': 'ios', + 'use_prefix': True + } } # Setting the release version in an environment variable @@ -40,6 +51,20 @@ def latest_ios_github_release(): return latest_github_release('ios') def determine_latest_release_version(platform): - repo_name = GITHUB_REPOS[platform] - react_native_releases = requests.get(f"https://api.github.com/repos/sentry-demos/{repo_name}/releases") - return react_native_releases.json()[0]['tag_name'] + repo = GITHUB_REPOS[platform] + releases = requests.get(f"https://api.github.com/repos/sentry-demos/{repo['name']}/releases").json() + if not repo['use_prefix']: + # Assuming correct ordering (might cause bugs) + return releases[0]['tag_name'] + else: + # When using -1.2.3 format GH will order releases alphabetically, i.e. 0.0.21 -> 0.0.3 + # We can't use "Latest" because we have multiple latest releasese - one for each platform + if len(releases) >= GITHUB_API_RELEASES_MAX_RESULTS: + raise NotImplementedError( + f"Github /releases API returned maximum number of results (${GITHUB_API_RELEASES_MAX_RESULTS}). " + + "Current implementation is not able to handle pagination. Please delete old releases or implement.") + + platform_releases = list(filter(lambda r: r['tag_name'].startswith(platform + '-'), releases)) + # Parse the 'published_at' times and sort the releases + platform_releases.sort(key=lambda release: datetime.strptime(release["published_at"], "%Y-%m-%dT%H:%M:%SZ"), reverse=True) + return platform_releases[0]['tag_name'] diff --git a/tda/run.sh b/tda/run.sh index 0aba0a99..ba9d9242 100755 --- a/tda/run.sh +++ b/tda/run.sh @@ -16,6 +16,7 @@ source env/bin/activate source .sauce_credentials export LATEST_REACT_NATIVE_GITHUB_RELEASE=$(python3 latest_github_release.py react_native) export LATEST_ANDROID_GITHUB_RELEASE=$(python3 latest_github_release.py android) +export LATEST_IOS_GITHUB_RELEASE=$(python3 latest_github_release.py android) # First run ALL canaries to ensure not a single one fails for job in jobs/*.sh; do