diff --git a/docs/AUTOMATION.md b/docs/AUTOMATION.md index 02f153176c7..e969d9edfb3 100644 --- a/docs/AUTOMATION.md +++ b/docs/AUTOMATION.md @@ -56,6 +56,26 @@ The publisher also leaves a draft with previous workflow metadata unchanged. It and stops without writing. Close that legacy draft so a later qualifying push can create a current workflow-owned draft, or mark it ready for review to transfer ownership to maintainers. +### Resolve a Draft Merge Conflict + +Each run merges the open managed draft with the triggering `main` commit before authoring. +When both changed the same lines, the author step fails before it creates a sandbox. +The error names the draft commit, the `main` commit, and each conflicting file. +Rerunning without a change hits the same conflict. + +1. Reproduce the conflict locally with + `git merge-tree --write-tree `. +2. Check the conflicting text against current source and tests, then choose the accurate wording. +3. Choose one recovery path: + - To keep automation ownership, open a PR that updates the conflicting `main` text so it + merges cleanly with the draft. Confirm with `git merge-tree` against the draft head. The next + qualifying push to `main` refreshes the draft. + - To take ownership, mark the draft PR ready for review and resolve the conflict on its branch. + Later workflow runs leave the PR unchanged. + +Do not push a resolution commit to the draft branch while automation owns it. The publisher +accepts only commits that the workflow created. + ### Recover an Orphaned Managed Branch If draft PR creation fails after branch creation, the publisher reports the exact branch and commit. diff --git a/test/generation/post-merge-docs.test.ts b/test/generation/post-merge-docs.test.ts index abd79fba50b..e0c23d3ae9e 100644 --- a/test/generation/post-merge-docs.test.ts +++ b/test/generation/post-merge-docs.test.ts @@ -965,7 +965,12 @@ describe("post-merge documentation runner", () => { git(source, ["checkout", "main"]); input.env.GITHUB_SHA = git(source, ["rev-parse", "HEAD"]); const { tools } = runnerTools(input); - expect(() => executePostMergeDocs(input.env, tools)).toThrow(); + const run = () => executePostMergeDocs(input.env, tools); + expect(run).toThrow( + `The managed documentation draft ${input.env.POST_MERGE_DOCS_PREVIOUS_SHA} conflicts with main ${input.env.GITHUB_SHA} in: docs/guide.mdx`, + ); + expect(run).toThrow("CONFLICT (content): Merge conflict in docs/guide.mdx"); + expect(run).toThrow("docs/AUTOMATION.md#resolve-a-draft-merge-conflict"); expect(tools.run).not.toHaveBeenCalled(); expect(fs.existsSync(path.join(input.root, "artifact/docs.patch"))).toBe(false); }); diff --git a/tools/post-merge-docs/README.md b/tools/post-merge-docs/README.md index 00509ea61f9..c1acd760227 100644 --- a/tools/post-merge-docs/README.md +++ b/tools/post-merge-docs/README.md @@ -7,8 +7,9 @@ This directory owns the trusted authoring and publishing boundary for `Docs / Au Each refresh merges the selected draft commit with the triggering `main` commit before authoring. The author extends those staged documentation changes. The reviewer checks the combined patch and -compares revisions or removals with the previous draft. A merge conflict stops the run for maintainer -resolution. Publication stops if the managed draft changed after selection. +compares revisions or removals with the previous draft. A merge conflict stops the run before authoring +and reports the conflicting files. Follow +[Resolve a Draft Merge Conflict](../../docs/AUTOMATION.md#resolve-a-draft-merge-conflict). Publication stops if the managed draft changed after selection. Successful draft creation, refresh, recovery, and no-change runs exit successfully. When a managed draft remains open, the publisher emits a notice linking to it for maintainer review and merge. diff --git a/tools/post-merge-docs/run.mts b/tools/post-merge-docs/run.mts index 7f7c4ed3106..7ae0d78fbb4 100755 --- a/tools/post-merge-docs/run.mts +++ b/tools/post-merge-docs/run.mts @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import { execFileSync } from "node:child_process"; +import { execFileSync, spawnSync } from "node:child_process"; import { createHash } from "node:crypto"; import fs from "node:fs"; import path from "node:path"; @@ -73,6 +73,28 @@ function git(repository: string, args: readonly string[]): string { }).trim(); } +function mergeDraftTree(repository: string, main: string, previous: string): string { + const result = spawnSync( + "git", + ["-C", repository, "merge-tree", "--write-tree", "--name-only", main, previous], + { encoding: "utf8", env: GIT_ENV, stdio: ["ignore", "pipe", "pipe"] }, + ); + if (result.error) throw result.error; + const [tree = "", ...rest] = result.stdout.trim().split("\n"); + if (result.status === 0) return exactSha(tree, "merged draft tree"); + if (result.status !== 1) fail(`git merge-tree failed: ${result.stderr.trim()}`); + const separator = rest.indexOf(""); + const files = separator < 0 ? rest : rest.slice(0, separator); + const messages = separator < 0 ? [] : rest.slice(separator + 1); + return fail( + [ + `The managed documentation draft ${previous} conflicts with main ${main} in: ${files.join(", ")}`, + ...messages, + "Follow the recovery procedure: https://github.com/NVIDIA/NemoClaw/blob/main/docs/AUTOMATION.md#resolve-a-draft-merge-conflict", + ].join("\n"), + ); +} + function reset(directory: string): void { fs.rmSync(directory, { force: true, recursive: true }); fs.mkdirSync(directory, { mode: 0o700, recursive: true }); @@ -176,8 +198,7 @@ function prepare(env: NodeJS.ProcessEnv): void { const main = exactSha(env.GITHUB_SHA, "GITHUB_SHA"); const previous = previousSha(env); if (previous) { - const merged = git(repository, ["merge-tree", "--write-tree", main, previous]); - git(repository, ["read-tree", "--reset", "-u", exactSha(merged, "merged draft tree")]); + git(repository, ["read-tree", "--reset", "-u", mergeDraftTree(repository, main, previous)]); validateCandidate(repository); } if (current === "review") {