Skip to content

Commit 086d91d

Browse files
committed
feat(ci): Refactor gemini review into a reusable workflow
This refactors the gemini review into a reusable workflow that can be called from other workflows. This also updates the .gitignore to ignore gemini-related files. Signed-off-by: Brad P. Crochet <brad@redhat.com>
1 parent d8d9f10 commit 086d91d

File tree

3 files changed

+137
-20
lines changed

3 files changed

+137
-20
lines changed

.github/workflows/code-review.yml

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
runs-on: ubuntu-latest
2424
outputs:
2525
should_run_review: ${{ steps.prep.outputs.should_run_review }}
26+
# For future use
27+
additional_context: ""
2628
permissions:
2729
pull-requests: write
2830
steps:
@@ -54,26 +56,16 @@ jobs:
5456
fi
5557
5658
gemini-code-review:
57-
runs-on: ubuntu-latest
5859
needs: [handle-label]
5960
if: needs.handle-label.outputs.should_run_review == 'true'
60-
steps:
61-
- name: Checkout repository
62-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
63-
with:
64-
ref: refs/pull/${{ github.event.pull_request.number }}/merge
65-
persist-credentials: false
66-
fetch-depth: 0
61+
uses: './.github/workflows/gemini-review.yml'
62+
permissions:
63+
contents: 'read'
64+
id-token: 'write'
65+
issues: 'write'
66+
pull-requests: 'write'
67+
with:
68+
additional_context: '${{ needs.handle-label.outputs.additional_context }}'
69+
secrets:
70+
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'
6771

68-
- name: Gemini AI Code Review
69-
uses: sshnaidm/gemini-code-review-action@d4ccdaf0e2cad5cb79f80f6db07857c0e7fff28f # v1
70-
with:
71-
gemini-key: ${{ secrets.GEMINI_API_KEY }}
72-
model: 'gemini-2.5-flash'
73-
prompt: |
74-
Please review this code with focus on:
75-
- Security vulnerabilities
76-
- Adherence to best practices
77-
- Performance optimizations
78-
- Idiomatic Go
79-
Provide specific feedback and suggestions for improvement.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: '🔎 Gemini Review'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
additional_context:
7+
type: 'string'
8+
description: 'Any additional context from the request'
9+
required: false
10+
secrets:
11+
GEMINI_API_KEY:
12+
description: 'Gemini API Key'
13+
required: true
14+
GOOGLE_API_KEY:
15+
description: 'Google API Key'
16+
required: false
17+
APP_PRIVATE_KEY:
18+
description: 'Mint identity private key'
19+
required: false
20+
21+
concurrency:
22+
group: '${{ github.workflow }}-review-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number }}'
23+
cancel-in-progress: true
24+
25+
defaults:
26+
run:
27+
shell: 'bash'
28+
29+
jobs:
30+
review:
31+
runs-on: 'ubuntu-latest'
32+
timeout-minutes: 7
33+
permissions:
34+
contents: 'read'
35+
id-token: 'write'
36+
issues: 'write'
37+
pull-requests: 'write'
38+
steps:
39+
- name: 'Mint identity token'
40+
id: 'mint_identity_token'
41+
if: |-
42+
${{ vars.APP_ID }}
43+
uses: 'actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf' # ratchet:actions/create-github-app-token@v2
44+
with:
45+
app-id: '${{ vars.APP_ID }}'
46+
private-key: '${{ secrets.APP_PRIVATE_KEY }}'
47+
permission-contents: 'read'
48+
permission-issues: 'write'
49+
permission-pull-requests: 'write'
50+
51+
- name: 'Checkout repository'
52+
uses: 'actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8' # ratchet:actions/checkout@v6
53+
with:
54+
persist-credentials: false
55+
56+
- name: 'Run Gemini pull request review'
57+
uses: 'google-github-actions/run-gemini-cli@5a3b23c898e09c9a9d00e75f7725e83ed603884d' # v0.1.19
58+
id: 'gemini_pr_review'
59+
env:
60+
GITHUB_TOKEN: '${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}'
61+
ISSUE_TITLE: '${{ github.event.pull_request.title || github.event.issue.title }}'
62+
ISSUE_BODY: '${{ github.event.pull_request.body || github.event.issue.body }}'
63+
PULL_REQUEST_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number }}'
64+
REPOSITORY: '${{ github.repository }}'
65+
ADDITIONAL_CONTEXT: '${{ inputs.additional_context }}'
66+
with:
67+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
68+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
69+
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
70+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
71+
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
72+
gemini_cli_version: '${{ vars.GEMINI_CLI_VERSION }}'
73+
gemini_debug: '${{ fromJSON(vars.GEMINI_DEBUG || vars.ACTIONS_STEP_DEBUG || false) }}'
74+
gemini_model: '${{ vars.GEMINI_MODEL }}'
75+
google_api_key: '${{ secrets.GOOGLE_API_KEY }}'
76+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
77+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
78+
upload_artifacts: '${{ vars.UPLOAD_ARTIFACTS }}'
79+
workflow_name: 'gemini-review'
80+
settings: |-
81+
{
82+
"model": {
83+
"maxSessionTurns": 25
84+
},
85+
"telemetry": {
86+
"enabled": true,
87+
"target": "local",
88+
"outfile": ".gemini/telemetry.log"
89+
},
90+
"mcpServers": {
91+
"github": {
92+
"command": "docker",
93+
"args": [
94+
"run",
95+
"-i",
96+
"--rm",
97+
"-e",
98+
"GITHUB_PERSONAL_ACCESS_TOKEN",
99+
"ghcr.io/github/github-mcp-server:v0.27.0"
100+
],
101+
"includeTools": [
102+
"add_comment_to_pending_review",
103+
"pull_request_read",
104+
"pull_request_review_write"
105+
],
106+
"env": {
107+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
108+
}
109+
}
110+
},
111+
"tools": {
112+
"core": [
113+
"run_shell_command(cat)",
114+
"run_shell_command(echo)",
115+
"run_shell_command(grep)",
116+
"run_shell_command(head)",
117+
"run_shell_command(tail)"
118+
]
119+
}
120+
}
121+
prompt: '/gemini-review'

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ e2e_test_artifacts/
6060

6161
# Vagrant
6262
.vagrant
63+
64+
# Gemini
65+
.gemini/
66+
gha-creds-*.json

0 commit comments

Comments
 (0)