Skip to content

Commit 9bea83d

Browse files
furedea-agent[bot]furedeaclaude
authored
ci: add the codex-review reusable workflow (#8)
## 概要 App が開いた PR も Codex にサブスクの枠でレビューさせる reusable workflow `codex-review.yml` を追加します.CI がオーナーの PAT で `@codex review` とコメントし,Codex の `codex-review-state` を読んで判定します.この PR 自身が実験台です(App が開いた PR で,自身の CI が新しい workflow を呼ぶ). | Codex の結果(HEAD の commit) | 判定 | | ------------------------------ | ---- | | 未解決の指摘なし | 成功 | | 未解決の指摘あり | 失敗 | | Codex が失敗(枠切れなど) | 失敗 | | 20 分以内に結果なし | 失敗 | ## 確認 - [x] actionlint - [ ] この PR で,App が開いた PR に対し CI の `@codex review` から Codex のレビューが走る - [ ] 追加の push で再レビューが走り,判定が新しい HEAD の結果で決まる - [ ] Codex の利用枠の減り方を確認する Refs #7 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent fc0cba9 commit 9bea83d

4 files changed

Lines changed: 134 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ jobs:
5050
secrets:
5151
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
5252

53+
codex-review:
54+
uses: ./.github/workflows/codex-review.yml
55+
permissions: {}
56+
secrets:
57+
codex_review_token: ${{ secrets.CODEX_REVIEW_TOKEN }}
58+
5359
all-green:
5460
if: always()
55-
needs: [nix-lint, claude-review]
61+
needs:
62+
- nix-lint
63+
- claude-review
64+
- codex-review
5665
runs-on: ubuntu-latest
5766
timeout-minutes: 1
5867
permissions: {}

‎.github/workflows/codex-review.yml‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Codex review (reusable)
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
codex_review_token:
7+
description: >-
8+
Fine-grained token of the repository owner (Pull requests: read and write).
9+
Codex ignores review requests from bots, so the request is posted as the owner.
10+
required: true
11+
12+
permissions: {}
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
18+
concurrency:
19+
group: codex-review-${{ github.repository }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
should-review:
24+
name: Decide whether to review
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 1
27+
permissions: {}
28+
# Same rule as claude-review: same-repository pull requests that a human or furedea-agent opened.
29+
# This job always succeeds so the caller job is never reported as skipped.
30+
outputs:
31+
run: >-
32+
${{ github.event_name == 'pull_request'
33+
&& github.event.pull_request.head.repo.full_name == github.repository
34+
&& (github.event.pull_request.user.type != 'Bot'
35+
|| github.event.pull_request.user.login == 'furedea-agent[bot]') }}
36+
steps:
37+
- name: No-op
38+
run: "true"
39+
40+
review:
41+
name: Codex review
42+
needs: should-review
43+
if: needs.should-review.outputs.run == 'true'
44+
runs-on: ubuntu-latest
45+
timeout-minutes: 25
46+
permissions: {}
47+
env:
48+
GH_TOKEN: ${{ secrets.codex_review_token }}
49+
REPO: ${{ github.repository }}
50+
PR_NUMBER: ${{ github.event.pull_request.number }}
51+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
52+
steps:
53+
- name: Request a review
54+
id: request
55+
run: |
56+
echo "requested_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >>"$GITHUB_OUTPUT"
57+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "@codex review"
58+
59+
# Codex keeps one summary comment per pull request and records its state in
60+
# <!-- codex-review-state:v1 {...} -->. Wait until that comment is updated after this
61+
# request (so a re-run never reads an old verdict) and its state is for HEAD_SHA.
62+
# A failed API call is retried on the next poll instead of ending the wait.
63+
- name: Wait for the review of the head commit
64+
id: wait
65+
env:
66+
REQUESTED_AT: ${{ steps.request.outputs.requested_at }}
67+
run: |
68+
deadline=$((SECONDS + 20 * 60))
69+
while ((SECONDS < deadline)); do
70+
state="$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" --paginate \
71+
--jq '.[] | select(.user.login == "chatgpt-codex-connector[bot]" and .updated_at >= env.REQUESTED_AT) | .body' \
72+
| sed -n 's/.*<!-- codex-review-state:v1 \(.*\) -->.*/\1/p' | tail -n 1)" || state=""
73+
sha="$(jq -r '.code_review.commit_sha // empty' <<<"$state" 2>/dev/null || true)"
74+
status="$(jq -r '.code_review.status // empty' <<<"$state" 2>/dev/null || true)"
75+
if [[ "$sha" == "$HEAD_SHA" && ( "$status" == "completed" || "$status" == "failed" ) ]]; then
76+
echo "status=$status" >>"$GITHUB_OUTPUT"
77+
echo "unresolved=$(jq -r '.code_review.has_unresolved_findings' <<<"$state")" >>"$GITHUB_OUTPUT"
78+
exit 0
79+
fi
80+
sleep 30
81+
done
82+
echo "status=timeout" >>"$GITHUB_OUTPUT"
83+
84+
- name: Fail unless the review passed
85+
if: always()
86+
env:
87+
STATUS: ${{ steps.wait.outputs.status }}
88+
UNRESOLVED: ${{ steps.wait.outputs.unresolved }}
89+
run: |
90+
case "$STATUS:$UNRESOLVED" in
91+
completed:false) echo "Codex review of $HEAD_SHA: no unresolved findings." >>"$GITHUB_STEP_SUMMARY" ;;
92+
completed:*) message="Codex left unresolved findings on $HEAD_SHA. Fix them, or resolve a refuted one with evidence in its thread." ;;
93+
failed:*) message="Codex could not review $HEAD_SHA (for example, usage limits). Read its summary comment on the pull request." ;;
94+
*) message="Codex did not review $HEAD_SHA within 20 minutes. Check the Codex connector settings and that the token is valid (\`repo review-token rotate\`)." ;;
95+
esac
96+
if [[ -n "${message:-}" ]]; then
97+
echo "$message" >>"$GITHUB_STEP_SUMMARY"
98+
echo "::error::$message"
99+
exit 1
100+
fi

‎.ls-lint.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ls:
44
.*: regex:[a-z0-9]*([._][a-z0-9]+)*
55
.github:
66
workflows:
7-
.yml: regex:[a-z0-9]*([._][a-z0-9]+)* | regex:claude-review
7+
.yml: regex:[a-z0-9]*([._][a-z0-9]+)* | regex:(claude|codex)-review
88

99
ignore:
1010
- .git

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,26 @@ jobs:
3535
```
3636
3737
The caller needs the repository secret `CLAUDE_CODE_OAUTH_TOKEN`.
38+
39+
## codex-review.yml
40+
41+
Asks the Codex GitHub connector to review every same-repository pull request, on open and on every push, and
42+
waits for its result. Codex ignores review requests from bots and charges repository-wide automatic reviews to
43+
credits, so the workflow posts `@codex review` with the repository owner's token; the review then runs on the
44+
owner's ChatGPT plan. The job reads the `codex-review-state` that Codex records in its summary comment and
45+
fails when the review of the head commit has unresolved findings, when Codex reports a failure (for example
46+
usage limits), or when no review arrives within 20 minutes. It skips the same pull requests as
47+
`claude-review.yml`.
48+
49+
```yaml
50+
jobs:
51+
codex-review:
52+
uses: furedea/reusable-workflows/.github/workflows/codex-review.yml@<full-commit-sha> # <ref>
53+
permissions: {}
54+
secrets:
55+
codex_review_token: ${{ secrets.CODEX_REVIEW_TOKEN }}
56+
```
57+
58+
Add `codex-review` to `all-green`'s `needs`. The caller needs the repository secret `CODEX_REVIEW_TOKEN`: a
59+
fine-grained token of the owner with only Pull requests read and write. In the Codex settings, keep the
60+
repository's automatic review on "Follow personal preferences".

0 commit comments

Comments
 (0)