From 041fee04f14eb941e5598f69d71cf31c74e4a8cd Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 3 Sep 2025 02:37:22 +0100 Subject: [PATCH] missing cases in push-to-branch --- .../test-claude-create-pull-request.lock.yml | 14 +++++++-- .../test-codex-create-pull-request.lock.yml | 14 +++++++-- pkg/workflow/compiler.go | 29 +++++++++++++++++-- pkg/workflow/git_patch.go | 18 ++++++++++-- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-claude-create-pull-request.lock.yml b/.github/workflows/test-claude-create-pull-request.lock.yml index fd2cee785cb..de0a102742e 100644 --- a/.github/workflows/test-claude-create-pull-request.lock.yml +++ b/.github/workflows/test-claude-create-pull-request.lock.yml @@ -100,7 +100,7 @@ jobs: To create a pull request: 1. Make any file changes directly in the working directory 2. If you haven't done so already, create a local branch using an appropriate unique name - 3. Add and commit your files to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to. + 3. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to. 4. Do not push your changes. That will be done later. Instead append the PR specification to the file "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "create-pull-request", "branch": "branch-name", "title": "PR title", "body": "PR body in markdown", "labels": ["optional", "labels"]} @@ -937,7 +937,17 @@ jobs: # Extract branch value using sed BRANCH_NAME=$(echo "$line" | sed -n 's/.*"branch"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') if [ -n "$BRANCH_NAME" ]; then - echo "Extracted branch name: $BRANCH_NAME" + echo "Extracted branch name from create-pull-request: $BRANCH_NAME" + break + fi + # Extract branch from push-to-branch line using simple grep and sed + elif echo "$line" | grep -q '"type"[[:space:]]*:[[:space:]]*"push-to-branch"'; then + echo "Found push-to-branch line: $line" + # For push-to-branch, we don't extract branch from JSONL since it's configured in the workflow + # The branch name should come from the environment variable GITHUB_AW_PUSH_BRANCH + if [ -n "$GITHUB_AW_PUSH_BRANCH" ]; then + BRANCH_NAME="$GITHUB_AW_PUSH_BRANCH" + echo "Using configured push-to-branch target: $BRANCH_NAME" break fi fi diff --git a/.github/workflows/test-codex-create-pull-request.lock.yml b/.github/workflows/test-codex-create-pull-request.lock.yml index aa830f463cf..1bc241ef433 100644 --- a/.github/workflows/test-codex-create-pull-request.lock.yml +++ b/.github/workflows/test-codex-create-pull-request.lock.yml @@ -102,7 +102,7 @@ jobs: To create a pull request: 1. Make any file changes directly in the working directory 2. If you haven't done so already, create a local branch using an appropriate unique name - 3. Add and commit your files to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to. + 3. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to. 4. Do not push your changes. That will be done later. Instead append the PR specification to the file "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "create-pull-request", "branch": "branch-name", "title": "PR title", "body": "PR body in markdown", "labels": ["optional", "labels"]} @@ -820,7 +820,17 @@ jobs: # Extract branch value using sed BRANCH_NAME=$(echo "$line" | sed -n 's/.*"branch"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') if [ -n "$BRANCH_NAME" ]; then - echo "Extracted branch name: $BRANCH_NAME" + echo "Extracted branch name from create-pull-request: $BRANCH_NAME" + break + fi + # Extract branch from push-to-branch line using simple grep and sed + elif echo "$line" | grep -q '"type"[[:space:]]*:[[:space:]]*"push-to-branch"'; then + echo "Found push-to-branch line: $line" + # For push-to-branch, we don't extract branch from JSONL since it's configured in the workflow + # The branch name should come from the environment variable GITHUB_AW_PUSH_BRANCH + if [ -n "$GITHUB_AW_PUSH_BRANCH" ]; then + BRANCH_NAME="$GITHUB_AW_PUSH_BRANCH" + echo "Using configured push-to-branch target: $BRANCH_NAME" break fi fi diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go index 44a22aabc6b..7027550e13d 100644 --- a/pkg/workflow/compiler.go +++ b/pkg/workflow/compiler.go @@ -2227,7 +2227,7 @@ func (c *Compiler) generateMainJobSteps(yaml *strings.Builder, data *WorkflowDat // Add git patch generation step only if safe-outputs create-pull-request feature is used if data.SafeOutputs != nil && (data.SafeOutputs.CreatePullRequests != nil || data.SafeOutputs.PushToBranch != nil) { - c.generateGitPatchStep(yaml) + c.generateGitPatchStep(yaml, data) } // Add post-steps (if any) after AI execution @@ -2356,6 +2356,14 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng yaml.WriteString(", ") } yaml.WriteString("Updating Issues") + written = true + } + + if data.SafeOutputs.PushToBranch != nil { + if written { + yaml.WriteString(", ") + } + yaml.WriteString("Pushing Changes to Branch") } yaml.WriteString("\n") yaml.WriteString(" \n") @@ -2388,7 +2396,7 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng yaml.WriteString(" To create a pull request:\n") yaml.WriteString(" 1. Make any file changes directly in the working directory\n") yaml.WriteString(" 2. If you haven't done so already, create a local branch using an appropriate unique name\n") - yaml.WriteString(" 3. Add and commit your files to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to.\n") + yaml.WriteString(" 3. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to.\n") yaml.WriteString(" 4. Do not push your changes. That will be done later. Instead append the PR specification to the file \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n") yaml.WriteString(" ```json\n") yaml.WriteString(" {\"type\": \"create-pull-request\", \"branch\": \"branch-name\", \"title\": \"PR title\", \"body\": \"PR body in markdown\", \"labels\": [\"optional\", \"labels\"]}\n") @@ -2434,6 +2442,19 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng yaml.WriteString(" \n") } + if data.SafeOutputs.PushToBranch != nil { + yaml.WriteString(" **Pushing Changes to Branch**\n") + yaml.WriteString(" \n") + yaml.WriteString(" To push changes to a branch:\n") + yaml.WriteString(" 1. Make any file changes directly in the working directory\n") + yaml.WriteString(" 2. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to.\n") + yaml.WriteString(" 3. Indicate your intention to push to the branch by writing to the file \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n") + yaml.WriteString(" ```json\n") + yaml.WriteString(" {\"type\": \"push-to-branch\", \"message\": \"Commit message describing the changes\"}\n") + yaml.WriteString(" ```\n") + yaml.WriteString(" \n") + } + yaml.WriteString(" **Example JSONL file content:**\n") yaml.WriteString(" ```\n") @@ -2455,6 +2476,10 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng yaml.WriteString(" {\"type\": \"add-issue-label\", \"labels\": [\"bug\", \"priority-high\"]}\n") exampleCount++ } + if data.SafeOutputs.PushToBranch != nil { + yaml.WriteString(" {\"type\": \"push-to-branch\", \"message\": \"Update documentation with latest changes\"}\n") + exampleCount++ + } // If no SafeOutputs are enabled, show a generic example if exampleCount == 0 { diff --git a/pkg/workflow/git_patch.go b/pkg/workflow/git_patch.go index d164c3b0492..0d6e7cf5820 100644 --- a/pkg/workflow/git_patch.go +++ b/pkg/workflow/git_patch.go @@ -3,11 +3,15 @@ package workflow import "strings" // generateGitPatchStep generates a step that creates and uploads a git patch of changes -func (c *Compiler) generateGitPatchStep(yaml *strings.Builder) { +func (c *Compiler) generateGitPatchStep(yaml *strings.Builder, data *WorkflowData) { yaml.WriteString(" - name: Generate git patch\n") yaml.WriteString(" if: always()\n") yaml.WriteString(" env:\n") yaml.WriteString(" GITHUB_AW_SAFE_OUTPUTS: ${{ env.GITHUB_AW_SAFE_OUTPUTS }}\n") + // Add push-to-branch configuration if available + if data.SafeOutputs != nil && data.SafeOutputs.PushToBranch != nil { + yaml.WriteString(" GITHUB_AW_PUSH_BRANCH: \"" + data.SafeOutputs.PushToBranch.Branch + "\"\n") + } yaml.WriteString(" run: |\n") yaml.WriteString(" # Check current git status\n") yaml.WriteString(" echo \"Current git status:\"\n") @@ -25,7 +29,17 @@ func (c *Compiler) generateGitPatchStep(yaml *strings.Builder) { yaml.WriteString(" # Extract branch value using sed\n") yaml.WriteString(" BRANCH_NAME=$(echo \"$line\" | sed -n 's/.*\"branch\"[[:space:]]*:[[:space:]]*\"\\([^\"]*\\)\".*/\\1/p')\n") yaml.WriteString(" if [ -n \"$BRANCH_NAME\" ]; then\n") - yaml.WriteString(" echo \"Extracted branch name: $BRANCH_NAME\"\n") + yaml.WriteString(" echo \"Extracted branch name from create-pull-request: $BRANCH_NAME\"\n") + yaml.WriteString(" break\n") + yaml.WriteString(" fi\n") + yaml.WriteString(" # Extract branch from push-to-branch line using simple grep and sed\n") + yaml.WriteString(" elif echo \"$line\" | grep -q '\"type\"[[:space:]]*:[[:space:]]*\"push-to-branch\"'; then\n") + yaml.WriteString(" echo \"Found push-to-branch line: $line\"\n") + yaml.WriteString(" # For push-to-branch, we don't extract branch from JSONL since it's configured in the workflow\n") + yaml.WriteString(" # The branch name should come from the environment variable GITHUB_AW_PUSH_BRANCH\n") + yaml.WriteString(" if [ -n \"$GITHUB_AW_PUSH_BRANCH\" ]; then\n") + yaml.WriteString(" BRANCH_NAME=\"$GITHUB_AW_PUSH_BRANCH\"\n") + yaml.WriteString(" echo \"Using configured push-to-branch target: $BRANCH_NAME\"\n") yaml.WriteString(" break\n") yaml.WriteString(" fi\n") yaml.WriteString(" fi\n")