Skip to content

Merge pull request #13 from bettersg/agent/uat/openai-assistants-api-1 #1

Merge pull request #13 from bettersg/agent/uat/openai-assistants-api-1

Merge pull request #13 from bettersg/agent/uat/openai-assistants-api-1 #1

name: Deploy PROD Agent
on:
push:
branches:
- "agent/prod/*"
paths:
- "implementation/agent.py"
jobs:
build_and_deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Read agent_name from .agent_name
run: echo "AGENT_NAME=$(grep AGENT_NAME .agent_name | cut -d '=' -f2 | xargs)" >> $GITHUB_ENV
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Get Access Token
id: get_token
run: |
# Obtain the access token
ACCESS_TOKEN=$(gcloud auth print-identity-token --audiences=${{ vars.API_HOST }})
# Mask the access token in logs
echo "::add-mask::$ACCESS_TOKEN"
# Set the access token as an environment variable for use in subsequent steps
echo "ACCESS_TOKEN=$ACCESS_TOKEN" >> $GITHUB_ENV
- name: Call Google Cloud API
run: |
response=$(curl -s -o response.json -w "%{http_code}" ${{ vars.API_HOST }}/checkers \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
-v \
-d '{"name": "'"$AGENT_NAME"'", "type": "ai", "telegramId": null}')
if [ "$response" = "409" ]; then
echo "Name already exists, continuing..."
elif [ "$response" = "200" ]; then
echo "Successfully created agent, continuing..."
else
echo "API call failed with response code $response"
cat response.json
exit 1
fi
- name: Deploy cloud function with pubsub trigger
run: |
gcloud functions deploy agent_$AGENT_NAME \
--gen2 \
--runtime=python311 \
--region=asia-southeast1 \
--source=. \
--entry-point=subscribe \
--trigger-topic=${{ vars.TOPIC_NAME }} \
--set-env-vars AGENT_NAME=$AGENT_NAME,API_HOST=${{ vars.API_HOST }},WEBDRIVER_HOST=${{ vars.WEBDRIVER_HOST }},GOOGLE_CSE_ID=${{ vars.GOOGLE_CSE_ID }} \
--set-secrets 'OPENAI_API_KEY=OPENAI_API_KEY:latest,GOOGLE_SEARCH_API_KEY=GOOGLE_SEARCH_API_KEY:latest'