# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# An example of Cloud Build configuration file to run deployment script for CI/CD pipeline.

steps:
- id: 'Check required variables'
  name: 'alpine'
  entrypoint: 'sh'
  args:
  - '-c'
  - |
      echo "***********************"
      echo "BRANCH_NAME: ${BRANCH_NAME}"
      echo "SHORT_SHA: ${SHORT_SHA}"
      echo "PROJECT_ID: ${PROJECT_ID}"
      echo "SERVICE_ACCOUNT_EMAIL: ${SERVICE_ACCOUNT_EMAIL}"
      echo "***********************"
      if [[ ! -v $BRANCH_NAME || ! -v $SHORT_SHA || ! -v $PROJECT_ID || ! -v $SERVICE_ACCOUNT_EMAIL ]]; then
        echo "A required variable is not set, failing the build."
        exit 1
      fi

- name: 'gcr.io/cloud-builders/gcloud'
  id: 'Deploy Agent Assist integration backend'
  entrypoint: 'bash'
  args: ['aa-integration-backend/deploy.sh']
  env:
  - 'GCP_PROJECT_ID=$PROJECT_ID'
  - 'ADMIN_ACCOUNT=$SERVICE_ACCOUNT_EMAIL'
  - 'AUTH_OPTION=Skip'
  - 'BACKEND_DIR=/aa-integration-backend'
  - 'CONNECTOR_SERVICE_NAME=ui-connector-presubmit-${SHORT_SHA}'
  - 'INTERCEPTOR_SERVICE_NAME=cloud-pubsub-interceptor-presubmit-${SHORT_SHA}'
