Skip to content
Open
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
86 changes: 84 additions & 2 deletions .github/workflows/reusable-workflow-ci-ai-agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,48 @@ on:
description: "LLM model to use for general purpose tasks"
required: false
type: string
codex_model:
description: "OpenAI model to use for Codex agent"
required: false
type: string
default: "o3"

jobs:
run-ci-ai-agent:
detect-agent:
if: |
inputs.event_name == 'issues' ||
inputs.event_name == 'issue_comment' ||
inputs.event_name == 'pull_request_review_comment' ||
inputs.event_name == 'pull_request_review'
runs-on: gha-production-medium
outputs:
agent: ${{ steps.parse.outputs.agent }}
codex_prompt: ${{ steps.parse.outputs.codex_prompt }}
steps:
- name: Parse agent from comment
id: parse
shell: bash
env:
EVENT_PAYLOAD: ${{ inputs.event_payload }}
run: |
comment=$(echo "$EVENT_PAYLOAD" | jq -r '.comment.body // .review.body // .issue.body // ""')
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jq expression '.comment.body // .review.body // .issue.body' may not extract the correct content for all event types. For issue_comment events on pull requests, the comment body is correct, but for issues events, you should check both issue.body and issue.title (as done in the trigger condition on line 19). The current implementation doesn't check issue.title, which means /codex- commands in issue titles won't be detected by this parsing logic.

Copilot uses AI. Check for mistakes.

if echo "$comment" | grep -q '/codex-'; then
echo "agent=codex" >> $GITHUB_OUTPUT
# Extract the command after /codex- (e.g., "review-pr" from "/codex-review-pr")
codex_cmd=$(echo "$comment" | grep -oE '/codex-[^ ]+' | head -1 | sed 's|/codex-||')
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern '/codex-[^ ]+' will only match up to the first space character, which means commands with spaces (e.g., "/codex-review this file") will truncate after "review" and lose important context. The grep pattern should be reconsidered to handle multi-word prompts properly, or the command format should be clearly documented to exclude spaces from the command portion.

Copilot uses AI. Check for mistakes.
# Extract any additional context after the command on the same line or following lines
full_prompt=$(echo "$comment" | sed -n '/\/codex-/,$p' | sed '1s|.*/codex-[^ ]*||')
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prompt extraction logic using nested sed commands is complex and difficult to understand. The expression 'sed -n '//codex-/,$p' | sed '1s|./codex-[^ ]||'' attempts to extract text after the codex command, but the logic is fragile and may produce unexpected results with different input formats. Consider simplifying this logic or adding inline comments to explain the expected behavior and edge cases.

Copilot uses AI. Check for mistakes.
echo "codex_prompt=${codex_cmd}${full_prompt}" >> $GITHUB_OUTPUT
else
echo "agent=claude" >> $GITHUB_OUTPUT
echo "codex_prompt=" >> $GITHUB_OUTPUT
fi

run-claude-agent:
needs: detect-agent
if: needs.detect-agent.outputs.agent == 'claude'
runs-on: gha-production-medium
container: ci-images-release.arti.tw.ee/actions_java_17_and_21
permissions:
contents: write
Expand Down Expand Up @@ -107,4 +140,53 @@ jobs:
${{ secrets.ANTHROPIC_BEDROCK_BASE_URL }}
claude_args: |
--allowedTools "mcp__github_inline_comment__create_inline_comment,mcp__github_file_ops__commit_files,mcp__github_file_ops__delete_files"
--model ${{ inputs.generic_model != '' && inputs.generic_model || vars.ANTHROPIC_DEFAULT_HAIKU_MODEL }}
--model ${{ inputs.generic_model != '' && inputs.generic_model || vars.ANTHROPIC_DEFAULT_HAIKU_MODEL }}

run-codex-agent:
needs: detect-agent
if: needs.detect-agent.outputs.agent == 'codex'
runs-on: gha-production-medium
# container: ci-images-release.arti.tw.ee/actions_java_17_and_21
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 1

- name: "Add repo as safe directory"
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Sync caller event context
shell: bash
env:
CALLER_EVENT_PAYLOAD: ${{ inputs.event_payload }}
run: |
event_file="$RUNNER_TEMP/original_event.json"
printf '%s' "$CALLER_EVENT_PAYLOAD" > "$event_file"
{
echo "GITHUB_EVENT_PATH=$event_file"
echo "GITHUB_EVENT_NAME=${{ inputs.event_name }}"
echo "GITHUB_REPOSITORY=${{ inputs.repository }}"
echo "GITHUB_REF=${{ inputs.ref }}"
echo "GITHUB_SHA=${{ inputs.sha }}"
echo "GITHUB_ACTOR=${{ inputs.actor }}"
} >> "$GITHUB_ENV"

- name: Run Codex Agent
uses: transferwise/[email protected]
env:
GITHUB_API_URL: https://eu.api.openai.com
with:
prompt: ${{ needs.detect-agent.outputs.codex_prompt }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
model: ${{ inputs.codex_model }}
sandbox: "workspace-write"
allow-users: "*"
safety-strategy: "unsafe"
8 changes: 4 additions & 4 deletions workflow-templates/call-ci-ai-agents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ on:
jobs:
call-ci-ai-agents:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '/run-ci-ai-agents')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '/run-ci-ai-agents')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '/run-ci-ai-agents')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '/run-ci-ai-agents') || contains(github.event.issue.title, '/run-ci-ai-agents')))
(github.event_name == 'issue_comment' && (contains(github.event.comment.body, '/run-ci-ai-agents') || contains(github.event.comment.body, '/codex-'))) ||
(github.event_name == 'pull_request_review_comment' && (contains(github.event.comment.body, '/run-ci-ai-agents') || contains(github.event.comment.body, '/codex-'))) ||
(github.event_name == 'pull_request_review' && (contains(github.event.review.body, '/run-ci-ai-agents') || contains(github.event.review.body, '/codex-'))) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '/run-ci-ai-agents') || contains(github.event.issue.title, '/run-ci-ai-agents') || contains(github.event.issue.body, '/codex-') || contains(github.event.issue.title, '/codex-')))
uses: transferwise/.github/.github/workflows/reusable-workflow-ci-ai-agents.yaml@master
secrets: inherit
with:
Expand Down