diff --git a/.github/workflows/update-cddl.yml b/.github/workflows/update-cddl.yml new file mode 100644 index 0000000000000..5c843af2afee5 --- /dev/null +++ b/.github/workflows/update-cddl.yml @@ -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 + + 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 + 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 + 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 }} diff --git a/Rakefile b/Rakefile index 8a1ee04f7c9a7..96834c524c961 100644 --- a/Rakefile +++ b/Rakefile @@ -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' diff --git a/common/webref_cddl.bzl b/common/webref_cddl.bzl index 297628ecb7631..35d621806fa74 100644 --- a/common/webref_cddl.bzl +++ b/common/webref_cddl.bzl @@ -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) @@ -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( diff --git a/rake_tasks/ruby.rake b/rake_tasks/ruby.rake index 97c0527842eb2..cb7262717e108 100644 --- a/rake_tasks/ruby.rake +++ b/rake_tasks/ruby.rake @@ -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=========================" diff --git a/scripts/update_cddl.py b/scripts/update_cddl.py index 587f2289904af..489e5739c4c26 100644 --- a/scripts/update_cddl.py +++ b/scripts/update_cddl.py @@ -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 @@ -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"} @@ -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", @@ -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'(?