From 304df19c3275951011fd32da711a44f2a9dae089 Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Tue, 19 Sep 2023 16:18:13 +0200 Subject: [PATCH] [bazel] Add support for pinning Firefox Dev Edition (#12762) --- common/browsers.bzl | 22 ++++++++++++++++ common/repositories.bzl | 48 ++++++++++++++++++++++++++++++++++ java/browsers.bzl | 36 +++++++++++++++++++++++++ java/private/selenium_test.bzl | 16 ++++++++++++ scripts/pinned_browsers.py | 28 +++++++++++--------- 5 files changed, 137 insertions(+), 13 deletions(-) diff --git a/common/browsers.bzl b/common/browsers.bzl index e9ed64deba658..0d32b5cafc67d 100644 --- a/common/browsers.bzl +++ b/common/browsers.bzl @@ -62,3 +62,25 @@ firefox_data = select({ ], "//conditions:default": [], }) + geckodriver_data + +firefox_beta_data = select({ + "@selenium//common:use_pinned_linux_firefox": [ + "@linux_beta_firefox//:files", + "@linux_beta_firefox//:firefox/firefox", + ], + "@selenium//common:use_pinned_macos_firefox": [ + "@mac_beta_firefox//:Firefox.app", + ], + "//conditions:default": [], +}) + geckodriver_data + +firefox_dev_data = select({ + "@selenium//common:use_pinned_linux_firefox": [ + "@linux_dev_firefox//:files", + "@linux_dev_firefox//:firefox/firefox", + ], + "@selenium//common:use_pinned_macos_firefox": [ + "@mac_dev_firefox//:Firefox.app", + ], + "//conditions:default": [], +}) + geckodriver_data diff --git a/common/repositories.bzl b/common/repositories.bzl index a2db61bc9fbfe..b2329aadc40c8 100644 --- a/common/repositories.bzl +++ b/common/repositories.bzl @@ -32,6 +32,54 @@ exports_files( build_file_content = "exports_files([\"Firefox.app\"])", ) + http_archive( + name = "linux_beta_firefox", + url = "https://ftp.mozilla.org/pub/firefox/releases/118.0b9/linux-x86_64/en-US/firefox-118.0b9.tar.bz2", + sha256 = "aabef5f4ad520030de0d7ab47e1b9fab6a90d5deea50829fe7e92feb4a426e56", + build_file_content = """ +filegroup( + name = "files", + srcs = glob(["**/*"]), + visibility = ["//visibility:public"], +) + +exports_files( + ["firefox/firefox"], +) +""", + ) + + dmg_archive( + name = "mac_beta_firefox", + url = "https://ftp.mozilla.org/pub/firefox/releases/118.0b9/mac/en-US/Firefox%20118.0b9.dmg", + sha256 = "0794dcdace86d8e7ddd7392c191abb15c6ee71cd23a7c99ef857957c5aa36c7d", + build_file_content = "exports_files([\"Firefox.app\"])", + ) + + http_archive( + name = "linux_dev_firefox", + url = "https://ftp.mozilla.org/pub/firefox/releases/118.0b9/linux-x86_64/en-US/firefox-118.0b9.tar.bz2", + sha256 = "aabef5f4ad520030de0d7ab47e1b9fab6a90d5deea50829fe7e92feb4a426e56", + build_file_content = """ +filegroup( + name = "files", + srcs = glob(["**/*"]), + visibility = ["//visibility:public"], +) + +exports_files( + ["firefox/firefox"], +) +""", + ) + + dmg_archive( + name = "mac_dev_firefox", + url = "https://ftp.mozilla.org/pub/firefox/releases/118.0b9/mac/en-US/Firefox%20118.0b9.dmg", + sha256 = "0794dcdace86d8e7ddd7392c191abb15c6ee71cd23a7c99ef857957c5aa36c7d", + build_file_content = "exports_files([\"Firefox.app\"])", + ) + http_archive( name = "linux_geckodriver", url = "https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-linux64.tar.gz", diff --git a/java/browsers.bzl b/java/browsers.bzl index e5073a8c8f97f..9dc5264e05d04 100644 --- a/java/browsers.bzl +++ b/java/browsers.bzl @@ -75,3 +75,39 @@ firefox_jvm_flags = select({ ], "//conditions:default": [], }) + geckodriver_jvm_flags + +firefox_beta_jvm_flags = select({ + "@selenium//common:use_pinned_linux_firefox": [ + "-Dwebdriver.firefox.bin=$(location @linux_beta_firefox//:firefox/firefox)", + ], + "@selenium//common:use_pinned_macos_firefox": [ + "-Dwebdriver.firefox.bin=$(location @mac_beta_firefox//:Firefox.app)/Contents/MacOS/firefox", + ], + "@selenium//common:use_local_geckodriver": [], + "//conditions:default": [ + "-Dselenium.skiptest=false", + ], +}) + select({ + "@selenium//common:use_headless_browser": [ + "-Dwebdriver.headless=true", + ], + "//conditions:default": [], +}) + geckodriver_jvm_flags + +firefox_dev_jvm_flags = select({ + "@selenium//common:use_pinned_linux_firefox": [ + "-Dwebdriver.firefox.bin=$(location @linux_dev_firefox//:firefox/firefox)", + ], + "@selenium//common:use_pinned_macos_firefox": [ + "-Dwebdriver.firefox.bin=$(location @mac_dev_firefox//:Firefox.app)/Contents/MacOS/firefox", + ], + "@selenium//common:use_local_geckodriver": [], + "//conditions:default": [ + "-Dselenium.skiptest=false", + ], +}) + select({ + "@selenium//common:use_headless_browser": [ + "-Dwebdriver.headless=true", + ], + "//conditions:default": [], +}) + geckodriver_jvm_flags diff --git a/java/private/selenium_test.bzl b/java/private/selenium_test.bzl index c0e2d20f8cade..e381712ef5d38 100644 --- a/java/private/selenium_test.bzl +++ b/java/private/selenium_test.bzl @@ -4,12 +4,16 @@ load( "COMMON_TAGS", "chrome_data", "edge_data", + "firefox_beta_data", "firefox_data", + "firefox_dev_data", ) load( "//java:browsers.bzl", "chrome_jvm_flags", "edge_jvm_flags", + "firefox_beta_jvm_flags", + "firefox_dev_jvm_flags", "firefox_jvm_flags", ) @@ -34,6 +38,18 @@ BROWSERS = { "data": firefox_data, "tags": COMMON_TAGS + ["firefox"], }, + "firefox-beta": { + "deps": ["//java/src/org/openqa/selenium/firefox"], + "jvm_flags": ["-Dselenium.browser=ff"] + firefox_beta_jvm_flags, + "data": firefox_beta_data, + "tags": COMMON_TAGS + ["firefox"], + }, + "firefox-dev": { + "deps": ["//java/src/org/openqa/selenium/firefox"], + "jvm_flags": ["-Dselenium.browser=ff"] + firefox_dev_jvm_flags, + "data": firefox_dev_data, + "tags": COMMON_TAGS + ["firefox"], + }, "ie": { "deps": ["//java/src/org/openqa/selenium/ie"], "jvm_flags": ["-Dselenium.browser=ie"] + diff --git a/scripts/pinned_browsers.py b/scripts/pinned_browsers.py index 0d5f2a3959cc0..da80d83738c69 100755 --- a/scripts/pinned_browsers.py +++ b/scripts/pinned_browsers.py @@ -210,19 +210,19 @@ def geckodriver(): """ % (url, sha) return content -def firefox(): +def firefox(version_key, workspace_name): r = http.request('GET', 'https://product-details.mozilla.org/1.0/firefox_versions.json') - v = json.loads(r.data)['LATEST_FIREFOX_VERSION'] + v = json.loads(r.data)[version_key] content = "" linux = "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" % (v, v) sha = calculate_hash(linux) - content = content + """ + content = content + f""" http_archive( - name = "linux_firefox", - url = "%s", - sha256 = "%s", + name = "linux_{workspace_name}firefox", + url = "{linux}", + sha256 = "{sha}", build_file_content = \"\"\" filegroup( name = "files", @@ -236,19 +236,19 @@ def firefox(): \"\"\", ) -""" % (linux, sha) +""" mac = "https://ftp.mozilla.org/pub/firefox/releases/%s/mac/en-US/Firefox%%20%s.dmg" % (v, v) sha = calculate_hash(mac) - content = content + """ + content = content + f""" dmg_archive( - name = "mac_firefox", - url = "%s", - sha256 = "%s", + name = "mac_{workspace_name}firefox", + url = "{mac}", + sha256 = "{sha}", build_file_content = "exports_files([\\"Firefox.app\\"])", ) -""" % (mac, sha) +""" return content @@ -264,7 +264,9 @@ def firefox(): def pin_browsers(): local_drivers() """ - content = content + firefox() + content = content + firefox("LATEST_FIREFOX_VERSION", "") + content = content + firefox("LATEST_FIREFOX_RELEASED_DEVEL_VERSION", "beta_") + content = content + firefox("FIREFOX_DEVEDITION", "dev_") content = content + geckodriver() content = content + edge() content = content + edgedriver()