diff --git a/.github/scripts/keepalive_loop.js b/.github/scripts/keepalive_loop.js index 61f5fab7d..fa3514b13 100644 --- a/.github/scripts/keepalive_loop.js +++ b/.github/scripts/keepalive_loop.js @@ -292,6 +292,7 @@ async function evaluateKeepaliveLoop({ github, context, core }) { return { prNumber, + prRef: pr.head.ref || '', action, reason, gateConclusion, diff --git a/.github/workflows/agents-keepalive-loop.yml b/.github/workflows/agents-keepalive-loop.yml index 2c605ab45..0f623f55f 100644 --- a/.github/workflows/agents-keepalive-loop.yml +++ b/.github/workflows/agents-keepalive-loop.yml @@ -24,6 +24,7 @@ jobs: environment: agent-standard outputs: pr_number: ${{ steps.evaluate.outputs.pr_number }} + pr_ref: ${{ steps.evaluate.outputs.pr_ref }} action: ${{ steps.evaluate.outputs.action }} reason: ${{ steps.evaluate.outputs.reason }} gate_conclusion: ${{ steps.evaluate.outputs.gate_conclusion }} @@ -103,6 +104,7 @@ jobs: const result = await evaluateKeepaliveLoop({ github, context, core }); const output = { pr_number: String(result.prNumber || ''), + pr_ref: String(result.prRef || ''), action: result.action || '', reason: result.reason || '', gate_conclusion: result.gateConclusion || '', @@ -169,6 +171,7 @@ jobs: prompt_file: .github/codex/prompts/keepalive_next_task.md mode: keepalive pr_number: ${{ needs.evaluate.outputs.pr_number }} + pr_ref: ${{ needs.evaluate.outputs.pr_ref }} summary: name: Update keepalive summary diff --git a/.github/workflows/reusable-codex-run.yml b/.github/workflows/reusable-codex-run.yml index 78ab16b13..3a46a236d 100644 --- a/.github/workflows/reusable-codex-run.yml +++ b/.github/workflows/reusable-codex-run.yml @@ -22,6 +22,11 @@ on: required: false default: '' type: string + pr_ref: + description: 'The branch/ref to checkout and push to (e.g., refs/heads/feature-branch).' + required: false + default: '' + type: string max_runtime_minutes: description: 'Upper bound for the job runtime in minutes.' required: false @@ -138,6 +143,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ inputs.pr_ref || github.ref }} token: ${{ steps.auth_token.outputs.checkout_token }} - name: Set up Python @@ -308,6 +314,7 @@ jobs: env: MODE: ${{ inputs.mode }} PR_NUMBER: ${{ inputs.pr_number }} + PR_REF: ${{ inputs.pr_ref }} PUSH_ALLOWED: ${{ steps.auth_token.outputs.push_allowed }} PUSH_TOKEN: ${{ steps.auth_token.outputs.push_token }} run: | @@ -315,6 +322,12 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + # Determine the target branch + TARGET_REF="${PR_REF:-${{ github.ref_name }}}" + # Strip refs/heads/ prefix if present + TARGET_BRANCH="${TARGET_REF#refs/heads/}" + echo "Target branch: ${TARGET_BRANCH}" + # Count changed files CHANGED_FILES=$(git status --porcelain | wc -l) echo "files-changed=${CHANGED_FILES}" >> "$GITHUB_OUTPUT" @@ -347,7 +360,7 @@ jobs: COMMIT_SHA=$(git rev-parse HEAD) echo "commit-sha=${COMMIT_SHA}" >> "$GITHUB_OUTPUT" - git push "https://x-access-token:${PUSH_TOKEN}@github.com/${{ github.repository }}" "HEAD:${{ github.ref_name }}" + git push "https://x-access-token:${PUSH_TOKEN}@github.com/${{ github.repository }}" "HEAD:${TARGET_BRANCH}" echo "::notice::Pushed commit ${COMMIT_SHA} with ${CHANGED_FILES} file(s) changed"