From 0590ee4a7f5680f424f99a3f8255628d844170dd Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Wed, 25 Nov 2026 12:44:29 +0100 Subject: [PATCH 1/5] Add optional CodeMirror bundle bump pull request --- .github/workflows/build-codemirror.yml | 99 +++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-codemirror.yml b/.github/workflows/build-codemirror.yml index 2e5b31d..18a56f5 100644 --- a/.github/workflows/build-codemirror.yml +++ b/.github/workflows/build-codemirror.yml @@ -23,9 +23,11 @@ on: required: true type: string default: "0.25.11" - -permissions: - contents: read + produce_pr_to_bump_lib: + description: "Produce a PR to update vendor/codemirror and geometry-editor.js" + required: false + type: boolean + default: false jobs: build: @@ -33,6 +35,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 + permissions: + contents: write + pull-requests: write + defaults: run: working-directory: build/codemirror @@ -47,6 +53,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 + with: + ref: main - name: Set up Node.js uses: actions/setup-node@v7 @@ -121,3 +129,88 @@ jobs: path: build/codemirror/dist/${{ steps.js.outputs.name }}.js if-no-files-found: error retention-days: 30 + + - name: Prepare vendor bundle and update component import + if: ${{ inputs.produce_pr_to_bump_lib }} + working-directory: . + env: + BUNDLE_NAME: ${{ steps.js.outputs.name }} + run: | + set -euo pipefail + + source="build/codemirror/dist/${BUNDLE_NAME}.js" + target="vendor/codemirror/${BUNDLE_NAME}.js" + + test -s "${source}" + mkdir -p vendor/codemirror + cp "${source}" "${target}" + + python3 - "${BUNDLE_NAME}" <<'PY' + import re + import sys + from pathlib import Path + + bundle_name = sys.argv[1] + component = Path("lib/modules/components/geometry-editor.js") + content = component.read_text(encoding="utf-8") + + pattern = re.compile(r'(["\'])/vendor/codemirror/[^"\']+\.js\1') + matches = list(pattern.finditer(content)) + if len(matches) != 1: + raise SystemExit( + f"Expected exactly one CodeMirror bundle import in {component}; " + f"found {len(matches)}." + ) + + quote = matches[0].group(1) + replacement = f'{quote}/vendor/codemirror/{bundle_name}.js{quote}' + updated = pattern.sub(lambda _: replacement, content, count=1) + component.write_text(updated, encoding="utf-8") + print(f"Updated CodeMirror import in {component}") + PY + + - name: Create or update CodeMirror bump pull request + if: ${{ inputs.produce_pr_to_bump_lib }} + working-directory: . + env: + GH_TOKEN: ${{ github.token }} + BUNDLE_NAME: ${{ steps.js.outputs.name }} + run: | + set -euo pipefail + + branch="automation/bump-codemirror-${BUNDLE_NAME}" + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + # Always build the bump branch from the current main branch. + git fetch origin main + git switch --force-create "${branch}" origin/main + + git add \ + "vendor/codemirror/${BUNDLE_NAME}.js" \ + "lib/modules/components/geometry-editor.js" + + if git diff --cached --quiet; then + echo "::notice::The selected CodeMirror bundle is already present on main; no bump PR is needed." + exit 0 + fi + + git commit -m "Bump CodeMirror bundle to ${BUNDLE_NAME}" + git push --force origin "${branch}" + + if gh pr view "${branch}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then + echo "Updated existing pull request for ${branch}." + else + gh pr create \ + --repo "${GITHUB_REPOSITORY}" \ + --base main \ + --head "${branch}" \ + --title "Bump CodeMirror bundle (${BUNDLE_NAME})" \ + --body "## Summary + + - Add the generated CodeMirror bundle to `vendor/codemirror/`. + - Update the bundle import in `geometry-editor.js`. + + Generated by the **Build CodeMirror bundle** workflow. This pull request is intentionally left open for manual review and merging." + fi From 590e1425fcbf7f16f71b9dd92864c140c6c60673 Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Wed, 25 Nov 2026 12:44:54 +0100 Subject: [PATCH 2/5] Create bump branch before preparing vendor files --- .github/workflows/build-codemirror.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-codemirror.yml b/.github/workflows/build-codemirror.yml index 18a56f5..67fbfb7 100644 --- a/.github/workflows/build-codemirror.yml +++ b/.github/workflows/build-codemirror.yml @@ -138,6 +138,10 @@ jobs: run: | set -euo pipefail + branch="automation/bump-codemirror-${BUNDLE_NAME}" + git fetch origin main + git switch --force-create "${branch}" origin/main + source="build/codemirror/dist/${BUNDLE_NAME}.js" target="vendor/codemirror/${BUNDLE_NAME}.js" @@ -183,10 +187,6 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - # Always build the bump branch from the current main branch. - git fetch origin main - git switch --force-create "${branch}" origin/main - git add \ "vendor/codemirror/${BUNDLE_NAME}.js" \ "lib/modules/components/geometry-editor.js" From 25e0a2076977c25915e03ee5e7fbffc7caa21f9d Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Wed, 25 Nov 2026 12:45:37 +0100 Subject: [PATCH 3/5] Pass bump PR description through a file --- .github/workflows/build-codemirror.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-codemirror.yml b/.github/workflows/build-codemirror.yml index 67fbfb7..7dcae84 100644 --- a/.github/workflows/build-codemirror.yml +++ b/.github/workflows/build-codemirror.yml @@ -202,15 +202,19 @@ jobs: if gh pr view "${branch}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then echo "Updated existing pull request for ${branch}." else + cat > "${RUNNER_TEMP}/pr-body.md" <<'EOF' + ## Summary + + - Add the generated CodeMirror bundle to `vendor/codemirror/`. + - Update the bundle import in `geometry-editor.js`. + + Generated by the **Build CodeMirror bundle** workflow. This pull request is intentionally left open for manual review and merging. + EOF + gh pr create \ --repo "${GITHUB_REPOSITORY}" \ --base main \ --head "${branch}" \ --title "Bump CodeMirror bundle (${BUNDLE_NAME})" \ - --body "## Summary - - - Add the generated CodeMirror bundle to `vendor/codemirror/`. - - Update the bundle import in `geometry-editor.js`. - - Generated by the **Build CodeMirror bundle** workflow. This pull request is intentionally left open for manual review and merging." + --body-file "${RUNNER_TEMP}/pr-body.md" fi From 0dfd6466827a26dfa77e9a3212e4b8ce3a75b329 Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Wed, 25 Nov 2026 13:15:47 +0100 Subject: [PATCH 4/5] Add script to update CodeMirror component import --- .../scripts/update_component_import.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 build/codemirror/scripts/update_component_import.py diff --git a/build/codemirror/scripts/update_component_import.py b/build/codemirror/scripts/update_component_import.py new file mode 100644 index 0000000..57c6e4f --- /dev/null +++ b/build/codemirror/scripts/update_component_import.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +"""Update the CodeMirror bundle import in the geometry editor component.""" + +import argparse +import re +from pathlib import Path + + +def update_import(bundle_name: str, component: Path) -> None: + """Point the component's CodeMirror import at the selected bundle.""" + if not re.fullmatch(r"[a-zA-Z0-9._-]+", bundle_name): + raise ValueError(f"Invalid bundle name: {bundle_name!r}") + + source = component.read_text(encoding="utf-8") + pattern = re.compile( + r'(?P\bfrom\s*)(?P["\'])' + r'/vendor/codemirror/[^"\']+\.js(?P=quote)' + ) + matches = list(pattern.finditer(source)) + + if len(matches) != 1: + raise ValueError( + f"Expected exactly one CodeMirror bundle import in {component}; " + f"found {len(matches)}." + ) + + match = matches[0] + quote = match.group("quote") + replacement = ( + f'{match.group("prefix")}{quote}' + f'/vendor/codemirror/{bundle_name}.js{quote}' + ) + updated = source[: match.start()] + replacement + source[match.end() :] + component.write_text(updated, encoding="utf-8") + print(f"Updated CodeMirror bundle import in {component}") + + +def main() -> None: + parser = argparse.ArgumentParser( + description="Update the geometry editor's CodeMirror bundle import." + ) + parser.add_argument("bundle_name", help="Bundle name, without the .js suffix") + parser.add_argument( + "--component", + type=Path, + default=Path("lib/modules/components/geometry-editor.js"), + help="Component file to update", + ) + args = parser.parse_args() + + try: + update_import(args.bundle_name, args.component) + except (OSError, ValueError) as exc: + parser.error(str(exc)) + + +if __name__ == "__main__": + main() From ccef40bedba1b745f5f677674798696b33515c00 Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Wed, 25 Nov 2026 13:15:57 +0100 Subject: [PATCH 5/5] Use dedicated script to update CodeMirror import --- .github/workflows/build-codemirror.yml | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-codemirror.yml b/.github/workflows/build-codemirror.yml index 7dcae84..dcc5e49 100644 --- a/.github/workflows/build-codemirror.yml +++ b/.github/workflows/build-codemirror.yml @@ -149,29 +149,8 @@ jobs: mkdir -p vendor/codemirror cp "${source}" "${target}" - python3 - "${BUNDLE_NAME}" <<'PY' - import re - import sys - from pathlib import Path - - bundle_name = sys.argv[1] - component = Path("lib/modules/components/geometry-editor.js") - content = component.read_text(encoding="utf-8") - - pattern = re.compile(r'(["\'])/vendor/codemirror/[^"\']+\.js\1') - matches = list(pattern.finditer(content)) - if len(matches) != 1: - raise SystemExit( - f"Expected exactly one CodeMirror bundle import in {component}; " - f"found {len(matches)}." - ) - - quote = matches[0].group(1) - replacement = f'{quote}/vendor/codemirror/{bundle_name}.js{quote}' - updated = pattern.sub(lambda _: replacement, content, count=1) - component.write_text(updated, encoding="utf-8") - print(f"Updated CodeMirror import in {component}") - PY + python3 build/codemirror/scripts/update_component_import.py "${BUNDLE_NAME}" + - name: Create or update CodeMirror bump pull request if: ${{ inputs.produce_pr_to_bump_lib }}