Skip to content
Merged
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
81 changes: 81 additions & 0 deletions .github/workflows/update-cddl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Update CDDL

on:
schedule:
- cron: 20 0 * * *
workflow_dispatch:

permissions:
contents: read

jobs:
update:
name: Update CDDL Specs
uses: ./.github/workflows/bazel.yml
with:
name: Update CDDL Specs
run: ./go update_cddl
artifact-name: cddl-updates
Comment thread
qodo-code-review[bot] marked this conversation as resolved.

create-pr:
name: Create Pull Request
if: github.event.repository.fork == false
runs-on: ubuntu-latest
needs: update
permissions:
contents: write
pull-requests: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Download patch
uses: actions/download-artifact@v8
with:
pattern: cddl-updates
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
merge-multiple: true
- name: Apply patch
id: apply
run: |
if [ -s changes.patch ]; then
git apply --index changes.patch
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
rm -f changes.patch
- name: Create Pull Request
if: steps.apply.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.SELENIUM_CI_TOKEN }}
commit-message: "update cddl spec files"
author: Selenium CI Bot <selenium-ci@users.noreply.github.com>
base: trunk
title: "[build] Automated CDDL Spec Update"
body: |
This is an automated pull request to repin the CDDL grammars and definition
indexes from w3c/webref, plus the rendered WebDriver BiDi spec from
w3c/webdriver-bidi.

Auto-generated by the [update-cddl workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
branch: automated-cddl-updates
labels: C-build

on-failure:
name: On CDDL Update Failure
runs-on: ubuntu-latest
needs: [update, create-pr]
if: failure() || cancelled()
steps:
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_ICON_EMOJI: ":rotating_light:"
SLACK_COLOR: failure
SLACK_CHANNEL: selenium-tlc
SLACK_USERNAME: GitHub Workflows
SLACK_TITLE: Needs Investigation
SLACK_MESSAGE: "Unable to create the daily CDDL Update PR"
MSG_MINIMAL: actions url
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ task :update_multitool do |_task, _arguments|
Bazel.execute('run', [], '//scripts:update_multitool_binaries')
end

desc 'Update pinned CDDL spec files from w3c/webref'
desc 'Update pinned CDDL spec files from w3c/webref and regenerate what they feed'
task :update_cddl do |_task, _arguments|
puts 'Updating pinned CDDL spec references'
Bazel.execute('run', [], '//scripts:update_cddl')

if SeleniumRake.git.diff('HEAD').path('common/webref_cddl.bzl').none?
puts 'Pins unchanged; skipping regeneration'
next
end

puts 'Updating the checked-in BiDi schema'
Bazel.execute('run', [], '//common/bidi:update-schema')
Rake::Task['rb:update_cddl'].invoke
end

desc 'Update Chrome DevTools support'
Expand Down
5 changes: 3 additions & 2 deletions common/webref_cddl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
# Pinned to a single w3c/webref "main" commit (kept on main so pin-to-pin diffs
# stay auditable) and regenerated by the //scripts:update_cddl Bazel target:
# https://github.com/w3c/webref/tree/main/ed/cddl
# Advanced only when a hash below changes, so it lags main's tip by design.
_COMMIT = "5e914258243bbca0ccbfe184bdc62eb82d53c6b7"
_BASE_URL = "https://raw.githubusercontent.com/w3c/webref/{commit}/ed/cddl".format(commit = _COMMIT)

Expand All @@ -19,8 +20,8 @@ _DFNS_BASE_URL = "https://raw.githubusercontent.com/w3c/webref/{commit}/ed/dfns"
# snapshot). Only this file carries the readable prose section ids
# (`#type-`/`#command-`/`#event-`/`#module-`) that webref does not extract; the schema
# step runs extract_bidi_anchors.mjs over it to build the prose-anchor index. This is a
# separate repo/branch from the webref pin above, so //scripts:update_cddl repins it to
# gh-pages' own tip; both track the same editor's draft, within a day of each other.
# separate repo/branch from the webref pin above, but it only annotates types that come from
# the CDDL, so //scripts:update_cddl takes gh-pages' tip only when the CDDL content changes.
_BIDI_SPEC_HTML_COMMIT = "975a118c247b6f0e0b64f8093b5f01238423bab1"
_BIDI_SPEC_HTML_SHA256 = "ddfc94f2d7692a3da189c997cb3e88388044b661d2459e68cf7a977a11807446"
_BIDI_SPEC_HTML_URL = "https://raw.githubusercontent.com/w3c/webdriver-bidi/{commit}/index.html".format(
Expand Down
6 changes: 6 additions & 0 deletions rake_tasks/ruby.rake
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ task :install do
end
end

desc 'Regenerate the BiDi protocol classes from the pinned CDDL schema'
task :update_cddl do
puts 'Regenerating Ruby BiDi protocol'
Bazel.execute('run', [], '//rb/lib/selenium/webdriver:bidi-generate')
end

desc 'Update Ruby changelog'
task :changelogs do
header = "#{ruby_version} (#{Time.now.strftime('%Y-%m-%d')})\n========================="
Expand Down
56 changes: 27 additions & 29 deletions scripts/update_cddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@
the per-spec ``dfns`` indexes (same webref commit), and the rendered core spec
HTML pinned from ``w3c/webdriver-bidi``'s ``gh-pages`` branch (its prose section
anchors are the source of the readable ``#type-``/``#command-`` spec links, and
that branch is a separate repo, so it is pinned to its own tip). It regenerates:
that branch is a separate repo, so it is resolved separately). It regenerates:

- ``_COMMIT``, ``_CDDL_FILES``, ``_DFNS_FILES``, and the ``_BIDI_SPEC_HTML_*``
pins in ``common/webref_cddl.bzl``
- the matching ``use_repo(...)`` list for the extension in ``MODULE.bazel``

-----------------------------------------------------------------------------
usage: update_cddl.py [-h] [--commit COMMIT] [--branch BRANCH]

options:
-h, --help show this help message and exit
--commit COMMIT pin this exact webref commit instead of the branch tip
--branch BRANCH webref branch to resolve when --commit is omitted (default: main)
-----------------------------------------------------------------------------
Nothing is written unless the consumed webref content changed, so both commit pins record
where the CDDL content last changed rather than the latest tip. The rendered spec is repinned
in lockstep with the CDDL, since it only annotates types the grammar defines.
"""

import argparse
import hashlib
import json
import os
Expand All @@ -46,6 +40,7 @@
root_dir = Path(os.path.realpath(__file__)).parent.parent

REPO = "w3c/webref"
BRANCH = "main"
CDDL_PATH = "ed/cddl"
DFNS_PATH = "ed/dfns"
API_HEADERS = {"Accept": "application/vnd.github+json", "User-Agent": "selenium-update-cddl"}
Expand Down Expand Up @@ -74,10 +69,6 @@
MODULE_FILE = root_dir / "MODULE.bazel"


def resolve_commit(branch):
return resolve_commit_for(REPO, branch)


def list_cddl_files(commit):
r = http.request(
"GET",
Expand Down Expand Up @@ -156,9 +147,18 @@ def sub_once(content, pattern, replacement, where):
return content


def update_pin(commit, cddl_entries, dfns_entries, bidi_commit, bidi_sha256):
content = BZL_FILE.read_text()
def current_bidi_pin(content):
commit = re.search(r'_BIDI_SPEC_HTML_COMMIT = "([0-9a-f]+)"', content).group(1)
sha256 = re.search(r'_BIDI_SPEC_HTML_SHA256 = "([0-9a-f]+)"', content).group(1)
return commit, sha256


def drop_commit(content):
"""Content with the webref commit blanked, so a pin bump alone does not read as a change."""
return re.sub(r'(?<![A-Z_])_COMMIT = "[0-9a-f]+"', "", content)


def update_pin(content, commit, cddl_entries, dfns_entries, bidi_commit, bidi_sha256):
# Anchor so this does not also match the tail of `_BIDI_SPEC_HTML_COMMIT = "…"`.
content = sub_once(content, r'(?<![A-Z_])_COMMIT = "[0-9a-f]+"', f'_COMMIT = "{commit}"', "_COMMIT assignment")
content = sub_once(
Expand All @@ -180,7 +180,7 @@ def update_pin(commit, cddl_entries, dfns_entries, bidi_commit, bidi_sha256):
"_BIDI_SPEC_HTML_SHA256 assignment",
)

BZL_FILE.write_text(content)
return content


def update_module(repo_names):
Expand All @@ -199,19 +199,11 @@ def update_module(repo_names):


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--commit", help="pin this exact webref commit instead of the branch tip")
parser.add_argument(
"--branch",
default="main",
help="webref branch to resolve when --commit is omitted (default: main)",
)
args = parser.parse_args()

commit = args.commit or resolve_commit(args.branch)
commit = resolve_commit_for(REPO, BRANCH)
print(f"Pinning {REPO}@{commit}")

before = existing_repo_names(BZL_FILE.read_text())
old = BZL_FILE.read_text()
before = existing_repo_names(old)

filenames = list_cddl_files(commit)
print(f"Found {len(filenames)} CDDL files in {CDDL_PATH}")
Expand All @@ -220,10 +212,16 @@ def main():
dfns_entries = build_dfns_entries(commit)
print(f"Refreshed {len(dfns_entries)} dfns indexes in {DFNS_PATH}")

# Probe with the pin already in the file so a gh-pages rebuild cannot open the gate.
webref_only = update_pin(old, commit, cddl_entries, dfns_entries, *current_bidi_pin(old))
if drop_commit(webref_only) == drop_commit(old):
print("No pinned spec content changed; leaving the pins at their current commits.")
return
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.

bidi_commit, bidi_sha256 = resolve_bidi_spec(BIDI_SPEC_BRANCH)
print(f"Pinning {BIDI_SPEC_REPO}@{bidi_commit} ({BIDI_SPEC_FILE})")

update_pin(commit, cddl_entries, dfns_entries, bidi_commit, bidi_sha256)
BZL_FILE.write_text(update_pin(old, commit, cddl_entries, dfns_entries, bidi_commit, bidi_sha256))

cddl_names = {name for name, _, _ in cddl_entries}
repo_names = cddl_names | {name for name, _, _ in dfns_entries} | {BIDI_SPEC_REPO_NAME}
Expand Down