💬 Gemini CLI #986
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: '💬 Gemini CLI' | |
| on: | |
| pull_request_review_comment: | |
| types: | |
| - 'created' | |
| pull_request_review: | |
| types: | |
| - 'submitted' | |
| issue_comment: | |
| types: | |
| - 'created' | |
| concurrency: | |
| group: '${{ github.workflow }}-${{ github.event.issue.number }}' | |
| cancel-in-progress: |- | |
| ${{ github.event.sender.type == 'User' && ( github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'MEMBER' || github.event.issue.author_association == 'COLLABORATOR') }} | |
| defaults: | |
| run: | |
| shell: 'bash' | |
| permissions: | |
| contents: 'write' | |
| pull-requests: 'write' | |
| issues: 'write' | |
| jobs: | |
| gemini-cli: | |
| # This condition seeks to ensure the action is only run when it is triggered by a trusted user. | |
| # For private repos, users who have access to the repo are considered trusted. | |
| # For public repos, users who members, owners, or collaborators are considered trusted. | |
| if: |- | |
| ( | |
| github.event_name == 'issues' && github.event.action == 'opened' && | |
| contains(github.event.issue.body, '@gemini-cli') && | |
| !contains(github.event.issue.body, '@gemini-cli /review') && | |
| !contains(github.event.issue.body, '@gemini-cli /triage') && | |
| ( | |
| github.event.repository.private == true || | |
| contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.issue.author_association) | |
| ) | |
| ) || | |
| ( | |
| ( | |
| github.event_name == 'issue_comment' || | |
| github.event_name == 'pull_request_review_comment' | |
| ) && | |
| contains(github.event.comment.body, '@gemini-cli') && | |
| !contains(github.event.comment.body, '@gemini-cli /review') && | |
| !contains(github.event.comment.body, '@gemini-cli /triage') && | |
| ( | |
| github.event.repository.private == true || | |
| contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) | |
| ) | |
| ) || | |
| ( | |
| github.event_name == 'pull_request_review' && | |
| contains(github.event.review.body, '@gemini-cli') && | |
| !contains(github.event.review.body, '@gemini-cli /review') && | |
| !contains(github.event.review.body, '@gemini-cli /triage') && | |
| ( | |
| github.event.repository.private == true || | |
| contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.review.author_association) | |
| ) | |
| ) | |
| timeout-minutes: 10 | |
| runs-on: 'ubuntu-latest' | |
| steps: | |
| # Mint a token so that the comments show up as gemini-cli instead of | |
| # github-actions. | |
| - name: 'Generate GitHub App Token' | |
| id: 'generate_token' | |
| if: |- | |
| ${{ vars.APP_ID }} | |
| uses: 'actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e' # ratchet:actions/create-github-app-token@v2 | |
| with: | |
| app-id: '${{ vars.APP_ID }}' | |
| private-key: '${{ secrets.APP_PRIVATE_KEY }}' | |
| # Tell the user that we're working on their request. | |
| - name: 'Acknowledge request' | |
| env: | |
| GITHUB_TOKEN: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}' | |
| ISSUE_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number }}' | |
| MESSAGE: |- | |
| 🤖 Hi @${{ github.actor }} - I am working on your request now! | |
| REPOSITORY: '${{ github.repository }}' | |
| run: |- | |
| gh issue comment "${ISSUE_NUMBER}" \ | |
| --body "${MESSAGE}" \ | |
| --repo "${REPOSITORY}" | |
| # Check out the SHA that corresponds to the event for when the issue | |
| # fired. This protects against attacks where new commits are pushed | |
| # between when a maintainer approved running the workflows and when the | |
| # workflow actually starts. | |
| - name: 'Checkout pull request' | |
| uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 | |
| with: | |
| ref: '${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.head.sha || github.sha }}' | |
| # In case the Gemini CLI needs to make commits to the repo, configure it's | |
| # identity. | |
| - name: 'Set up git user for commits' | |
| run: |- | |
| git config --global user.name 'gemini-cli[bot]' | |
| git config --global user.email 'gemini-cli[bot]@users.noreply.github.com' | |
| - name: 'Run Gemini' | |
| id: 'run_gemini' | |
| uses: './' | |
| env: | |
| DESCRIPTION: '${{ github.event.pull_request.body || github.event.issue.body }}' | |
| EVENT_NAME: '${{ github.event_name }}' | |
| GITHUB_TOKEN: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}' | |
| IS_PULL_REQUEST: '${{ !!github.event.pull_request }}' | |
| ISSUE_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number }}' | |
| REPOSITORY: '${{ github.repository }}' | |
| USER_REQUEST: '${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}' | |
| with: | |
| gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' | |
| gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}' | |
| gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}' | |
| gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}' | |
| gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' | |
| use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' | |
| use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' | |
| settings: |- | |
| { | |
| "debug": ${{ fromJSON(env.DEBUG || env.ACTIONS_STEP_DEBUG || false) }}, | |
| "maxSessionTurns": 50, | |
| "telemetry": { | |
| "enabled": true, | |
| "target": "gcp" | |
| } | |
| } | |
| prompt: |- | |
| ## Role | |
| You are a helpful AI assistant invoked via a CLI interface in a GitHub workflow. You have access to tools to interact with the repository and respond to the user. | |
| ## Steps | |
| Start by running these commands to gather the required data and context: | |
| 1. Run: echo "${DESCRIPTION}" to get a description of the pull request or issue | |
| 2. Run: echo "${EVENT_NAME}" to learn what kind of GitHub event triggered this request | |
| 3. Run: echo "${IS_PULL_REQUEST}" to learn whether this is a Pull Request (PR) or Issue | |
| 4. Run: echo "${ISSUE_NUMBER}" to get the PR or Issue number | |
| 5. Run: echo "${REPOSITORY}" to get the github repository in <OWNER>/<REPO> format | |
| 6. Run: echo "${USER_REQUEST}" to get the user's request | |
| ## How to Respond to Issues, PR Comments, and Questions | |
| This workflow supports three main scenarios: | |
| 1. **Creating a Fix for an Issue** | |
| - Carefully read the user request and the related issue or PR description. | |
| - Use available tools to gather all relevant context (e.g., `gh issue view`, `gh issue comments list` `gh pr diff`, `cat`, `head`, `tail`). | |
| - Identify the root cause of the problem before proceeding. | |
| - **Show and maintain a plan as a checklist**: | |
| - At the very beginning, outline the steps needed to resolve the issue or address the request and post them as a checklist comment on the issue or PR (use GitHub markdown checkboxes: `- [ ] Task`). | |
| - Example: | |
| ``` | |
| ### Plan | |
| - [ ] Investigate the root cause | |
| - [ ] Implement the fix in `file.py` | |
| - [ ] Add/modify tests | |
| - [ ] Update documentation | |
| - [ ] Verify the fix and close the issue | |
| ``` | |
| - Use: `gh issue comment "${ISSUE_NUMBER}" --body "<plan>"` to post the initial plan. | |
| - As you make progress, keep the checklist visible and up to date by editing the same comment (check off completed tasks with `- [x]`). | |
| - To update the checklist: | |
| 1. Find the comment ID for the checklist: `gh issue comment list "${ISSUE_NUMBER}"` | |
| 2. Edit the comment with the updated checklist: `gh issue comment --edit "<comment-id>" --body "<updated plan>"` | |
| 3. The checklist should only be maintained as a comment on the issue or PR. Do not track or update the checklist in code files. | |
| - If the fix requires code changes, determine which files and lines are affected. If clarification is needed, note any questions for the user. | |
| - Make the necessary code or documentation changes using the available tools (e.g., `write_file`). Ensure all changes follow project conventions and best practices. Reference all shell variables as `"${VAR}"` (with quotes and braces) to prevent errors. | |
| - Run any relevant tests or checks to verify the fix works as intended. If possible, provide evidence (test output, screenshots, etc.) that the issue is resolved. | |
| - **Branching and Committing**: | |
| - **NEVER commit directly to the `main` branch.** | |
| - If you are working on a **pull request** (`IS_PULL_REQUEST` is `true`), the correct branch is already checked out. Simply commit and push to it. | |
| - `git add .` | |
| - `git commit -m "feat: <describe the change>"` | |
| - `git push` | |
| - If you are working on an **issue** (`IS_PULL_REQUEST` is `false`), create a new branch for your changes. The branch name should be `gemini/fix-${ISSUE_NUMBER}`. | |
| - `git checkout -b "gemini/fix-${ISSUE_NUMBER}"` | |
| - `git add .` | |
| - `git commit -m "feat: <describe the fix>"` | |
| - `git push origin "gemini/fix-${ISSUE_NUMBER}"` | |
| - After pushing, create a pull request: `gh pr create --title "Fixes #${ISSUE_NUMBER}: <short title>" --body "This PR addresses issue #${ISSUE_NUMBER}."` | |
| - Summarize what was changed and why in `response.md` in markdown format and post it as a comment: `gh issue comment "${ISSUE_NUMBER}" --body-file "response.md"` | |
| 2. **Addressing Comments on a Pull Request** | |
| - Read the specific description and context. | |
| - Use tools like `gh pr diff` and `cat` to understand the code and discussion. | |
| - If the description requests a change or clarification, follow the same process as for fixing an issue: create a checklist plan, implement, test, and commit any required changes, updating the checklist as you go. | |
| - **Committing Changes**: The correct PR branch is already checked out. Simply add, commit, and push your changes. | |
| - `git add .` | |
| - `git commit -m "fix: address review comments"` | |
| - `git push` | |
| - If the description is a question, answer it directly and clearly, referencing code or documentation as needed. | |
| - Document your response in `response.md` in markdown format and post it as a comment: `gh issue comment "${ISSUE_NUMBER}" --body-file "response.md"` | |
| 3. **Answering Any Question on an Issue** | |
| - Read the description and the full context. | |
| - Research or analyze the codebase as needed to provide an accurate answer. | |
| - If the question requires code or documentation changes, follow the fix process above, including creating and updating a checklist plan and **creating a new branch for your changes as described in section 1.** | |
| - Write a clear, concise answer in `response.md` in markdown format and post it as a comment: `gh issue comment "${ISSUE_NUMBER}" --body-file "response.md"` | |
| ## Guidelines | |
| - **Be concise and actionable.** Focus on solving the user's problem efficiently. | |
| - **Always commit and push your changes if you modify code or documentation.** | |
| - **If you are unsure about the fix or answer, explain your reasoning and ask clarifying questions.** | |
| - **Follow project conventions and best practices.** | |
| - name: 'Print failure' | |
| if: |- | |
| ${{ failure() && !cancelled() }} | |
| env: | |
| GITHUB_TOKEN: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}' | |
| ISSUE_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number }}' | |
| MESSAGE: |- | |
| 🤖 I'm sorry @${{ github.actor }}, but I was unable to process your request. Please [see the logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details. | |
| REPOSITORY: '${{ github.repository }}' | |
| run: |- | |
| gh issue comment "${ISSUE_NUMBER}" \ | |
| --body "${MESSAGE}" \ | |
| --repo "${REPOSITORY}" |