diff --git a/.github/workflows/gemini-cli.yml b/.github/workflows/gemini-cli.yml index be5cfcec..85db7b84 100644 --- a/.github/workflows/gemini-cli.yml +++ b/.github/workflows/gemini-cli.yml @@ -125,6 +125,7 @@ jobs: gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}' gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' + google_api_key: '${{ secrets.GOOGLE_API_KEY }}' use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' settings: |- { diff --git a/.github/workflows/gemini-issue-automated-triage.yml b/.github/workflows/gemini-issue-automated-triage.yml index aea8f922..71087cd4 100644 --- a/.github/workflows/gemini-issue-automated-triage.yml +++ b/.github/workflows/gemini-issue-automated-triage.yml @@ -87,6 +87,7 @@ jobs: gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' + google_api_key: '${{ secrets.GOOGLE_API_KEY }}' use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' settings: |- { diff --git a/.github/workflows/gemini-issue-scheduled-triage.yml b/.github/workflows/gemini-issue-scheduled-triage.yml index 13f2e0f6..fd42fa6a 100644 --- a/.github/workflows/gemini-issue-scheduled-triage.yml +++ b/.github/workflows/gemini-issue-scheduled-triage.yml @@ -95,6 +95,7 @@ jobs: gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' + google_api_key: '${{ secrets.GOOGLE_API_KEY }}' use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' settings: |- { diff --git a/.github/workflows/gemini-pr-review.yml b/.github/workflows/gemini-pr-review.yml index beaddf43..aeaaabfb 100644 --- a/.github/workflows/gemini-pr-review.yml +++ b/.github/workflows/gemini-pr-review.yml @@ -169,6 +169,7 @@ jobs: gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' + google_api_key: '${{ secrets.GOOGLE_API_KEY }}' use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' settings: |- { diff --git a/README.md b/README.md index b6ca2d50..0c7ca98e 100644 --- a/README.md +++ b/README.md @@ -45,15 +45,19 @@ Use it to perform GitHub pull request reviews, triage issues, perform code analy Get started with Gemini CLI in your repository in just a few minutes: ### 1. Get a Gemini API Key + Obtain your API key from [Google AI Studio] with generous free-of-charge quotas ### 2. Add it as a GitHub Secret + Store your API key as a secret named `GEMINI_API_KEY` in your repository: + - Go to your repository's **Settings > Secrets and variables > Actions** - Click **New repository secret** - Name: `GEMINI_API_KEY`, Value: your API key ### 3. Update your .gitignore + Add the following entries to your `.gitignore` file: ```gitignore @@ -65,9 +69,11 @@ gha-creds-*.json ``` ### 4. Choose a Workflow + You have two options to set up a workflow: **Option A: Use setup command (Recommended)** + 1. Start the Gemini CLI in your terminal: ```shell @@ -81,19 +87,23 @@ You have two options to set up a workflow: ``` **Option B: Manually copy workflows** + 1. Copy the pre-built workflows from the [`examples/workflows`](./examples/workflows) directory to your repository's `.github/workflows` directory. ### 5. Try it out! **Pull Request Review:** + - Open a pull request in your repository and wait for automatic review - Comment `@gemini-cli /review` on an existing pull request to manually trigger a review **Issue Triage:** + - Open an issue and wait for automatic triage - Comment `@gemini-cli /triage` on existing issues to manually trigger triaging **General AI Assistance:** + - In any issue or pull request, mention `@gemini-cli` followed by your request - Examples: - `@gemini-cli explain this code change` @@ -117,7 +127,7 @@ This action can be used to automatically review pull requests when they are opened. For a detailed guide on how to set up the pull request review system, go to the [GitHub PR Review workflow documentation](./examples/workflows/pr-review). -There is a [known issue](https://github.com/google-github-actions/run-gemini-cli/issues/169) that action bot may approve the PR occasionally, +There is a [known issue](https://github.com/google-github-actions/run-gemini-cli/issues/169) that action bot may approve the PR occasionally, to avoid this situation as org owner you can restrict who can approve the PR following [Code Review Limits](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-pull-request-reviews-in-your-repository#enabling-code-review-limits). @@ -153,6 +163,8 @@ go to the [Gemini CLI workflow documentation](./examples/workflows/gemini-cli). - gemini_cli_version: _(Optional, default: `latest`)_ The version of the Gemini CLI to install. +- google_api_key: _(Optional)_ The Vertex AI API key to use with Gemini. + @@ -162,6 +174,8 @@ go to the [Gemini CLI workflow documentation](./examples/workflows/gemini-cli). - `summary`: The summarized output from the Gemini CLI execution. +- `error`: The error output from the Gemini CLI execution, if any. + @@ -180,11 +194,11 @@ We recommend setting the following values as repository variables so they can be | `GOOGLE_GENAI_USE_GCA` | Set to `true` to use Gemini Code Assist | Variable | No | Using Gemini Code Assist | | `APP_ID` | GitHub App ID for custom authentication. | Variable | No | Using a custom GitHub App | - To add a repository variable: -1) Go to your repository's **Settings > Secrets and variables > Actions > New variable**. -2) Enter the variable name and value. -3) Save. + +1. Go to your repository's **Settings > Secrets and variables > Actions > New variable**. +2. Enter the variable name and value. +3. Save. For details about repository variables, refer to the [GitHub documentation on variables][variables]. @@ -192,10 +206,11 @@ For details about repository variables, refer to the [GitHub documentation on va You can set the following secrets in your repository: -| Name | Description | Required | When Required | -| ----------------- | --------------------------------------------- | -------- | ----------------------------- | -| `GEMINI_API_KEY` | Your Gemini API key from Google AI Studio. | No | You don't have a GCP project. | -| `APP_PRIVATE_KEY` | Private key for your GitHub App (PEM format). | No | Using a custom GitHub App. | +| Name | Description | Required | When Required | +| ----------------- | --------------------------------------------- | -------- | ------------------------------------- | +| `GEMINI_API_KEY` | Your Gemini API key from Google AI Studio. | No | You don't have a GCP project. | +| `APP_PRIVATE_KEY` | Private key for your GitHub App (PEM format). | No | Using a custom GitHub App. | +| `GOOGLE_API_KEY` | Your Google API Key to use with Vertex AI. | No | You have a express Vertex AI account. | To add a secret: diff --git a/action.yml b/action.yml index a7e82247..2f59e111 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,9 @@ inputs: description: 'The version of the Gemini CLI to install.' required: false default: 'latest' + google_api_key: + description: 'The Vertex AI API key to use with Gemini.' + required: false outputs: summary: @@ -201,6 +204,7 @@ runs: GOOGLE_CLOUD_PROJECT: '${{ inputs.gcp_project_id }}' GOOGLE_CLOUD_LOCATION: '${{ inputs.gcp_location }}' GOOGLE_GENAI_USE_VERTEXAI: '${{ inputs.use_vertex_ai }}' + GOOGLE_API_KEY: '${{ inputs.google_api_key }}' GOOGLE_GENAI_USE_GCA: '${{ inputs.use_gemini_code_assist }}' GOOGLE_CLOUD_ACCESS_TOKEN: '${{steps.auth.outputs.access_token}}' PROMPT: '${{ inputs.prompt }}' diff --git a/docs/authentication.md b/docs/authentication.md index 942f5208..d1284423 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -56,7 +56,30 @@ This is the simplest method and is suitable for projects that do not require Goo gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' ``` -### Method 2: Authenticating with Google Cloud +### Method 2: Authenticating with a Vertex AI API Key + +This method is used for quick setup using Vertex AI through Google Cloud Console + +#### Prerequisites + +- A Vertex AI API key from Google Cloud Console + +#### Setup + +1. **Create an API Key**: Obtain your Google Cloud [API key](https://cloud.google.com/vertex-ai/generative-ai/docs/start/api-keys?usertype=newuser) +2. **Add to GitHub Secrets**: In your GitHub repository, go to **Settings > Secrets and variables > Actions** and add a new repository secret with the name `GOOGLE_API_KEY` and paste your key as the value and create new variable with the name `GOOGLE_GENAI_USE_VERTEXAI` and set value as `true`. + +#### Example + +```yaml +- uses: 'google-github-actions/run-gemini-cli@v0' + with: + prompt: |- + Explain this code + google_api_key: '${{ secrets.GOOGLE_API_KEY }}' +``` + +### Method 3: Authenticating with Google Cloud **[Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation)** is Google Cloud's preferred, keyless authentication method for GitHub Actions. It provides: