Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/AUTOMATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <main-sha> <draft-sha>`.
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.
Expand Down
7 changes: 6 additions & 1 deletion test/generation/post-merge-docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
5 changes: 3 additions & 2 deletions tools/post-merge-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 24 additions & 3 deletions tools/post-merge-docs/run.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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") {
Expand Down
Loading