Fix WPT sync and simplify the update scripts (#29999)

Much of the code used to import WPT tests from upstream has been moved
to the WPT repository itself, so this can be reused. In addition,
simplify the workflows by merging the entire process into mach and also
directly into the GitHub workflow. This should fix WPT imports after
combining compilation of layout and legacy layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2023-07-17 15:55:57 +02:00 committed by GitHub
parent 4c8b47adbb
commit da5b861b3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 541 deletions

View file

@ -1,160 +0,0 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
set -o errexit
set -o nounset
set -o pipefail
REMOTE_NAME=sync-fork
LOG_FILE=test-wpt.log
BLUETOOTH_LOG_FILE=test-wpt-bluetooth.log
WDSPEC_LOG_FILE=test-wpt-wdspec.log
CURRENT_DATE=$(date +"%d-%m-%Y")
BRANCH_NAME="wpt_update"
REMOTE_BRANCH_NAME="wpt_update_${CURRENT_DATE}"
export GIT_AUTHOR_NAME="WPT Sync Bot"
export GIT_AUTHOR_EMAIL="josh+wptsync@joshmatthews.net"
export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
# Retrieve the HEAD commit and extract its hash
function latest_git_commit() {
git log -1 --oneline | cut -f 1 -d ' '
}
# Create a new branch for this sync, pull down all changes from the upstream
# web-platform-tests repository, and commit the changes.
function unsafe_pull_from_upstream() {
git checkout -b "${1}" || return 1
OLD_COMMIT=$(latest_git_commit)
# Fetch all changes from upstream WPT and automatically transpose them
# into a single servo commit.
./mach update-wpt --sync --patch || return 2
# If there was no new commit created, there are no changes that need syncing.
# Skip the remaining steps.
if [[ "$(latest_git_commit)" == "${OLD_COMMIT}" ]]; then
return 255
fi
# Update the manifest to include the new changes.
./mach update-manifest || return 3
# Update the manifest again to reach a fixed state (https://github.com/servo/servo/issues/22275).
./mach update-manifest || return 4
# Clean up any now-unused test results.
(python3 etc/unused_wpt_results.py | xargs rm -rfv) || return 5
# Amend the existing commit with the new changes from updating the manifest.
git commit -a --amend --no-edit || return 6
}
# Remove all local traces of this sync operation.
function cleanup() {
git remote rm "${REMOTE_NAME}" || true
git reset --hard || true
git checkout master || true
git branch -D "${BRANCH_NAME}" || true
./mach update-wpt --abort || true
}
# Build Servo and run the full WPT testsuite, saving the results to a log file.
function unsafe_run_tests() {
# Run the full testsuite and record the new test results.
./mach test-wpt --release --processes 12 --log-raw "${1}" \
--always-succeed || return 1
# Run the bluetooth testsuite, which uses the webdriver test harness.
./mach test-wpt --release --product=servodriver --headless \
--log-raw "${2}" /bluetooth --always-succeed || return 2
# Run the wdspec testsuite
./mach test-wpt --release --timeout-multiplier=4 --log-raw "${3}" /webdriver \
--always-succeed || return 3
}
# Using an existing log file, update the expected test results and amend the
# last commit with the new results.
function unsafe_update_metadata() {
./mach update-wpt "${1}" "${2}" "${3}" || return 1
# Hope that any test result changes from layout-2013 are also applicable to layout-2020.
./mach update-wpt --layout-2020 "${1}" "${2}" "${3}" || return 2
# Ensure any new directories or ini files are included in these changes.
git add tests/wpt/meta tests/wpt/metadata-legacy-layout tests/wpt/mozilla/meta tests/wpt/mozilla/meta-legacy-layout || return 3
# Merge all changes with the existing commit.
git commit -a --amend --no-edit || return 3
}
function pull_from_upstream() {
unsafe_pull_from_upstream "${1}" || { code="${?}"; cleanup; return "${code}"; }
}
function run_tests() {
unsafe_run_tests "${1}" "${2}" "${3}" || { code="${?}"; cleanup; return "${code}"; }
}
function update_metadata() {
unsafe_update_metadata "${1}" "${2}" "${3}" || { code="${?}"; cleanup; return "${code}"; }
}
SCRIPT_NAME="${0}"
function update_test_results() {
run_tests "${LOG_FILE}" "${BLUETOOTH_LOG_FILE}" "${WDSPEC_LOG_FILE}"
update_metadata "${LOG_FILE}" "${BLUETOOTH_LOG_FILE}" "${WDSPEC_LOG_FILE}"
}
function fetch_upstream_changes() {
pull_from_upstream "${BRANCH_NAME}"
}
function usage() {
echo "usage: ${SCRIPT_NAME} [cmd]"
echo " commands:"
echo " - fetch-upstream-changes: create a branch with the latest changes from upstream"
echo " - update-test-results: run the tests, update the expected test results, and commit the changes"
echo " - fetch-and-update-expectations: combines fetch-upstream-changes and update-test-results"
echo " - cleanup: cleanup all traces of an in-progress sync and checkout the master branch"
exit 1
}
function main() {
if [[ "${1}" == "fetch-upstream-changes" ]] || [[ "${1}" == "fetch-and-update-expectations" ]]; then
code=""
fetch_upstream_changes || code="${?}"
if [[ "${code}" == "255" ]]; then
echo "No changes to sync."
return 0
fi
if [[ "${code}" != "" ]]; then
return "${code}"
else
return 0
fi
fi
if [[ "${1}" == "update-test-results" ]] || [[ "${1}" == "fetch-and-update-expectations" ]]; then
update_test_results
elif [[ "${1}" == "cleanup" ]]; then
cleanup
else
usage
fi
}
if [[ "$#" != 1 ]]; then
usage
fi
# Ensure we clean up after ourselves if this script is interrupted.
trap 'cleanup' SIGINT SIGTERM
main "${1}"

View file

@ -1,45 +0,0 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
set -o errexit
set -o nounset
set -o pipefail
# For a given chunk, use the existing log files to update the expected test
# results and amend the last commit with the new results.
function unsafe_update_metadata_chunk() {
./mach update-wpt \
"wpt-logs-linux-layout-2013/test-wpt.${1}.log" || return 1
./mach update-wpt --layout-2020 \
"wpt-logs-linux-layout-2020/test-wpt.${1}.log" || return 2
# Ensure any new directories or ini files are included in these changes.
git add tests/wpt/meta \
tests/wpt/meta-legacy-layout \
tests/wpt/mozilla/meta \
tests/wpt/mozilla/meta-legacy-layout || return 3
# Merge all changes with the existing commit.
git commit -a --amend --no-edit || return 3
}
function update_metadata_chunk() {
unsafe_update_metadata_chunk "${1}" || \
{ code="${?}"; return "${code}"; }
}
function main() {
for n in $(seq 1 "${MAX_CHUNK_ID}")
do
code=""
update_metadata_chunk "${n}" || code="${?}"
if [[ "${code}" != "" ]]; then
return "${code}"
fi
done
}
main

View file

@ -1,55 +0,0 @@
#!/usr/bin/env python
# Copyright 2019 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# For all directories and ini files under the WPT metadata directory,
# check whether there is a match directory/test file in the vendored WPT
# test collection. If there is not, the test result file is leftover since
# the original test was moved/renamed/deleted and no longer serves any
# purpose.
import os
test_root = os.path.join('tests', 'wpt', 'tests')
meta_root = os.path.join('tests', 'wpt', 'meta')
missing_dirs = []
for base_dir, dir_names, files in os.walk(meta_root):
# Skip recursing into any directories that were previously found to be missing.
if base_dir in missing_dirs:
# Skip processing any subdirectories of known missing directories.
missing_dirs += map(lambda x: os.path.join(base_dir, x), dir_names)
continue
for dir_name in dir_names:
meta_dir = os.path.join(base_dir, dir_name)
# Skip any known directories that are meta-metadata.
if dir_name == '.cache':
missing_dirs += [meta_dir]
continue
# Turn tests/wpt/meta/foo into tests/wpt/tests/foo.
test_dir = os.path.join(test_root, os.path.relpath(meta_dir, meta_root))
if not os.path.exists(test_dir):
missing_dirs += [meta_dir]
print(meta_dir)
for fname in files:
# Skip any known files that are meta-metadata.
if fname in ['__dir__.ini', 'MANIFEST.json', 'mozilla-sync']:
continue
# Turn tests/wpt/meta/foo/bar.html.ini into tests/wpt/tests/foo/bar.html.
test_dir = os.path.join(test_root, os.path.relpath(base_dir, meta_root))
test_file = os.path.join(test_dir, fname)
if not os.path.exists(os.path.splitext(test_file)[0]):
print(os.path.join(base_dir, fname))