Skip to content

Commit e9ddf24

Browse files
authored
Refactor action to use inputs instead of environment variables (#65)
This commit refactors the GitHub Action to use explicit inputs instead of environment variables for configuration. This change improves the usability and clarity of the action by making all configuration options visible in the workflow file. Key changes: - action.yml: Replaced environment variable references with new inputs for Gemini API key, GCP project ID, CLI version, and other settings. - README.md: Updated documentation to reflect the new input-based configuration and updated the environment variable section. - Workflows: Updated all example workflows to use the new inputs. Fixes #28 @sethvargo PTAL
1 parent 5816973 commit e9ddf24

17 files changed

Lines changed: 242 additions & 224 deletions

.github/workflows/gemini-cli.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,14 @@ jobs:
173173
USER_REQUEST: '${{ steps.get_context.outputs.user_request }}'
174174
ISSUE_NUMBER: '${{ steps.get_context.outputs.issue_number }}'
175175
IS_PR: '${{ steps.get_context.outputs.is_pr }}'
176-
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'
177-
GCP_WIF_PROVIDER: '${{ vars.GCP_WIF_PROVIDER }}'
178-
OTLP_GOOGLE_CLOUD_PROJECT: '${{ vars.OTLP_GOOGLE_CLOUD_PROJECT }}'
179-
GOOGLE_CLOUD_PROJECT: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
180-
GOOGLE_CLOUD_LOCATION: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
181-
GOOGLE_GENAI_USE_VERTEXAI: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
182-
GOOGLE_GENAI_USE_GCA: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
183-
SERVICE_ACCOUNT_EMAIL: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
184176
with:
177+
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
178+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
179+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
180+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
181+
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
182+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
183+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
185184
settings: |
186185
{
187186
"maxSessionTurns": 50,

.github/workflows/gemini-issue-automated-triage.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,15 @@ jobs:
6464
ISSUE_BODY: '${{ github.event.issue.body }}'
6565
ISSUE_NUMBER: '${{ github.event.issue.number }}'
6666
REPOSITORY: '${{ github.repository }}'
67-
GEMINI_CLI_VERSION: '${{ vars.GEMINI_CLI_VERSION }}'
68-
OTLP_GOOGLE_CLOUD_PROJECT: '${{ vars.OTLP_GOOGLE_CLOUD_PROJECT }}'
69-
GCP_WIF_PROVIDER: '${{ vars.GCP_WIF_PROVIDER }}'
70-
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'
71-
GOOGLE_CLOUD_PROJECT: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
72-
GOOGLE_CLOUD_LOCATION: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
73-
GOOGLE_GENAI_USE_VERTEXAI: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
74-
GOOGLE_GENAI_USE_GCA: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
75-
SERVICE_ACCOUNT_EMAIL: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
7667
with:
68+
gemini_cli_version: '${{ vars.GEMINI_CLI_VERSION }}'
69+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
70+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
71+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
72+
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
73+
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
74+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
75+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
7776
settings: |-
7877
{
7978
"maxSessionTurns": 25,

.github/workflows/gemini-issue-scheduled-triage.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,15 @@ jobs:
7272
GITHUB_TOKEN: '${{ steps.generate_token.outputs.token }}'
7373
ISSUES_TO_TRIAGE: '${{ steps.find_issues.outputs.issues_to_triage }}'
7474
REPOSITORY: '${{ github.repository }}'
75-
GEMINI_CLI_VERSION: '${{ vars.GEMINI_CLI_VERSION }}'
76-
OTLP_GOOGLE_CLOUD_PROJECT: '${{ vars.OTLP_GOOGLE_CLOUD_PROJECT }}'
77-
GCP_WIF_PROVIDER: '${{ vars.GCP_WIF_PROVIDER }}'
78-
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'
79-
GOOGLE_CLOUD_PROJECT: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
80-
GOOGLE_CLOUD_LOCATION: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
81-
GOOGLE_GENAI_USE_VERTEXAI: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
82-
GOOGLE_GENAI_USE_GCA: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
83-
SERVICE_ACCOUNT_EMAIL: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
8475
with:
76+
gemini_cli_version: '${{ vars.GEMINI_CLI_VERSION }}'
77+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
78+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
79+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
80+
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
81+
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
82+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
83+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
8584
settings: |-
8685
{
8786
"maxSessionTurns": 25,

.github/workflows/gemini-pr-review.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,15 @@ jobs:
151151
CHANGED_FILES: '${{ steps.get_pr.outputs.changed_files || steps.get_pr_comment.outputs.changed_files }}'
152152
ADDITIONAL_INSTRUCTIONS: '${{ steps.get_pr.outputs.additional_instructions || steps.get_pr_comment.outputs.additional_instructions }}'
153153
REPOSITORY: '${{ github.repository }}'
154-
GEMINI_CLI_VERSION: '${{ vars.GEMINI_CLI_VERSION }}'
155-
OTLP_GOOGLE_CLOUD_PROJECT: '${{ vars.OTLP_GOOGLE_CLOUD_PROJECT }}'
156-
GCP_WIF_PROVIDER: '${{ vars.GCP_WIF_PROVIDER }}'
157-
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'
158-
GOOGLE_CLOUD_PROJECT: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
159-
GOOGLE_CLOUD_LOCATION: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
160-
GOOGLE_GENAI_USE_VERTEXAI: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
161-
GOOGLE_GENAI_USE_GCA: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
162-
SERVICE_ACCOUNT_EMAIL: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
163154
with:
155+
gemini_cli_version: '${{ vars.GEMINI_CLI_VERSION }}'
156+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
157+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
158+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
159+
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
160+
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
161+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
162+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
164163
settings: |-
165164
{
166165
"maxSessionTurns": 20,

README.md

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ Cloud product, please contact [Google Cloud support].**
2121
- [Issue Triage](#issue-triage)
2222
- [Pull Request Review](#pull-request-review)
2323
- [Generic Gemini CLI](#generic-gemini-cli)
24-
- [Authentication](#authentication)
24+
- [GitHub Authentication](#github-authentication)
2525
- [Observability with OpenTelemetry](#observability-with-opentelemetry)
26-
- [OpenTelemetry in Google Cloud](#opentelemetry-in-google-cloud)
2726
- [Customization](#customization)
2827
- [Contributing](#contributing)
2928

@@ -47,8 +46,7 @@ Before using the Gemini CLI GitHub Action, make sure to:
4746

4847
## Configuration
4948

50-
The Gemini CLI GitHub Action is configured via a combination of workflow inputs, outputs,
51-
environment variables, and secrets.
49+
The Gemini CLI GitHub Action is configured via workflow inputs and secrets.
5250

5351
### Inputs
5452

@@ -59,6 +57,22 @@ environment variables, and secrets.
5957
- <a name="settings"></a><a href="#user-content-settings"><code>settings</code></a>: _(Optional)_ A JSON string written to `.gemini/settings.json` to configure the CLI's _project_ settings.
6058
For more details, see the documentation on [settings files](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/configuration.md#settings-files).
6159

60+
- <a name="gemini_api_key"></a><a href="#user-content-gemini_api_key"><code>gemini_api_key</code></a>: _(Optional)_ The API key for the Gemini API.
61+
62+
- <a name="gcp_project_id"></a><a href="#user-content-gcp_project_id"><code>gcp_project_id</code></a>: _(Optional)_ The Google Cloud project ID.
63+
64+
- <a name="gcp_location"></a><a href="#user-content-gcp_location"><code>gcp_location</code></a>: _(Optional)_ The Google Cloud location.
65+
66+
- <a name="gcp_workload_identity_provider"></a><a href="#user-content-gcp_workload_identity_provider"><code>gcp_workload_identity_provider</code></a>: _(Optional)_ The Google Cloud Workload Identity Provider.
67+
68+
- <a name="gcp_service_account"></a><a href="#user-content-gcp_service_account"><code>gcp_service_account</code></a>: _(Optional)_ The Google Cloud service account email.
69+
70+
- <a name="use_vertex_ai"></a><a href="#user-content-use_vertex_ai"><code>use_vertex_ai</code></a>: _(Optional, default: `false`)_ A flag to indicate if Vertex AI should be used.
71+
72+
- <a name="use_gemini_code_assist"></a><a href="#user-content-use_gemini_code_assist"><code>use_gemini_code_assist</code></a>: _(Optional, default: `false`)_ A flag to indicate if Gemini Code Assist should be used.
73+
74+
- <a name="gemini_cli_version"></a><a href="#user-content-gemini_cli_version"><code>gemini_cli_version</code></a>: _(Optional, default: `latest`)_ The version of the Gemini CLI to install.
75+
6276

6377
<!-- END_AUTOGEN_INPUTS -->
6478

@@ -73,35 +87,48 @@ environment variables, and secrets.
7387

7488
### Environment Variables
7589

76-
Set the following environment variables in your repository or workflow:
90+
You can set the following environment variables in your repository:
91+
92+
| Name | Description | Type | Required | When Required |
93+
| -------- | ---------------------------------------- | -------- | -------- | ------------------------- |
94+
| `APP_ID` | GitHub App ID for custom authentication. | Variable | No | Using a custom GitHub App |
95+
96+
The following environment variables are automatically passed into the action's inputs if set in your repository or workflow.
97+
You may also set them directly as workflow inputs if preferred.
98+
99+
| Name | Description | Type | Required | When Required |
100+
| --------------------------- | ------------------------------------------------------ | -------- | -------- | ------------------------ |
101+
| `GEMINI_CLI_VERSION` | Controls which version of the Gemini CLI is installed. | Variable | No | Pinning the CLI version |
102+
| `GCP_WIF_PROVIDER` | Full resource name of the Workload Identity Provider. | Variable | No | Using Google Cloud |
103+
| `GOOGLE_CLOUD_PROJECT` | Google Cloud project for inference and observability. | Variable | No | Using Google Cloud |
104+
| `SERVICE_ACCOUNT_EMAIL` | Google Cloud service account email address. | Variable | No | Using Google Cloud |
105+
| `GOOGLE_CLOUD_LOCATION` | Region of the Google Cloud project. | Variable | No | Using Google Cloud |
106+
| `GOOGLE_GENAI_USE_VERTEXAI` | Set to 'true' to use Vertex AI | Variable | No | Using Vertex AI |
107+
| `GOOGLE_GENAI_USE_GCA` | Set to 'true' to use Gemini Code Assist | Variable | No | Using Gemini Code Assist |
77108

78-
| Name | Description | Type | Required | When Required |
79-
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- | ----------------------------------- |
80-
| GEMINI_CLI_VERSION | Controls which version of the Gemini CLI is installed. Supports `npm` versions (e.g., `0.1.0`, `latest`), a branch name (e.g., `main`), or a commit hash. | Variable | No | To pin or override the CLI version |
81-
| GCP_WIF_PROVIDER | Full resource name of the Workload Identity Provider. | Variable | No | When using observability |
82-
| OTLP_GOOGLE_CLOUD_PROJECT | Google Cloud project for telemetry. | Variable | No | When using observability |
83-
| GOOGLE_CLOUD_PROJECT | Google Cloud project for Vertex AI authentication. | Variable | No | When using Vertex AI authentication |
84-
| GOOGLE_CLOUD_LOCATION | Geographic location of the Google Cloud project for Vertex AI authentication. | Variable | No | When using Vertex AI authentication |
85-
| GOOGLE_GENAI_USE_VERTEXAI | Set to 'true' to use Vertex AI | Variable | No | When using Vertex AI authentication |
86-
| APP_ID | GitHub App ID for custom authentication. | Variable | No | When using a custom GitHub App |
87109

110+
To add an environment variable:
111+
1) Go to your repository's **Settings > Secrets and variables > Actions > New variable**.
112+
2) Enter the variable name and value.
113+
3) Save.
88114

89-
To add an environment variable: 1) Go to your repository's **Settings > Secrets and
90-
variables > Actions > New variable**; 2) Enter the variable name and value; and 3) Save.
91-
For organization-wide or environment-specific variables, refer to the
92-
[GitHub documentation on variables][variables].
115+
For organization-wide or environment-specific variables, refer to the [GitHub documentation on variables][variables].
93116

94117
### Secrets
95118

96-
The following secrets are required for security:
119+
You can set the following secrets in your repository:
97120

98-
| Name | Description | Required | When Required |
99-
| --------------- | --------------------------------------------- | -------- | --------------------------------------------------------- |
100-
| GEMINI_API_KEY | Your Gemini API key from Google AI Studio. | No | If you are using the Gemini API key from Google AI Studio |
101-
| APP_PRIVATE_KEY | Private key for your GitHub App (PEM format). | No | If you are using a custom GitHub App |
121+
| Name | Description | Required | When Required |
122+
| ----------------- | --------------------------------------------- | -------- | ----------------------------- |
123+
| `GEMINI_API_KEY` | Your Gemini API key from Google AI Studio. | No | You don't have a GCP project. |
124+
| `APP_PRIVATE_KEY` | Private key for your GitHub App (PEM format). | No | Using a custom GitHub. |
102125

103-
To add a secret, go to your repository's **Settings > Secrets and variables >
104-
Actions > New repository secret**. For more information, refer to the
126+
To add a secret:
127+
1) Go to your repository's **Settings > Secrets and variables >Actions > New repository secret**.
128+
2) Enter the secret name and value.
129+
3) Save.
130+
131+
For more information, refer to the
105132
[official GitHub documentation on creating and using encrypted secrets][secrets].
106133

107134
## Workflows
@@ -110,7 +137,7 @@ Workflows include Issue Triage, Pull Request Review. and Generic Gemini CLI. To
110137
this GitHub Action, you need to create a workflow file in your repository (e.g.,
111138
`.github/workflows/gemini.yml`). The best way to get started is to copy one of the pre-built workflows from the
112139
[`/workflows`](./workflows) directory into your project's `.github/workflows`
113-
folder and customize it.
140+
folder and [customize](/workflows/README.md#customizing-workflows) it.
114141

115142
Below are specific examples of workflows:
116143

@@ -137,7 +164,7 @@ AI assistant within the pull requests and issues to perform a wide range of
137164
tasks. For a detailed guide on how to set up the [Gemini CLI], go to the Generic
138165
[Gemini CLI workflow documentation](./workflows/gemini-cli).
139166

140-
## Authentication
167+
## GitHub Authentication
141168

142169
This action requires a GitHub token to interact with the GitHub API. You can
143170
authenticate in two ways:
@@ -161,12 +188,6 @@ for debugging and optimization.
161188
For detailed instructions on how to set up and configure observability, go to
162189
the [Observability documentation](./docs/observability.md).
163190

164-
### OpenTelemetry in Google Cloud
165-
166-
To use observability features with Google Cloud, you'll need to set up Workload
167-
Identity Federation. For detailed setup instructions, check out the
168-
[Workload Identity Federation documentation](./docs/workload-identity.md).
169-
170191
## Customization
171192

172193
Create a `GEMINI.md` file in the root of your repository to provide

action.yml

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ inputs:
2828
A JSON string written to `.gemini/settings.json` to configure the CLI's _project_ settings.
2929
For more details, see the documentation on [settings files](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/configuration.md#settings-files).
3030
required: false
31+
gemini_api_key:
32+
description: 'The API key for the Gemini API.'
33+
required: false
34+
gcp_project_id:
35+
description: 'The Google Cloud project ID.'
36+
required: false
37+
gcp_location:
38+
description: 'The Google Cloud location.'
39+
required: false
40+
gcp_workload_identity_provider:
41+
description: 'The Google Cloud Workload Identity Provider.'
42+
required: false
43+
gcp_service_account:
44+
description: 'The Google Cloud service account email.'
45+
required: false
46+
use_vertex_ai:
47+
description: 'A flag to indicate if Vertex AI should be used.'
48+
required: false
49+
default: 'false'
50+
use_gemini_code_assist:
51+
description: 'A flag to indicate if Gemini Code Assist should be used.'
52+
required: false
53+
default: 'false'
54+
gemini_cli_version:
55+
description: 'The version of the Gemini CLI to install.'
56+
required: false
57+
default: 'latest'
3158

3259
outputs:
3360
summary:
@@ -49,21 +76,21 @@ runs:
4976

5077
- name: 'Authenticate to Google Cloud'
5178
if: |-
52-
${{ env.GCP_WIF_PROVIDER != '' }}
79+
${{ inputs.gcp_workload_identity_provider != '' }}
5380
id: 'auth'
5481
uses: 'google-github-actions/auth@v2'
5582
with:
56-
project_id: '${{ env.GOOGLE_CLOUD_PROJECT }}'
57-
workload_identity_provider: '${{ env.GCP_WIF_PROVIDER }}'
58-
service_account: '${{ env.SERVICE_ACCOUNT_EMAIL }}'
83+
project_id: '${{ inputs.gcp_project_id }}'
84+
workload_identity_provider: '${{ inputs.gcp_workload_identity_provider }}'
85+
service_account: '${{ inputs.gcp_service_account }}'
5986
token_format: 'access_token'
6087
access_token_scopes: 'https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
6188

6289
- name: 'Run Telemetry Collector for Google Cloud'
6390
if: |-
64-
${{ env.GCP_WIF_PROVIDER != '' }}
91+
${{ inputs.gcp_workload_identity_provider != '' }}
6592
env:
66-
OTLP_GOOGLE_CLOUD_PROJECT: '${{ env.OTLP_GOOGLE_CLOUD_PROJECT }}'
93+
OTLP_GOOGLE_CLOUD_PROJECT: '${{ inputs.gcp_project_id }}'
6794
GITHUB_ACTION_PATH: '${{ github.action_path }}'
6895
shell: 'bash'
6996
run: |-
@@ -82,7 +109,7 @@ runs:
82109
- name: 'Install Gemini CLI'
83110
id: 'install'
84111
env:
85-
GEMINI_CLI_VERSION: '${{ env.GEMINI_CLI_VERSION }}'
112+
GEMINI_CLI_VERSION: '${{ inputs.gemini_cli_version }}'
86113
shell: 'bash'
87114
run: |-
88115
set -euo pipefail
@@ -121,12 +148,12 @@ runs:
121148
echo "${GEMINI_RESPONSE}"
122149
shell: 'bash'
123150
env:
124-
GEMINI_API_KEY: '${{ env.GEMINI_API_KEY }}'
151+
GEMINI_API_KEY: '${{ inputs.gemini_api_key }}'
125152
SURFACE: 'GitHub'
126-
GOOGLE_CLOUD_PROJECT: '${{ env.GOOGLE_CLOUD_PROJECT }}'
127-
GOOGLE_CLOUD_LOCATION: '${{ env.GOOGLE_CLOUD_LOCATION }}'
128-
GOOGLE_GENAI_USE_VERTEXAI: '${{ env.GOOGLE_GENAI_USE_VERTEXAI }}'
129-
GOOGLE_GENAI_USE_GCA: '${{ env.GOOGLE_GENAI_USE_GCA }}'
153+
GOOGLE_CLOUD_PROJECT: '${{ inputs.gcp_project_id }}'
154+
GOOGLE_CLOUD_LOCATION: '${{ inputs.gcp_location }}'
155+
GOOGLE_GENAI_USE_VERTEXAI: '${{ inputs.use_vertex_ai }}'
156+
GOOGLE_GENAI_USE_GCA: '${{ inputs.use_gemini_code_assist }}'
130157
GOOGLE_CLOUD_ACCESS_TOKEN: '${{steps.auth.outputs.access_token}}'
131158
PROMPT: '${{ inputs.prompt }}'
132159

0 commit comments

Comments
 (0)