|
| 1 | +name: Repair strict fix runner |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - fix/strict-content-promotion-gate |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + repair-runner: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd |
| 16 | + with: |
| 17 | + ref: fix/strict-content-promotion-gate |
| 18 | + - name: Make patch anchors indentation-safe |
| 19 | + run: | |
| 20 | + python - <<'PY' |
| 21 | + from pathlib import Path |
| 22 | +
|
| 23 | + path = Path('.github/workflows/tmp-apply-strict-content-promotion-fix.yml') |
| 24 | + text = path.read_text(encoding='utf-8') |
| 25 | + old = ''' def replace_once(path, old, new): |
| 26 | + p = Path(path) |
| 27 | + text = p.read_text(encoding='utf-8') |
| 28 | + if old not in text: |
| 29 | + raise SystemExit(f'anchor missing in {path}: {old[:120]!r}') |
| 30 | + p.write_text(text.replace(old, new, 1), encoding='utf-8') |
| 31 | +''' |
| 32 | + new = ''' def replace_once(path, old, new): |
| 33 | + p = Path(path) |
| 34 | + text = p.read_text(encoding='utf-8') |
| 35 | + if old in text: |
| 36 | + p.write_text(text.replace(old, new, 1), encoding='utf-8') |
| 37 | + return |
| 38 | + source_lines = text.splitlines(keepends=True) |
| 39 | + wanted = old.splitlines() |
| 40 | + for start in range(0, len(source_lines) - len(wanted) + 1): |
| 41 | + window = source_lines[start:start + len(wanted)] |
| 42 | + if all(window[index].strip() == wanted[index].strip() for index in range(len(wanted))): |
| 43 | + target_indent = len(window[0]) - len(window[0].lstrip(' ')) |
| 44 | + replacement_lines = new.splitlines(keepends=True) |
| 45 | + first = next((line for line in replacement_lines if line.strip()), '') |
| 46 | + replacement_base = len(first) - len(first.lstrip(' ')) |
| 47 | + adjusted = [] |
| 48 | + for line in replacement_lines: |
| 49 | + if not line.strip(): |
| 50 | + adjusted.append(line) |
| 51 | + continue |
| 52 | + newline = '\\n' if line.endswith('\\n') else '' |
| 53 | + body = line[:-1] if newline else line |
| 54 | + indent = len(body) - len(body.lstrip(' ')) |
| 55 | + relative = max(0, indent - replacement_base) |
| 56 | + adjusted.append(' ' * (target_indent + relative) + body.lstrip(' ') + newline) |
| 57 | + source_lines[start:start + len(wanted)] = [''.join(adjusted)] |
| 58 | + p.write_text(''.join(source_lines), encoding='utf-8') |
| 59 | + return |
| 60 | + raise SystemExit(f'anchor missing in {path}: {old[:120]!r}') |
| 61 | +''' |
| 62 | + if old not in text: |
| 63 | + raise SystemExit('original replace_once helper not found') |
| 64 | + path.write_text(text.replace(old, new, 1), encoding='utf-8') |
| 65 | + Path('.github/workflows/tmp-repair-strict-fix-runner.yml').unlink() |
| 66 | + PY |
| 67 | + - name: Commit repaired runner |
| 68 | + run: | |
| 69 | + git config user.name 'niakvio-ci' |
| 70 | + git config user.email 'actions@users.noreply.github.com' |
| 71 | + git add -A |
| 72 | + git commit -m 'ci: make strict fix patcher indentation-safe' |
| 73 | + git push origin HEAD:fix/strict-content-promotion-gate |
0 commit comments