Merge pull request #1 from bettersg/agent/uat/openai-assistants-api-1 #22
Workflow file for this run
This file contains 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: Deploy UAT Agent | |
on: | |
push: | |
branches: | |
- "agent/uat/*" | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
environment: uat | |
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}} |