From 0d92782aeafe34e3fc9d0e2e856beebb8990d577 Mon Sep 17 00:00:00 2001 From: Ira Iosub Date: Wed, 22 Apr 2026 18:24:16 +0100 Subject: [PATCH 1/2] add experimental formatting fixing action --- .github/workflows/fix-protocol-style.yml | 60 +++++++ .github/workflows/validate-protocol.yml | 6 + scripts/fix_protocol_style.py | 189 +++++++++++++++++++++++ tests/test_fix_protocol_style.py | 44 ++++++ 4 files changed, 299 insertions(+) create mode 100644 .github/workflows/fix-protocol-style.yml create mode 100644 scripts/fix_protocol_style.py create mode 100644 tests/test_fix_protocol_style.py diff --git a/.github/workflows/fix-protocol-style.yml b/.github/workflows/fix-protocol-style.yml new file mode 100644 index 0000000..edceccc --- /dev/null +++ b/.github/workflows/fix-protocol-style.yml @@ -0,0 +1,60 @@ +name: fix-protocol-style + +on: + workflow_dispatch: + inputs: + base_branch: + description: Branch to fix and open a PR against + required: true + default: main + +permissions: + contents: write + pull-requests: write + +concurrency: + group: fix-protocol-style-${{ github.event.inputs.base_branch || 'main' }} + cancel-in-progress: false + +jobs: + fix-style: + runs-on: ubuntu-latest + + steps: + - name: Check out target branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.inputs.base_branch }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Run unit tests + run: | + python -m unittest discover -s tests -p 'test_*.py' + + - name: Apply style fixer + run: | + python scripts/fix_protocol_style.py README.md + + - name: Verify README style after fixing + run: | + python scripts/validate_protocol_style.py README.md + + - name: Create pull request with style fixes + uses: peter-evans/create-pull-request@v7 + with: + base: ${{ github.event.inputs.base_branch }} + branch: automation/fix-protocol-style/${{ github.event.inputs.base_branch }} + delete-branch: true + commit-message: Normalize protocol README style + title: Normalize protocol README style + body: | + This PR was opened automatically by the style-fix workflow. + + It applies deterministic README style fixes from `scripts/fix_protocol_style.py` and re-validates the result with `scripts/validate_protocol_style.py`. + add-paths: | + README.md diff --git a/.github/workflows/validate-protocol.yml b/.github/workflows/validate-protocol.yml index e3999e5..2675b48 100644 --- a/.github/workflows/validate-protocol.yml +++ b/.github/workflows/validate-protocol.yml @@ -6,23 +6,29 @@ on: - main paths: - README.md + - scripts/fix_protocol_style.py - scripts/validate_protocol.py - scripts/validate_protocol_content.py - scripts/validate_protocol_style.py + - tests/test_fix_protocol_style.py - tests/test_validate_protocol_content.py - tests/test_validate_protocol_style.py - .github/workflows/validate-protocol.yml + - .github/workflows/fix-protocol-style.yml push: branches: - main paths: - README.md + - scripts/fix_protocol_style.py - scripts/validate_protocol.py - scripts/validate_protocol_content.py - scripts/validate_protocol_style.py + - tests/test_fix_protocol_style.py - tests/test_validate_protocol_content.py - tests/test_validate_protocol_style.py - .github/workflows/validate-protocol.yml + - .github/workflows/fix-protocol-style.yml workflow_dispatch: jobs: diff --git a/scripts/fix_protocol_style.py b/scripts/fix_protocol_style.py new file mode 100644 index 0000000..52b3d7c --- /dev/null +++ b/scripts/fix_protocol_style.py @@ -0,0 +1,189 @@ +"""Apply deterministic style fixes to a protocol README.""" + +from pathlib import Path +import argparse +import re +from typing import Callable, Match + +NUMBER_RE = r"\d+(?:\.\d+)?" +TEMPERATURE_RE = re.compile( + rf"\b(?P{NUMBER_RE})(?P\s*)(?P°?)(?P\s*)(?P[Cc])\b" +) +PH_RE = re.compile(r"\b(?P