Skip to content

GitHub Action: redline the .docx files a PR changes#27

Open
JSv4 wants to merge 2 commits into
mainfrom
claude/docx-redlines-github-action-fh2yma
Open

GitHub Action: redline the .docx files a PR changes#27
JSv4 wants to merge 2 commits into
mainfrom
claude/docx-redlines-github-action-fh2yma

Conversation

@JSv4

@JSv4 JSv4 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Closes #12.

This makes the repository usable directly as a GitHub Action, per the design discussed on the issue (inspired by vanbroup/build-guidelines-action): explicit file-pair configuration, an author input for the tracked changes, plus an auto-detect mode that redlines every .docx a pull request changes.

Minimal usage

on: pull_request
jobs:
  redline:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: JSv4/Python-Redlines@main

For each .docx the PR modifies (or renames), the action extracts the base and head versions from git, runs the redline engine, writes redlines/<path>/<name>.redline.docx with native Word tracked changes, uploads the lot as a workflow artifact, and posts a job-summary table (file → revision count → outputs). Explicit-pair mode (original: + modified: inputs) covers the "just compare these two files" case from the issue thread.

What's in the change

  • action.yml — composite action. Installs python-redlines[docxodus|ooxmlpowertools] from PyPI (prebuilt engine wheels — nothing compiles at run time), runs the driver, uploads the artifact, links it from the summary. Inputs: files globs, base-ref/head-ref, author, engine, comparison (wmlcomparer/docxdiff), detect-moves, output-dir, html-preview, summary, upload-artifact/artifact-name, and version pins for the pip package and preview tool. Outputs: count, any-changes, redlines (JSON records), artifact-url.
  • action/redline_changed.py — stdlib-only driver. Resolves the comparison window from the triggering event: PR base/head with merge-base semantics (matches the PR "files changed" view; falls back with a warning on shallow clones), push before/after (with a parent-commit fallback for new branches), or HEAD~1..HEAD; missing commits are fetched by SHA. Diffs with rename detection and case-insensitive glob pathspecs, reads both sides out of git (independent of checkout state — important on PR merge commits), and reports added/deleted files without redlining them (no counterpart to compare). Pure renames skip the engine. A per-file engine failure is reported and fails the run only after every file is processed.
  • HTML previewshtml-preview: auto|true|false renders each redline to browser-viewable HTML (ins/del/move markup) via the Docxodus Docx2Html dotnet tool's new --track-changes mode, added in the companion PR docx2html: add --track-changes and story rendering flags Docxodus#269. Until that ships in a Docxodus release (≥ 7.1.0 on NuGet), the default auto mode detects the missing capability and skips with a warning instead of producing a misleading "all changes accepted" preview; true makes it a hard requirement; false skips the .NET setup entirely.
  • Teststests/test_action_script.py (28 tests): input validation, --name-status -z parsing, ref resolution across event shapes, pathspec filtering, output-path safety for absolute sources (caught a real bug where an absolute modified: path escaped output-dir), and two integration tests running the real engine over the repo fixtures (9 revisions, matching the documented fixture count).
  • Self-test workflow.github/workflows/redline-action-test.yml runs the action from the checkout in both modes and asserts on outputs; the auto-detect job builds a synthetic two-commit docx history in the runner's clone.
  • Docs — README "GitHub Action" section with the full input table; CLAUDE.md maintenance notes.

Verification

  • python -m pytest tests/ — 68 passed (40 existing + 28 new).
  • Driver exercised end-to-end locally in both modes against the published python-redlines==0.3.0 wheels: auto-detect over a scratch repo (modified + added + deleted docx classified correctly, 9 revisions) and explicit-pair with a locally-built docx2html --track-changes producing an HTML preview with 11 ins/del elements.
  • The self-test workflow runs on this PR itself.

🤖 Generated with Claude Code

https://claude.ai/code/session_0142X9VTMpdo639kHKQa4PE1


Generated by Claude Code

… files

Closes #12. 'uses: JSv4/Python-Redlines@<ref>' now redlines every .docx a
pull request (or push) changes, or an explicit original/modified pair, and
surfaces the results where reviewers look:

- action.yml — composite action: installs python-redlines from PyPI (prebuilt
  engine wheels, no .NET build), runs the driver, uploads the output dir as a
  workflow artifact, and links it from the job summary. Inputs cover file
  globs, base/head refs, author, engine (docxodus/xmlpowertools), comparison
  algorithm (wmlcomparer/docxdiff), move detection, and output/artifact knobs.
- action/redline_changed.py — stdlib-only driver. Auto-detect mode resolves
  the comparison window from the triggering event (PR base/head with
  merge-base semantics, push before/after, or HEAD~1..HEAD), diffs with
  rename detection, extracts both sides from git (no dependence on checkout
  state), and writes <output-dir>/<path>/<name>.redline.docx with native Word
  tracked changes. Added/deleted files are reported but not redlined; pure
  renames skip the engine. Per-file failures are reported and fail the run
  after processing everything. Emits count/any-changes/redlines outputs and a
  job-summary table.
- HTML previews: html-preview: auto|true|false renders each redline to
  browser-viewable HTML via the Docxodus Docx2Html dotnet tool's new
  --track-changes mode (Docxodus >= 7.1.0); 'auto' skips with a warning when
  the installed tool lacks support.
- tests/test_action_script.py — 28 tests: input validation, name-status
  parsing, ref resolution (push/PR/merge-base/new-branch), pathspec
  filtering, output-path safety for absolute sources, plus two integration
  tests running the real engine over the repo fixtures.
- .github/workflows/redline-action-test.yml — self-test running the action
  from the checkout in both modes and asserting on its outputs.
- README.md / CLAUDE.md — usage and maintenance docs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0142X9VTMpdo639kHKQa4PE1
Path.is_absolute() is False on Windows for a rooted-but-driveless path like
'/x/y', yet joining it onto output_dir still replaces the whole prefix, so
the escape guard never fired (caught by the new unit test on the
windows-latest CI matrix). Guard on drive/root/'..' components as well, and
cover '..' traversal in the test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0142X9VTMpdo639kHKQa4PE1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub Action

2 participants