aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <infra@servo.org>2023-01-26 03:01:03 +0100
committerGitHub <noreply@github.com>2023-01-26 03:01:03 +0100
commit4f355f5877878bb2f4aed2b471e82722cd43f8e1 (patch)
tree11abe9676d2373ce1c51d25cc2a38a87a62d4afd
parent7f838a4f5f37755f7e4ae7080bf2a226e3d78bb9 (diff)
parenta18baf67195ac7d64b153d642bb36b3517016968 (diff)
downloadservo-4f355f5877878bb2f4aed2b471e82722cd43f8e1.tar.gz
servo-4f355f5877878bb2f4aed2b471e82722cd43f8e1.zip
Auto merge of #29299 - mrobinson:fix-upstream-wpt-changes, r=jdm
Fix upstreaming of WPT changes The GitHub Action needs access to Servo repository secrets, so switch to using the 'pull_request_target' event. Since these PRs have more complete access to the Servo repository, do not execute the version of the upstream script that comes with the PR. Instead, simply fetch the changes. To make this work, the script no longer expects the PR commit to be checked out, merely that they exist in the repository somewhere. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes
-rw-r--r--.github/workflows/upstream-wpt-changes.yml5
-rw-r--r--etc/ci/upstream-wpt-changes/test.py19
-rw-r--r--etc/ci/upstream-wpt-changes/wptupstreamer/__init__.py13
-rw-r--r--etc/ci/upstream-wpt-changes/wptupstreamer/step.py3
4 files changed, 30 insertions, 10 deletions
diff --git a/.github/workflows/upstream-wpt-changes.yml b/.github/workflows/upstream-wpt-changes.yml
index d53e5715b9d..0e78e4df583 100644
--- a/.github/workflows/upstream-wpt-changes.yml
+++ b/.github/workflows/upstream-wpt-changes.yml
@@ -1,6 +1,6 @@
name: WPT export
on:
- pull_request:
+ pull_request_target:
types: ['opened', 'synchronize', 'reopened', 'edited', 'closed']
jobs:
@@ -16,7 +16,8 @@ jobs:
git init -b main
git remote add origin ${{ github.event.repository.clone_url}}
git fetch origin pull/${{ github.event.pull_request.number}}/head:pr --depth ${{ env.PR_FETCH_DEPTH }}
- git checkout pr
+ git fetch origin master:master --depth 1
+ git checkout master
- name: Check out wpt
uses: actions/checkout@v3
with:
diff --git a/etc/ci/upstream-wpt-changes/test.py b/etc/ci/upstream-wpt-changes/test.py
index 67d83603805..b40af2a48ee 100644
--- a/etc/ci/upstream-wpt-changes/test.py
+++ b/etc/ci/upstream-wpt-changes/test.py
@@ -268,9 +268,12 @@ class TestFullSyncRun(unittest.TestCase):
@classmethod
def tearDownClass(cls):
+ assert cls.server is not None
cls.server.shutdown()
def tearDown(self):
+ assert SYNC is not None
+
# Clean up any old files.
first_commit_hash = SYNC.local_servo_repo.run("rev-list", "HEAD").splitlines()[
-1
@@ -286,9 +289,9 @@ class TestFullSyncRun(unittest.TestCase):
return [diff, "tmp author", "tmp@tmp.com", "tmp commit message"]
return diff
- commits = [make_commit_data(diff) for diff in diffs]
-
# Apply each commit to the repository.
+ orig_sha = SYNC.local_servo_repo.run("rev-parse", "HEAD").strip()
+ commits = [make_commit_data(diff) for diff in diffs]
for commit in commits:
patch_file, author, email, message = commit
SYNC.local_servo_repo.run("apply", os.path.join(TESTS_DIR, patch_file))
@@ -306,6 +309,12 @@ class TestFullSyncRun(unittest.TestCase):
},
)
+ # Reset the repository to the original hash, but the commits are still
+ # available until the next `git gc`.
+ last_commit_sha = SYNC.local_servo_repo.run("rev-parse", "HEAD").strip()
+ SYNC.local_servo_repo.run("reset", "--hard", orig_sha)
+ return last_commit_sha
+
def run_test(
self, payload_file: str, diffs: list, existing_prs: list[MockPullRequest] = []
):
@@ -313,7 +322,8 @@ class TestFullSyncRun(unittest.TestCase):
payload = json.loads(file.read())
logging.info("Mocking application of PR to servo.")
- self.mock_servo_repository_state(diffs)
+ last_commit_sha = self.mock_servo_repository_state(diffs)
+ payload["pull_request"]["head"]["sha"] = last_commit_sha
logging.info("Resetting server state")
assert self.server is not None
@@ -618,4 +628,7 @@ def tearDownModule():
if __name__ == "__main__":
+ # Uncomment this line to enable verbose logging.
+ # logging.getLogger().setLevel(logging.INFO)
+
unittest.main()
diff --git a/etc/ci/upstream-wpt-changes/wptupstreamer/__init__.py b/etc/ci/upstream-wpt-changes/wptupstreamer/__init__.py
index 97b0de8af72..f1b1ef92598 100644
--- a/etc/ci/upstream-wpt-changes/wptupstreamer/__init__.py
+++ b/etc/ci/upstream-wpt-changes/wptupstreamer/__init__.py
@@ -169,7 +169,8 @@ class WPTSync:
logging.info(
" → Detected existing upstream PR %s", upstream_pr)
- run = SyncRun(self, servo_pr, AsyncValue(upstream_pr), step_callback)
+ run = SyncRun(self, servo_pr, AsyncValue(
+ upstream_pr), step_callback)
pull_data = payload["pull_request"]
if payload["action"] in ["opened", "synchronize", "reopened"]:
@@ -189,10 +190,12 @@ class WPTSync:
return False
def handle_new_pull_request_contents(self, run: SyncRun, pull_data: dict):
+ num_commits = pull_data["commits"]
+ head_sha = pull_data["head"]["sha"]
is_upstreamable = (
len(
self.local_servo_repo.run(
- "diff", f"HEAD~{pull_data['commits']}", "--", UPSTREAMABLE_PATH
+ "diff", head_sha, f"{head_sha}~{num_commits}", "--", UPSTREAMABLE_PATH
)
)
> 0
@@ -245,7 +248,8 @@ class WPTSync:
logging.info("Changing upstream PR title")
if run.upstream_pr.has_value():
run.add_step(ChangePRStep(
- run.upstream_pr.value(), "open", pull_data["title"], pull_data["body"]
+ run.upstream_pr.value(
+ ), "open", pull_data["title"], pull_data["body"]
))
run.add_step(CommentStep(
run.servo_pr, UPDATED_TITLE_IN_EXISTING_UPSTREAM_PR))
@@ -258,7 +262,8 @@ class WPTSync:
if pull_data["merged"]:
# Since the upstreamable changes have now been merged locally, merge the
# corresponding upstream PR.
- run.add_step(MergePRStep(run.upstream_pr.value(), ["do not merge yet"]))
+ run.add_step(MergePRStep(
+ run.upstream_pr.value(), ["do not merge yet"]))
else:
# If a PR with upstreamable changes is closed without being merged, we
# don't want to merge the changes upstream either.
diff --git a/etc/ci/upstream-wpt-changes/wptupstreamer/step.py b/etc/ci/upstream-wpt-changes/wptupstreamer/step.py
index 31ae94b96eb..3c16bf88c81 100644
--- a/etc/ci/upstream-wpt-changes/wptupstreamer/step.py
+++ b/etc/ci/upstream-wpt-changes/wptupstreamer/step.py
@@ -99,8 +99,9 @@ class CreateOrUpdateBranchForPRStep(Step):
def _get_upstreamable_commits_from_local_servo_repo(self, sync: WPTSync):
local_servo_repo = sync.local_servo_repo
number_of_commits = self.pull_data["commits"]
+ pr_head = self.pull_data["head"]["sha"]
commit_shas = local_servo_repo.run(
- "log", "--pretty=%H", f"-{number_of_commits}"
+ "log", "--pretty=%H", pr_head, f"-{number_of_commits}"
).splitlines()
filtered_commits = []