This tutorial utilizes Gemini to assist with code reviews within the CICD process. An example integration and workflow are included to demonstrate the capabilities and bootstrap your effort. Additional modifications and customizations can be made by providing your own prompts as well as extending the provided CLI tool.
In this tutorial you will:
- Configure GCP for access to Gemini APIs
- Configure GitHub to integrate with GCP
- Review GitHub workflow and Gemini API calls
- Execute a CICD job and Review GenAI output
- Open the google cloud console
- Activate Cloud Shell
The following steps prepare your Google Cloud project to enable and access Gemini API through Vertex.
In the opened terminal, enable required services to use Vertex AI APIs and Gemini chat.
gcloud services enable \
aiplatform.googleapis.com \
cloudaicompanion.googleapis.com \
cloudresourcemanager.googleapis.com \
secretmanager.googleapis.comIf prompted to authorize, click "Authorize" to continue.
Run following commands to create a new service account and download the keys to your workspace.
You will use this service account to make API calls to Vertex AI Gemini API from CICD pipelines.
PROJECT_ID=$(gcloud config get-value project)
SERVICE_ACCOUNT_NAME='vertex-client'
DISPLAY_NAME='Vertex Client'
KEY_FILE_NAME='vertex-client-key'
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME --display-name "$DISPLAY_NAME"
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" --role="roles/aiplatform.admin" --condition None
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" --role="roles/secretmanager.secretAccessor" --condition None
gcloud iam service-accounts keys create $KEY_FILE_NAME.json --iam-account=$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.comThis tutorial uses a sample repository to demostrate the features. Start by forking the repo for your own use.
- Fork GitHub repo
- Select your github userid as an owner.
- Uncheck option to copy only the "main" branch.
- Click "Create fork".
A GitHub workflow is provided in the repo, however you will need to enable GitHub actions in your forked repo in order to run the process.
- Open the forked repo in the browser
- Switch to the "Actions" tab
- Enable GitHub workflows
In this step you will create a repository secret to hold the GCP API credentials and make them available to Actions within this repo.
- In your GCP terminal run the following command to view the GCP secret created earlier.
cat ~/vertex-client-key.json-
Copy the secret output to your clipboard. You'll paste it in the following steps
-
In GitHub, navigate to "Settings -> Secrets and variables -> Actions" in the GitHub repository.
-
Add Repository secret called "GOOGLE_API_CREDENTIALS"
-
Paste the secret you copied earlier into the value field for the secret.
-
Click Add Secret
-
Follow the same steps to add
PROJECT_ID=your-gcp-project andLOCATION=us-central1 secrets
Navigate to your GitHub repository in the browser and run the workflow - GenAI For Developers.
The workflow is configured to run on code push or manual execution.
You can review the execution and resulting summary in GitHub.
- In the browser, Open the GitHub "Actions" tab and review the workflow output.
- When the job completes click on Summary and scroll down to see the AI generated output.
Return to the Cloud Shell terminal and clone the repository. Change YOUR-GITHUB-USERID to your GitHub userid before running the commands.
git clone https://github.com/YOUR-GITHUB-USERID/genai-for-developers.git Change into the directory before continuing with the rest of the tutorial.
cd genai-for-developersOpen the GitHub workflow by opening the file below.
cloudshell edit .github/workflows/devai-review.yml Review the tasks at the bottom of the file that use the devai cli.
For example the code review step includes devai review code -c [source to review]
In cloudshell you can open the specific file with the following command.
cloudshell edit devai-cli/src/devai/commands/review.py Review the prompt used in the code function. The function begins with
@click.command(name='code')
@click.option('-c', '--context', required=False, type=str, default="")
def code(context):Review the other functions and prompts used in this workflow such as testcoverage, performance, security, blockers.
Take a look at other tutorials to enable integrations with JIRA, GitLab and LangSmith.