Skip to content
Open
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
201 changes: 201 additions & 0 deletions .github/workflows/ci-js-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
name: CI for JS API tests

on:
push:
branches: [main]
paths:
- .github/workflows/ci-js-api.yml
- test/harness/testharness.js
- test/js-api/**

pull_request:
branches: [main]
paths:
- .github/workflows/ci-js-api.yml
- test/harness/testharness.js
- test/js-api/**

schedule:
- cron: '23 6 1 * *'

workflow_dispatch:
inputs:
refresh:
description: Test current releases and update the browser bump PR from the default branch
type: boolean
default: false
chrome-version:
description: Candidate Chrome version (blank uses the pin)
type: string
firefox-version:
description: Candidate Firefox version (blank uses the pin)
type: string
safari-version:
description: Candidate Safari version, or "installed" to accept the hosted version
type: string

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
js-api:
name: JS API (${{ matrix.browser }})
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- browser: firefox
os: ubuntu-24.04
version: ${{ inputs.firefox-version }}
- browser: chrome
os: ubuntu-24.04
version: ${{ inputs.chrome-version }}
- browser: safari
os: macos-15
version: ${{ inputs.safari-version }}
env:
BROWSER: ${{ matrix.browser }}
REFRESH: ${{ github.event_name == 'schedule' || inputs.refresh }}
PROPOSE: ${{ (github.event_name == 'schedule' || inputs.refresh) && github.ref_name == github.event.repository.default_branch }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Install Selenium
run: python -m pip install selenium==4.53.0
- name: Select browser version
id: browser
env:
OVERRIDE: ${{ matrix.version }}
run: |
args=(select-version "$BROWSER" --override "$OVERRIDE")
if [[ "$REFRESH" == true ]]; then
args+=(--refresh)
fi
version=$(python test/js-api/scripts/ci.py "${args[@]}")
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Enable Safari Remote Automation
if: matrix.browser == 'safari'
run: sudo /usr/bin/safaridriver --enable
- name: Run JS API tests
env:
BROWSER_VERSION: ${{ steps.browser.outputs.version }}
SE_SKIP_DRIVER_IN_PATH: 'true'
run: |
args=(--browser "$BROWSER" --json wasm-js-api.json --summary "$GITHUB_STEP_SUMMARY")
if [[ -n "$BROWSER_VERSION" ]]; then
args+=(--browser-version "$BROWSER_VERSION")
fi
status=0
python test/js-api/scripts/run.py "${args[@]}" || status=$?
# Candidate test failures are expected. The proposal job validates the report.
if [[ "$PROPOSE" == true && "$status" == 1 && -s wasm-js-api.json ]]; then
exit 0
fi
exit "$status"
- name: Upload browser report
if: ${{ !cancelled() && hashFiles('wasm-js-api.json') != '' }}
uses: actions/upload-artifact@v4
with:
name: wasm-js-api-${{ matrix.browser }}
path: wasm-js-api.json
if-no-files-found: error

propose-browser-update:
name: Propose browser update
if: ${{ (github.event_name == 'schedule' || inputs.refresh) && github.ref_name == github.event.repository.default_branch }}
needs: js-api
runs-on: ubuntu-24.04
timeout-minutes: 5
concurrency: js-api-browser-update
permissions:
actions: write
contents: write
pull-requests: write
steps:
- name: Checkout tested commit
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Download browser reports
uses: actions/download-artifact@v4
with:
pattern: wasm-js-api-*
path: ${{ runner.temp }}/js-api-reports
- name: Check the default branch is unchanged
env:
BASE_BRANCH: ${{ github.event.repository.default_branch }}
run: |
if [[ "$(git ls-remote origin "refs/heads/$BASE_BRANCH" | cut -f1)" != "$GITHUB_SHA" ]]; then
echo "The default branch moved during testing. Run the refresh again." >&2
exit 1
fi
- name: Update pins and expectations
id: update
run: python3 test/js-api/scripts/ci.py propose "$RUNNER_TEMP/js-api-reports" | tee -a "$GITHUB_STEP_SUMMARY"
# A rejected browser fails the job, but the other browsers are still proposed.
- name: Open or update browser bump PR
if: ${{ !cancelled() && steps.update.outcome != 'skipped' }}
env:
GH_TOKEN: ${{ github.token }}
BASE_BRANCH: ${{ github.event.repository.default_branch }}
UPDATE_OUTCOME: ${{ steps.update.outcome }}
run: |
branch=automation/js-api-browser-versions
ref="refs/heads/$branch"
previous=$(git ls-remote origin "$ref" | cut -f1)
lease="--force-with-lease=$ref:$previous"
git add -- test/js-api/scripts/browser-versions.json test/js-api/scripts/expectations.json
if git diff --cached --quiet; then
if [[ -n "$previous" && "$UPDATE_OUTCOME" == success ]]; then
gh auth setup-git
git push "$lease" origin ":$ref"
fi
echo "No browser updates to propose."
exit 0
fi

pr=$(gh api --method GET "repos/$GITHUB_REPOSITORY/pulls" \
-f state=open -f base="$BASE_BRANCH" \
-f head="${GITHUB_REPOSITORY%%/*}:$branch" --jq '.[0].number // empty')
if [[ -n "$pr" && -n "$previous" ]]; then
previous_tree=$(gh api "repos/$GITHUB_REPOSITORY/git/commits/$previous" --jq .tree.sha)
if [[ "$(git write-tree)" == "$previous_tree" ]]; then
echo "PR #$pr already contains this update."
exit 0
fi
fi

title='[js-api] Bump CI browser versions'
body_file=$(mktemp)
cat > "$body_file" <<EOF
Update the browser pins and failure expectations from complete JS API suite runs.

[Browser reports]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)
EOF
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -m "$title"
gh auth setup-git
# Rebuild the bot branch from the tested default-branch commit.
git push "$lease" origin "HEAD:$ref"
# Pushes made with GITHUB_TOKEN do not trigger pull_request runs, so start CI on the PR head.
gh workflow run ci-js-api.yml --repo "$GITHUB_REPOSITORY" --ref "$branch"
if [[ -n "$pr" ]]; then
gh api --method PATCH "repos/$GITHUB_REPOSITORY/pulls/$pr" \
-F body=@"$body_file" --jq .html_url
else
gh pr create --repo "$GITHUB_REPOSITORY" --base "$BASE_BRANCH" \
--head "$branch" --title "$title" --body-file "$body_file"
fi
35 changes: 35 additions & 0 deletions test/js-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,38 @@ See the [testharness.js] documentation for more information.
[web-platform-tests project]: https://github.com/web-platform-tests/wpt/tree/master/wasm/jsapi
[testharness.js]: https://web-platform-tests.org/writing-tests/testharness-api.html
[multi-global tests]: https://web-platform-tests.org/writing-tests/testharness.html#multi-global-tests

## Running in browsers

From the repository root, install Selenium in a Python virtual environment and
run the suite against an installed browser.

```sh
python3 -m venv /tmp/wasm-js-api-venv
/tmp/wasm-js-api-venv/bin/python -m pip install selenium
/tmp/wasm-js-api-venv/bin/python test/js-api/scripts/run.py --browser firefox
```

For Safari, enable Remote Automation once with `safaridriver --enable`.

### Pinned browser versions

The [browser version file](scripts/browser-versions.json) pins exact Chrome and Firefox
versions. Selenium Manager selects or downloads those versions. For Safari,
the file records the full version last tested on the GitHub-hosted image.

The [CI workflow](../../.github/workflows/ci-js-api.yml) checks for browser
updates monthly. After complete runs, it opens a PR with newer versions
and their expectations. This requires the repository setting "Allow GitHub
Actions to create and approve pull requests".

### Browser expectations

The test runner uses [scripts/expectations.json](scripts/expectations.json) to
track expected results of tests. To update expectations from a test run, save a
JSON report and apply it to the expectations file:

```sh
/tmp/wasm-js-api-venv/bin/python test/js-api/scripts/run.py --browser firefox --json firefox.json
python3 test/js-api/scripts/update-expectations.py --in-place firefox.json
```
5 changes: 5 additions & 0 deletions test/js-api/scripts/browser-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"chrome": "157.0.8103.78",
"firefox": "160.0",
"safari": "27.2"
}
131 changes: 131 additions & 0 deletions test/js-api/scripts/ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env python3
"""Browser version selection and update proposals for the JS API CI workflow."""

import argparse
import json
import sys
import time
from pathlib import Path
from urllib.request import urlopen

from lib.expectations import apply_report
from lib.tests import (
BROWSERS,
EXPECTATIONS,
PINS,
VERSION,
discover_tests,
read_json,
version_key,
write_json,
)

LATEST_RELEASE_URLS = {
"chrome": "https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_STABLE",
"firefox": "https://product-details.mozilla.org/1.0/firefox_versions.json",
}


def fetch(url, attempts=3):
for attempt in range(1, attempts + 1):
try:
with urlopen(url, timeout=30) as response:
return response.read().decode("utf-8")
except OSError:
if attempt == attempts:
raise
time.sleep(5 * attempt)


def latest_release(browser):
body = fetch(LATEST_RELEASE_URLS[browser])
if browser == "firefox":
return json.loads(body)["LATEST_FIREFOX_VERSION"]
return body.strip()


def select_version(browser, override, refresh):
"""Return the version to require, or an empty string to accept any."""
pin = read_json(PINS)[browser]
if override:
version = override
elif browser == "safari":
# The hosted runner supplies Safari. Normal CI checks only its major version.
version = "installed" if refresh else pin.split(".")[0]
elif refresh:
latest = latest_release(browser)
if not VERSION.fullmatch(latest):
raise ValueError(f"Could not resolve a stable {browser} version: {latest}")
# A release feed can lag behind the version already tested.
version = max(pin, latest, key=version_key)
else:
version = pin

if browser == "safari" and version == "installed":
return ""
if not VERSION.fullmatch(version):
raise ValueError(f"Invalid {browser} version: {version}")
return version


def propose(reports):
"""Update pins and expectations from CI reports. Returns the rejected browsers."""
pins = read_json(PINS)
expectations = read_json(EXPECTATIONS)
_, tests = discover_tests()
rejected = []
for browser in BROWSERS:
pin = pins[browser]
try:
report = read_json(reports / f"wasm-js-api-{browser}" / "wasm-js-api.json")
version = report.get("version")
if report.get("browser") != browser or not (
isinstance(version, str) and VERSION.fullmatch(version)
):
raise ValueError("report has no valid browser version")
if version == pin:
continue
if version_key(version) < version_key(pin):
raise ValueError(f"{version} is older than the tested pin {pin}")
expectations = apply_report(expectations, report, tests, require_complete=True)
except (OSError, ValueError, KeyError, TypeError, AttributeError) as error:
print(f"::error::{browser}: {error}", file=sys.stderr)
rejected.append(browser)
continue
pins[browser] = version
print(f"- {browser} {pin} → {version}")
write_json(PINS, pins)
write_json(EXPECTATIONS, expectations)
return rejected


def main():
parser = argparse.ArgumentParser(description=__doc__)
commands = parser.add_subparsers(dest="command", required=True)

select = commands.add_parser(
"select-version", help="Print the browser version a CI run should require"
)
select.add_argument("browser", choices=BROWSERS)
select.add_argument("--override", help="Candidate version to test instead")
select.add_argument(
"--refresh", action="store_true", help="Test the latest stable release"
)

update = commands.add_parser(
"propose", help="Update pins and expectations from downloaded CI reports"
)
update.add_argument("reports", type=Path, help="Directory of report artifacts")

args = parser.parse_args()
if args.command == "select-version":
try:
print(select_version(args.browser, args.override, args.refresh))
except (OSError, ValueError, KeyError) as error:
parser.error(str(error))
return 0
return 1 if propose(args.reports) else 0


if __name__ == "__main__":
sys.exit(main())
Loading
Loading