codex-pr-review.yml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. name: Codex PR Review
  2. on:
  3. pull_request_target:
  4. types: [opened, ready_for_review]
  5. jobs:
  6. pr-review:
  7. # 仅对有写入权限的用户运行,且跳过 draft PR 和 bot
  8. if: |
  9. (github.event.pull_request.author_association == 'OWNER' ||
  10. github.event.pull_request.author_association == 'MEMBER' ||
  11. github.event.pull_request.author_association == 'CONTRIBUTOR' ||
  12. github.event.pull_request.author_association == 'COLLABORATOR') &&
  13. github.event.pull_request.draft == false &&
  14. !endsWith(github.actor, '[bot]')
  15. runs-on: ubuntu-latest
  16. concurrency:
  17. group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  18. cancel-in-progress: false
  19. permissions:
  20. contents: read
  21. pull-requests: write
  22. outputs:
  23. review_result: ${{ steps.run_codex.outputs.final-message }}
  24. steps:
  25. - name: Checkout repository
  26. uses: actions/checkout@v5
  27. with:
  28. ref: refs/pull/${{ github.event.pull_request.number }}/merge
  29. fetch-depth: 0
  30. - name: Pre-fetch base and head refs
  31. run: |
  32. git fetch --no-tags origin \
  33. ${{ github.event.pull_request.base.ref }} \
  34. +refs/pull/${{ github.event.pull_request.number }}/head
  35. - name: Run Codex for Comprehensive PR Review
  36. id: run_codex
  37. uses: openai/codex-action@v1
  38. env:
  39. GH_TOKEN: ${{ github.token }}
  40. GITHUB_TOKEN: ${{ github.token }}
  41. with:
  42. openai-api-key: ${{ secrets.OPENAI_API_KEY }}
  43. responses-api-endpoint: ${{ secrets.OPENAI_BASE_URL }}
  44. model: ${{ vars.OPENAI_MODEL || 'gpt-5.2' }}
  45. effort: ${{ vars.OPENAI_EFFORT || 'xhigh' }}
  46. sandbox: danger-full-access
  47. safety-strategy: drop-sudo
  48. prompt-file: .github/prompts/codex-pr-review.md
  49. post-review:
  50. runs-on: ubuntu-latest
  51. needs: pr-review
  52. if: needs.pr-review.outputs.review_result != ''
  53. permissions:
  54. pull-requests: write
  55. steps:
  56. - name: Post Review Comment
  57. uses: actions/github-script@v7
  58. env:
  59. REVIEW_RESULT: ${{ needs.pr-review.outputs.review_result }}
  60. with:
  61. github-token: ${{ secrets.GITHUB_TOKEN }}
  62. script: |
  63. const body = process.env.REVIEW_RESULT;
  64. if (body && body.trim()) {
  65. await github.rest.pulls.createReview({
  66. owner: context.repo.owner,
  67. repo: context.repo.repo,
  68. pull_number: context.payload.pull_request.number,
  69. body: body,
  70. event: 'COMMENT'
  71. });
  72. }