diff --git a/.github/workflows/test-claude-add-issue-comment.lock.yml b/.github/workflows/test-claude-add-issue-comment.lock.yml index 88d1eca7517..00895d7c714 100644 --- a/.github/workflows/test-claude-add-issue-comment.lock.yml +++ b/.github/workflows/test-claude-add-issue-comment.lock.yml @@ -263,9 +263,13 @@ jobs: ### Available Output Types: **Adding a Comment to an Issue or Pull Request** + + To add a comment to an issue or pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-comment", "body": "Your comment content in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-claude-add-issue-labels.lock.yml b/.github/workflows/test-claude-add-issue-labels.lock.yml index b99dfc186b7..23451b32279 100644 --- a/.github/workflows/test-claude-add-issue-labels.lock.yml +++ b/.github/workflows/test-claude-add-issue-labels.lock.yml @@ -263,9 +263,13 @@ jobs: ### Available Output Types: **Adding Labels to Issues or Pull Requests** + + To add labels to a pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-label", "labels": ["label1", "label2", "label3"]} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-claude-command.lock.yml b/.github/workflows/test-claude-command.lock.yml index c06a3c68e34..61cb4cf19ad 100644 --- a/.github/workflows/test-claude-command.lock.yml +++ b/.github/workflows/test-claude-command.lock.yml @@ -501,9 +501,13 @@ jobs: ### Available Output Types: **Adding a Comment to an Issue or Pull Request** + + To add a comment to an issue or pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-comment", "body": "Your comment content in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` @@ -1318,7 +1322,7 @@ jobs: create_issue_comment: needs: test-claude-command - if: github.event.issue.number || github.event.pull_request.number + if: (contains(github.event.issue.body, '/test-claude-command') || contains(github.event.comment.body, '/test-claude-command') || contains(github.event.pull_request.body, '/test-claude-command')) && (github.event.issue.number || github.event.pull_request.number) runs-on: ubuntu-latest permissions: contents: read diff --git a/.github/workflows/test-claude-create-issue.lock.yml b/.github/workflows/test-claude-create-issue.lock.yml index da5be232e8c..bd775ffd5db 100644 --- a/.github/workflows/test-claude-create-issue.lock.yml +++ b/.github/workflows/test-claude-create-issue.lock.yml @@ -92,9 +92,13 @@ jobs: ### Available Output Types: **Creating an Issue** + + To create an issue: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "create-issue", "title": "Issue title", "body": "Issue body in markdown", "labels": ["optional", "labels"]} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-claude-create-pull-request.lock.yml b/.github/workflows/test-claude-create-pull-request.lock.yml index bc248180a84..d3dc1d6d688 100644 --- a/.github/workflows/test-claude-create-pull-request.lock.yml +++ b/.github/workflows/test-claude-create-pull-request.lock.yml @@ -105,6 +105,7 @@ jobs: ```json {"type": "create-pull-request", "branch": "branch-name", "title": "PR title", "body": "PR body in markdown", "labels": ["optional", "labels"]} ``` + 5. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-claude-mcp.lock.yml b/.github/workflows/test-claude-mcp.lock.yml index 4bb49b78d5c..fdc53158926 100644 --- a/.github/workflows/test-claude-mcp.lock.yml +++ b/.github/workflows/test-claude-mcp.lock.yml @@ -284,9 +284,13 @@ jobs: ### Available Output Types: **Creating an Issue** + + To create an issue: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "create-issue", "title": "Issue title", "body": "Issue body in markdown", "labels": ["optional", "labels"]} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-claude-push-to-branch.lock.yml b/.github/workflows/test-claude-push-to-branch.lock.yml index 0a4feab9528..3ea2fd300bc 100644 --- a/.github/workflows/test-claude-push-to-branch.lock.yml +++ b/.github/workflows/test-claude-push-to-branch.lock.yml @@ -2,7 +2,7 @@ # To update this file, edit the corresponding .md file and run: # gh aw compile -name: "Claude Test File" +name: "Test Claude Push To Branch" on: issues: types: [opened, edited, reopened] @@ -18,7 +18,7 @@ permissions: {} concurrency: group: "gh-aw-${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number }}" -run-name: "Claude Test File" +run-name: "Test Claude Push To Branch" jobs: task: @@ -63,7 +63,7 @@ jobs: echo "User ${{ github.actor }} is not a team member" exit 1 - claude-test-file: + test-claude-push-to-branch: needs: task runs-on: ubuntu-latest permissions: read-all @@ -129,7 +129,7 @@ jobs: Create a new file called "claude-test-file.md" with the following content: ```markdown - # Claude Test File + # Test Claude Push To Branch This file was created by the Claude agentic workflow to test the push-to-branch functionality. @@ -166,7 +166,7 @@ jobs: Create a commit message: "Add test files created by Claude agentic workflow" - Push these changes to the branch for the pull request + Push these changes to the branch for the pull request #${github.event.pull_request.number} --- @@ -181,13 +181,14 @@ jobs: **Pushing Changes to Branch** - To push changes to a branch: + To push changes to a branch, for example to add code to a pull request: 1. Make any file changes directly in the working directory 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. 3. Indicate your intention to push to the branch by writing to the file "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "push-to-branch", "message": "Commit message describing the changes"} ``` + 4. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` @@ -219,7 +220,7 @@ jobs: engine_name: "Claude Code", model: "", version: "", - workflow_name: "Claude Test File", + workflow_name: "Test Claude Push To Branch", experimental: false, supports_tools_whitelist: true, supports_http_transport: true, @@ -329,13 +330,13 @@ jobs: run: | # Copy the detailed execution file from Agentic Action if available if [ -n "${{ steps.agentic_execution.outputs.execution_file }}" ] && [ -f "${{ steps.agentic_execution.outputs.execution_file }}" ]; then - cp ${{ steps.agentic_execution.outputs.execution_file }} /tmp/claude-test-file.log + cp ${{ steps.agentic_execution.outputs.execution_file }} /tmp/test-claude-push-to-branch.log else - echo "No execution file output found from Agentic Action" >> /tmp/claude-test-file.log + echo "No execution file output found from Agentic Action" >> /tmp/test-claude-push-to-branch.log fi # Ensure log file exists - touch /tmp/claude-test-file.log + touch /tmp/test-claude-push-to-branch.log - name: Check if workflow-complete.txt exists, if so upload it id: check_file run: | @@ -731,7 +732,7 @@ jobs: if: always() uses: actions/github-script@v7 env: - AGENT_LOG_FILE: /tmp/claude-test-file.log + AGENT_LOG_FILE: /tmp/test-claude-push-to-branch.log with: script: | function main() { @@ -1006,8 +1007,8 @@ jobs: if: always() uses: actions/upload-artifact@v4 with: - name: claude-test-file.log - path: /tmp/claude-test-file.log + name: test-claude-push-to-branch.log + path: /tmp/test-claude-push-to-branch.log if-no-files-found: warn - name: Generate git patch if: always() @@ -1131,8 +1132,8 @@ jobs: if-no-files-found: ignore push_to_branch: - needs: claude-test-file - if: always() + needs: test-claude-push-to-branch + if: contains(github.event.issue.body, '/test-claude-push-to-branch') || contains(github.event.comment.body, '/test-claude-push-to-branch') || contains(github.event.pull_request.body, '/test-claude-push-to-branch') runs-on: ubuntu-latest permissions: contents: write @@ -1156,7 +1157,7 @@ jobs: id: push_to_branch uses: actions/github-script@v7 env: - GITHUB_AW_AGENT_OUTPUT: ${{ needs.claude-test-file.outputs.output }} + GITHUB_AW_AGENT_OUTPUT: ${{ needs.test-claude-push-to-branch.outputs.output }} GITHUB_AW_PUSH_BRANCH: "claude-test-branch" GITHUB_AW_PUSH_TARGET: "*" with: diff --git a/.github/workflows/test-claude-push-to-branch.md b/.github/workflows/test-claude-push-to-branch.md index 2c0f3ac20f3..0b4efea732c 100644 --- a/.github/workflows/test-claude-push-to-branch.md +++ b/.github/workflows/test-claude-push-to-branch.md @@ -15,7 +15,7 @@ safe-outputs: Create a new file called "claude-test-file.md" with the following content: ```markdown -# Claude Test File +# Test Claude Push To Branch This file was created by the Claude agentic workflow to test the push-to-branch functionality. @@ -52,4 +52,4 @@ if __name__ == "__main__": Create a commit message: "Add test files created by Claude agentic workflow" -Push these changes to the branch for the pull request +Push these changes to the branch for the pull request #${github.event.pull_request.number} diff --git a/.github/workflows/test-claude-update-issue.lock.yml b/.github/workflows/test-claude-update-issue.lock.yml index c6e2aa194e1..1157c275078 100644 --- a/.github/workflows/test-claude-update-issue.lock.yml +++ b/.github/workflows/test-claude-update-issue.lock.yml @@ -267,9 +267,12 @@ jobs: ### Available Output Types: **Updating an Issue** + + To udpate an issue: ```json {"type": "update-issue", "status": "open" // or "closed", "title": "New issue title", "body": "Updated issue body in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-codex-add-issue-comment.lock.yml b/.github/workflows/test-codex-add-issue-comment.lock.yml index 1b187d7ebc2..da8a1482544 100644 --- a/.github/workflows/test-codex-add-issue-comment.lock.yml +++ b/.github/workflows/test-codex-add-issue-comment.lock.yml @@ -265,9 +265,13 @@ jobs: ### Available Output Types: **Adding a Comment to an Issue or Pull Request** + + To add a comment to an issue or pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-comment", "body": "Your comment content in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-codex-add-issue-labels.lock.yml b/.github/workflows/test-codex-add-issue-labels.lock.yml index 2d7655645cb..a4618034aeb 100644 --- a/.github/workflows/test-codex-add-issue-labels.lock.yml +++ b/.github/workflows/test-codex-add-issue-labels.lock.yml @@ -265,9 +265,13 @@ jobs: ### Available Output Types: **Adding Labels to Issues or Pull Requests** + + To add labels to a pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-label", "labels": ["label1", "label2", "label3"]} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-codex-command.lock.yml b/.github/workflows/test-codex-command.lock.yml index 29d978be318..6ff932c72f6 100644 --- a/.github/workflows/test-codex-command.lock.yml +++ b/.github/workflows/test-codex-command.lock.yml @@ -501,9 +501,13 @@ jobs: ### Available Output Types: **Adding a Comment to an Issue or Pull Request** + + To add a comment to an issue or pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-comment", "body": "Your comment content in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` @@ -1318,7 +1322,7 @@ jobs: create_issue_comment: needs: test-codex-command - if: github.event.issue.number || github.event.pull_request.number + if: (contains(github.event.issue.body, '/test-codex-command') || contains(github.event.comment.body, '/test-codex-command') || contains(github.event.pull_request.body, '/test-codex-command')) && (github.event.issue.number || github.event.pull_request.number) runs-on: ubuntu-latest permissions: contents: read diff --git a/.github/workflows/test-codex-create-issue.lock.yml b/.github/workflows/test-codex-create-issue.lock.yml index 8cf0b2d00eb..2570f47854b 100644 --- a/.github/workflows/test-codex-create-issue.lock.yml +++ b/.github/workflows/test-codex-create-issue.lock.yml @@ -94,9 +94,13 @@ jobs: ### Available Output Types: **Creating an Issue** + + To create an issue: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "create-issue", "title": "Issue title", "body": "Issue body in markdown", "labels": ["optional", "labels"]} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-codex-create-pull-request.lock.yml b/.github/workflows/test-codex-create-pull-request.lock.yml index 1bc241ef433..502ae2845e9 100644 --- a/.github/workflows/test-codex-create-pull-request.lock.yml +++ b/.github/workflows/test-codex-create-pull-request.lock.yml @@ -107,6 +107,7 @@ jobs: ```json {"type": "create-pull-request", "branch": "branch-name", "title": "PR title", "body": "PR body in markdown", "labels": ["optional", "labels"]} ``` + 5. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-codex-mcp.lock.yml b/.github/workflows/test-codex-mcp.lock.yml index 197e5f92ff6..f5d971756df 100644 --- a/.github/workflows/test-codex-mcp.lock.yml +++ b/.github/workflows/test-codex-mcp.lock.yml @@ -284,9 +284,13 @@ jobs: ### Available Output Types: **Creating an Issue** + + To create an issue: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "create-issue", "title": "Issue title", "body": "Issue body in markdown", "labels": ["optional", "labels"]} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-codex-push-to-branch.lock.yml b/.github/workflows/test-codex-push-to-branch.lock.yml index 024df33bb1b..2d8440db84e 100644 --- a/.github/workflows/test-codex-push-to-branch.lock.yml +++ b/.github/workflows/test-codex-push-to-branch.lock.yml @@ -2,7 +2,7 @@ # To update this file, edit the corresponding .md file and run: # gh aw compile -name: "Codex Test File" +name: "Test Codex Push To Branch" on: issues: types: [opened, edited, reopened] @@ -18,7 +18,7 @@ permissions: {} concurrency: group: "gh-aw-${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number }}" -run-name: "Codex Test File" +run-name: "Test Codex Push To Branch" jobs: task: @@ -63,7 +63,7 @@ jobs: echo "User ${{ github.actor }} is not a team member" exit 1 - codex-test-file: + test-codex-push-to-branch: needs: task runs-on: ubuntu-latest permissions: read-all @@ -131,7 +131,7 @@ jobs: Create a new file called "codex-test-file.md" with the following content: ```markdown - # Codex Test File + # Test Codex Push To Branch This file was created by the Codex agentic workflow to test the push-to-branch functionality. @@ -185,13 +185,14 @@ jobs: **Pushing Changes to Branch** - To push changes to a branch: + To push changes to a branch, for example to add code to a pull request: 1. Make any file changes directly in the working directory 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. 3. Indicate your intention to push to the branch by writing to the file "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "push-to-branch", "message": "Commit message describing the changes"} ``` + 4. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` @@ -223,7 +224,7 @@ jobs: engine_name: "Codex", model: "", version: "", - workflow_name: "Codex Test File", + workflow_name: "Test Codex Push To Branch", experimental: true, supports_tools_whitelist: true, supports_http_transport: false, @@ -261,7 +262,7 @@ jobs: # Run codex with log capture codex exec \ -c model=o4-mini \ - --full-auto "$INSTRUCTION" 2>&1 | tee /tmp/codex-test-file.log + --full-auto "$INSTRUCTION" 2>&1 | tee /tmp/test-codex-push-to-branch.log env: GITHUB_AW_SAFE_OUTPUTS: ${{ env.GITHUB_AW_SAFE_OUTPUTS }} GITHUB_STEP_SUMMARY: ${{ env.GITHUB_STEP_SUMMARY }} @@ -651,7 +652,7 @@ jobs: if: always() uses: actions/github-script@v7 env: - AGENT_LOG_FILE: /tmp/codex-test-file.log + AGENT_LOG_FILE: /tmp/test-codex-push-to-branch.log with: script: | function main() { @@ -881,8 +882,8 @@ jobs: if: always() uses: actions/upload-artifact@v4 with: - name: codex-test-file.log - path: /tmp/codex-test-file.log + name: test-codex-push-to-branch.log + path: /tmp/test-codex-push-to-branch.log if-no-files-found: warn - name: Generate git patch if: always() @@ -1006,8 +1007,8 @@ jobs: if-no-files-found: ignore push_to_branch: - needs: codex-test-file - if: always() + needs: test-codex-push-to-branch + if: contains(github.event.issue.body, '/test-codex-push-to-branch') || contains(github.event.comment.body, '/test-codex-push-to-branch') || contains(github.event.pull_request.body, '/test-codex-push-to-branch') runs-on: ubuntu-latest permissions: contents: write @@ -1031,7 +1032,7 @@ jobs: id: push_to_branch uses: actions/github-script@v7 env: - GITHUB_AW_AGENT_OUTPUT: ${{ needs.codex-test-file.outputs.output }} + GITHUB_AW_AGENT_OUTPUT: ${{ needs.test-codex-push-to-branch.outputs.output }} GITHUB_AW_PUSH_BRANCH: "codex-test-branch" GITHUB_AW_PUSH_TARGET: "*" with: diff --git a/.github/workflows/test-codex-push-to-branch.md b/.github/workflows/test-codex-push-to-branch.md index 9929aa6e4d3..f18d9bfe164 100644 --- a/.github/workflows/test-codex-push-to-branch.md +++ b/.github/workflows/test-codex-push-to-branch.md @@ -15,7 +15,7 @@ safe-outputs: Create a new file called "codex-test-file.md" with the following content: ```markdown -# Codex Test File +# Test Codex Push To Branch This file was created by the Codex agentic workflow to test the push-to-branch functionality. diff --git a/.github/workflows/test-codex-update-issue.lock.yml b/.github/workflows/test-codex-update-issue.lock.yml index c41013ef32e..9e6c76fcbeb 100644 --- a/.github/workflows/test-codex-update-issue.lock.yml +++ b/.github/workflows/test-codex-update-issue.lock.yml @@ -269,9 +269,12 @@ jobs: ### Available Output Types: **Updating an Issue** + + To udpate an issue: ```json {"type": "update-issue", "status": "open" // or "closed", "title": "New issue title", "body": "Updated issue body in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/.github/workflows/test-proxy.lock.yml b/.github/workflows/test-proxy.lock.yml index de585f626a9..7862e2149da 100644 --- a/.github/workflows/test-proxy.lock.yml +++ b/.github/workflows/test-proxy.lock.yml @@ -260,9 +260,13 @@ jobs: ### Available Output Types: **Adding a Comment to an Issue or Pull Request** + + To add a comment to an issue or pull request: + 1. Write an entry to "${{ env.GITHUB_AW_SAFE_OUTPUTS }}": ```json {"type": "add-issue-comment", "body": "Your comment content in markdown"} ``` + 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up **Example JSONL file content:** ``` diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go index b5c0edbd805..f618b2235f7 100644 --- a/pkg/workflow/compiler.go +++ b/pkg/workflow/compiler.go @@ -1877,9 +1877,20 @@ func (c *Compiler) buildCreateOutputIssueJob(data *WorkflowData, mainJobName str "issue_url": "${{ steps.create_issue.outputs.issue_url }}", } + // Determine the job condition for command workflows + var jobCondition string + if data.Command != "" { + // Build the command trigger condition + commandCondition := buildCommandOnlyCondition(data.Command) + commandConditionStr := commandCondition.Render() + jobCondition = fmt.Sprintf("if: %s", commandConditionStr) + } else { + jobCondition = "" // No conditional execution + } + job := &Job{ Name: "create_issue", - If: "", // No conditional execution + If: jobCondition, RunsOn: "runs-on: ubuntu-latest", Permissions: "permissions:\n contents: read\n issues: write", TimeoutMinutes: 10, // 10-minute timeout as required @@ -1925,13 +1936,33 @@ func (c *Compiler) buildCreateOutputAddIssueCommentJob(data *WorkflowData, mainJ } // Determine the job condition based on target configuration - var jobCondition string + var baseCondition string if data.SafeOutputs.AddIssueComments.Target == "*" { // Allow the job to run in any context when target is "*" - jobCondition = "if: always()" // This allows the job to run even without triggering issue/PR + baseCondition = "always()" // This allows the job to run even without triggering issue/PR } else { // Default behavior: only run in issue or PR context - jobCondition = "if: github.event.issue.number || github.event.pull_request.number" + baseCondition = "github.event.issue.number || github.event.pull_request.number" + } + + // If this is a command workflow, combine the command trigger condition with the base condition + var jobCondition string + if data.Command != "" { + // Build the command trigger condition + commandCondition := buildCommandOnlyCondition(data.Command) + commandConditionStr := commandCondition.Render() + + // Combine command condition with base condition using AND + if baseCondition == "always()" { + // If base condition is always(), just use the command condition + jobCondition = fmt.Sprintf("if: %s", commandConditionStr) + } else { + // Combine both conditions with AND + jobCondition = fmt.Sprintf("if: (%s) && (%s)", commandConditionStr, baseCondition) + } + } else { + // No command trigger, just use the base condition + jobCondition = fmt.Sprintf("if: %s", baseCondition) } job := &Job{ @@ -2010,9 +2041,20 @@ func (c *Compiler) buildCreateOutputPullRequestJob(data *WorkflowData, mainJobNa "branch_name": "${{ steps.create_pull_request.outputs.branch_name }}", } + // Determine the job condition for command workflows + var jobCondition string + if data.Command != "" { + // Build the command trigger condition + commandCondition := buildCommandOnlyCondition(data.Command) + commandConditionStr := commandCondition.Render() + jobCondition = fmt.Sprintf("if: %s", commandConditionStr) + } else { + jobCondition = "" // No conditional execution + } + job := &Job{ Name: "create_pull_request", - If: "", // No conditional execution + If: jobCondition, RunsOn: "runs-on: ubuntu-latest", Permissions: "permissions:\n contents: write\n issues: write\n pull-requests: write", TimeoutMinutes: 10, // 10-minute timeout as required @@ -2456,17 +2498,25 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng if data.SafeOutputs.AddIssueComments != nil { yaml.WriteString(" **Adding a Comment to an Issue or Pull Request**\n") + yaml.WriteString(" \n") + yaml.WriteString(" To add a comment to an issue or pull request:\n") + yaml.WriteString(" 1. Write an entry to \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n") yaml.WriteString(" ```json\n") yaml.WriteString(" {\"type\": \"add-issue-comment\", \"body\": \"Your comment content in markdown\"}\n") yaml.WriteString(" ```\n") + yaml.WriteString(" 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up\n") yaml.WriteString(" \n") } if data.SafeOutputs.CreateIssues != nil { yaml.WriteString(" **Creating an Issue**\n") + yaml.WriteString(" \n") + yaml.WriteString(" To create an issue:\n") + yaml.WriteString(" 1. Write an entry to \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n") yaml.WriteString(" ```json\n") yaml.WriteString(" {\"type\": \"create-issue\", \"title\": \"Issue title\", \"body\": \"Issue body in markdown\", \"labels\": [\"optional\", \"labels\"]}\n") yaml.WriteString(" ```\n") + yaml.WriteString(" 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up\n") yaml.WriteString(" \n") } @@ -2481,19 +2531,26 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng 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") yaml.WriteString(" ```\n") + yaml.WriteString(" 5. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up\n") yaml.WriteString(" \n") } if data.SafeOutputs.AddIssueLabels != nil { yaml.WriteString(" **Adding Labels to Issues or Pull Requests**\n") + yaml.WriteString(" \n") + yaml.WriteString(" To add labels to a pull request:\n") + yaml.WriteString(" 1. Write an entry to \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n") yaml.WriteString(" ```json\n") yaml.WriteString(" {\"type\": \"add-issue-label\", \"labels\": [\"label1\", \"label2\", \"label3\"]}\n") yaml.WriteString(" ```\n") + yaml.WriteString(" 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up\n") yaml.WriteString(" \n") } if data.SafeOutputs.UpdateIssues != nil { yaml.WriteString(" **Updating an Issue**\n") + yaml.WriteString(" \n") + yaml.WriteString(" To udpate an issue:\n") yaml.WriteString(" ```json\n") // Build example based on allowed fields @@ -2519,19 +2576,21 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng } yaml.WriteString(" ```\n") + yaml.WriteString(" 2. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up\n") 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(" To push changes to a branch, for example to add code to a pull request:\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(" 4. After you write to that file, read it as JSONL and check it is valid. If it isn't, make any necessary corrections to it to fix it up\n") yaml.WriteString(" \n") } diff --git a/pkg/workflow/output_labels.go b/pkg/workflow/output_labels.go index ecfdb034a1e..5598665ae65 100644 --- a/pkg/workflow/output_labels.go +++ b/pkg/workflow/output_labels.go @@ -49,9 +49,23 @@ func (c *Compiler) buildCreateOutputLabelJob(data *WorkflowData, mainJobName str "labels_added": "${{ steps.add_labels.outputs.labels_added }}", } + // Determine the job condition for command workflows + var baseCondition = "github.event.issue.number || github.event.pull_request.number" // Only run in issue or PR context + var jobCondition string + if data.Command != "" { + // Build the command trigger condition + commandCondition := buildCommandOnlyCondition(data.Command) + commandConditionStr := commandCondition.Render() + // Combine command condition with base condition using AND + jobCondition = fmt.Sprintf("if: (%s) && (%s)", commandConditionStr, baseCondition) + } else { + // No command trigger, just use the base condition + jobCondition = fmt.Sprintf("if: %s", baseCondition) + } + job := &Job{ Name: "add_labels", - If: "if: github.event.issue.number || github.event.pull_request.number", // Only run in issue or PR context + If: jobCondition, RunsOn: "runs-on: ubuntu-latest", Permissions: "permissions:\n contents: read\n issues: write\n pull-requests: write", TimeoutMinutes: 10, // 10-minute timeout as required diff --git a/pkg/workflow/output_push_to_branch.go b/pkg/workflow/output_push_to_branch.go index 9775ee7de49..b4dc937264f 100644 --- a/pkg/workflow/output_push_to_branch.go +++ b/pkg/workflow/output_push_to_branch.go @@ -61,13 +61,33 @@ func (c *Compiler) buildCreateOutputPushToBranchJob(data *WorkflowData, mainJobN } // Determine the job condition based on target configuration - var jobCondition string + var baseCondition string if data.SafeOutputs.PushToBranch.Target == "*" { // Allow pushing to any pull request - no specific context required - jobCondition = "if: always()" + baseCondition = "always()" } else { // Default behavior: only run in pull request context - jobCondition = "if: github.event.pull_request.number" + baseCondition = "github.event.pull_request.number" + } + + // If this is a command workflow, combine the command trigger condition with the base condition + var jobCondition string + if data.Command != "" { + // Build the command trigger condition + commandCondition := buildCommandOnlyCondition(data.Command) + commandConditionStr := commandCondition.Render() + + // Combine command condition with base condition using AND + if baseCondition == "always()" { + // If base condition is always(), just use the command condition + jobCondition = fmt.Sprintf("if: %s", commandConditionStr) + } else { + // Combine both conditions with AND + jobCondition = fmt.Sprintf("if: (%s) && (%s)", commandConditionStr, baseCondition) + } + } else { + // No command trigger, just use the base condition + jobCondition = fmt.Sprintf("if: %s", baseCondition) } job := &Job{ diff --git a/pkg/workflow/output_update_issue.go b/pkg/workflow/output_update_issue.go index 8f356a38daf..2e4ab6cb35b 100644 --- a/pkg/workflow/output_update_issue.go +++ b/pkg/workflow/output_update_issue.go @@ -44,16 +44,36 @@ func (c *Compiler) buildCreateOutputUpdateIssueJob(data *WorkflowData, mainJobNa } // Determine the job condition based on target configuration - var jobCondition string + var baseCondition string if data.SafeOutputs.UpdateIssues.Target == "*" { // Allow updates to any issue - no specific context required - jobCondition = "if: always()" + baseCondition = "always()" } else if data.SafeOutputs.UpdateIssues.Target != "" { // Explicit issue number specified - no specific context required - jobCondition = "if: always()" + baseCondition = "always()" } else { // Default behavior: only update triggering issue - jobCondition = "if: github.event.issue.number" + baseCondition = "github.event.issue.number" + } + + // If this is a command workflow, combine the command trigger condition with the base condition + var jobCondition string + if data.Command != "" { + // Build the command trigger condition + commandCondition := buildCommandOnlyCondition(data.Command) + commandConditionStr := commandCondition.Render() + + // Combine command condition with base condition using AND + if baseCondition == "always()" { + // If base condition is always(), just use the command condition + jobCondition = fmt.Sprintf("if: %s", commandConditionStr) + } else { + // Combine both conditions with AND + jobCondition = fmt.Sprintf("if: (%s) && (%s)", commandConditionStr, baseCondition) + } + } else { + // No command trigger, just use the base condition + jobCondition = fmt.Sprintf("if: %s", baseCondition) } job := &Job{