Skip to content

Commit

Permalink
Pin Chromium revision for install
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRyanSmith committed May 2, 2022
1 parent 73220c7 commit 3afc523
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 9 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/update_chromium_revision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: update_chromium_revision
on:
# Trigger everyday at 10 UTC.
schedule:
- cron: 0 10 * * *
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: setup python
uses: actions/setup-python@v3
with:
python-version: '3.10'
cache: 'pip'
- run: pip install requests
- name: execute update_chromium_revision.py
run: python -m tools.wpt.update_chromium_revision
- name: Create pull request
# Use a conditional step instead of a conditional job to work around #20700.
if: github.repository == 'web-platform-tests/wpt'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
author: wpt-pr-bot <[email protected]>
title: "Update latest available Chromium revisions"
commit-message: "Latest Chromium revision for Linux/Mac/Win"
body: |
This automated pull request updates `tools/wpt/latest_chromium_revisions.json` with the current latest available Chromium revisions for major platforms.
If additional changes are needed, please manually create another PR based on this one.
See the [workflow](https://github.com/web-platform-tests/wpt/blob/master/.github/workflows/update_chromium_revision.yml) for how this pull request was created.
branch: actions/update-chromium-revision
22 changes: 21 additions & 1 deletion tools/ci/run_tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import zipfile

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from wpt.utils import get_download_to_descriptor # type: ignore
from wpt.utils import get, get_download_to_descriptor, unzip # type: ignore

root = os.path.abspath(
os.path.join(os.path.dirname(__file__),
Expand Down Expand Up @@ -257,13 +257,33 @@ def setup_environment(args):
assert args.channel is not None
install_chrome(args.channel)

if "chromium" in args.browser:
install_chromium()

if args.xvfb:
start_xvfb()

if args.oom_killer:
start_userspace_oom_killer()


def install_chromium():
revisions_path = os.path.join(os.getcwd(), "tools", "wpt", "latest_chromium_revision.txt")
with open(revisions_path) as f:
revision = f.read().strip()
dest = os.path.join("/tmp")
installer_path = os.path.join("/tmp", "chrome-linux.zip")

url = ("https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/"
f"{revision}/chrome-linux.zip")
resp = get(url)
with open(installer_path, "wb") as f:
f.write(resp.content)
with open(installer_path, "rb") as f:
unzip(f, dest)
os.remove(installer_path)


def setup_repository(args):
is_pr = os.environ.get("GITHUB_PULL_REQUEST", "false") != "false"

Expand Down
15 changes: 7 additions & 8 deletions tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,12 @@ class ChromeChromiumBase(Browser):
"Darwin": "Mac",
}.get(uname[0])

def _get_latest_chromium_revision(self, architecture):
"""Queries Chromium Snapshots and returns the latest Chromium revision number
for the current platform.
"""
revision_url = ("https://storage.googleapis.com/chromium-browser-snapshots/"
f"{architecture}/LAST_CHANGE")
return get(revision_url).text.strip()
def _get_latest_chromium_revision(self):
"""Returns the latest Chromium revision number for the current platform."""
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"latest_chromium_revision.txt")
with open(path) as f:
return f.read().strip()

def _get_chromium_download_url(self, version=None):
"""Format a Chromium Snapshots URL to download a browser component."""
Expand All @@ -557,7 +556,7 @@ def _get_chromium_download_url(self, version=None):
f"based on version. {url}")
# If no URL was used in a previous install
# and no version was passed, use the latest Chromium revision.
revision = self._get_latest_chromium_revision(architecture)
revision = self._get_latest_chromium_revision()

# If the url is successfully used to download/install, it will be used again
# if another component is also installed during this run (browser/webdriver).
Expand Down
1 change: 1 addition & 0 deletions tools/wpt/latest_chromium_revision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
996554
88 changes: 88 additions & 0 deletions tools/wpt/update_chromium_revision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import requests
from time import time

from .utils import get


PLATFORM_INFO = [
("Win_x64", "chrome-win.zip"),
("Win", "chrome-win.zip"),
("Linux_x64", "chrome-linux.zip"),
("Mac", "chrome-mac.zip")
]
SNAPSHOTS_PATH = "https://storage.googleapis.com/chromium-browser-snapshots/"


def main(timeout=600.0):
start = time()

# Load existing pinned revision.
existing_revision = None
with open("tools/wpt/latest_chromium_revision.txt", "r") as f:
existing_revision = int(f.read())

# Find the lowest new revision number among latest revisions by platform.
# We need to find a revision number that is available for download for all platforms,
# so we start looking from the smallest of these latest revisions.
smallest_revision = existing_revision
for platform, filename in PLATFORM_INFO:
try:
url = f"{SNAPSHOTS_PATH}{platform}/LAST_CHANGE"
revision = get(url).text.strip()
smallest_revision = max(smallest_revision, int(revision))
except requests.RequestException as e:
print(f"failed LAST_CHANGE lookup for {platform}: {e}")
continue

if smallest_revision == existing_revision:
return

# Step backwards through revision numbers until we find one
# that is available for all platforms.
largest_mutually_available_revision = smallest_revision
available_for_all = False
timed_out = False
while not available_for_all and not timed_out:
available_for_all = True
# For each platform, check if Chromium is available for download from snapshots.
for platform, filename in PLATFORM_INFO:
try:
url = (f"{SNAPSHOTS_PATH}{platform}/"
f"{largest_mutually_available_revision}/{filename}")
# Check the headers of each possible download URL.
r = requests.head(url)
# If the "Accept-Ranges" header is not present, we know the file is not
# available for download. Decrement the revision number and try again.
if "Accept-Ranges" not in r.headers:
largest_mutually_available_revision -= 1
available_for_all = False
break
except requests.RequestException as e:
print(e)
largest_mutually_available_revision -= 1
available_for_all = False
break
if time() - start > timeout:
timed_out = True

if timed_out:
raise TimeoutError(f"Reached timeout {timeout}s while checking revision "
f"{largest_mutually_available_revision}")

end = time()
if largest_mutually_available_revision == existing_revision:
print(f"No new mutually available revision numbers found after "
f"{'{:.2f}'.format(end - start)} seconds.")
return

print(f"Found mutually available revision at {largest_mutually_available_revision}.")
print(f"This process started at {smallest_revision} and checked "
f"{smallest_revision - largest_mutually_available_revision} revisions.")
print(f"The whole process took {'{:.2f}'.format(end - start)} seconds.")

with open("tools/wpt/latest_chromium_revision.txt", "w") as f:
f.write(f"{largest_mutually_available_revision}\n")


if __name__ == "__main__":
main() # type: ignore

0 comments on commit 3afc523

Please sign in to comment.