# Copyright 2022 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.

options:
  dynamic_substitutions: true

substitutions:
  _NODE_VERSION: "14"
  _BUILD_TYPE: "presubmit"
  _TRIGGER_SOURCE: '${_PR_NUMBER:-main}'

logsBucket: 'gs://${_LOGS_BUCKET}/logs/nodejs-getting-started/${_TRIGGER_SOURCE}/${COMMIT_SHA}/${TRIGGER_NAME}'
timeout: 7200s

steps:
  - name: 'gcr.io/kaniko-project/executor:v1.10.0'
    args: [
      '--log-format=text',
      '--context=dir:///workspace/testing',
      '--build-arg=NODE_VERSION=${_NODE_VERSION}',
      '--dockerfile=ci/cloudbuild/Dockerfile',
      '--cache=true',
      '--destination=gcr.io/${PROJECT_ID}/${_IMAGE_PREFIX}${_NODE_VERSION}',
      '--push-retry=3',
      '--image-fs-extract-retry=3'
    ]

  - name: gcr.io/${PROJECT_ID}/${_IMAGE_PREFIX}${_NODE_VERSION}
    id: "test-driver"
    timeout: 7200s
    entrypoint: "bash"
    env:
    - 'BUILD_TYPE=${_BUILD_TYPE}'
    - 'GCLOUD_PROJECT=${PROJECT_ID}'
    - 'PROJECT_ID=${PROJECT_ID}'
    - 'COMMIT_SHA=${COMMIT_SHA}'
    - 'BUILD_ID=${BUILD_ID}'
    - 'REPO_OWNER=${_REPO_OWNER}'
    - 'REPO_NAME=${REPO_NAME}'
    args: [
      "ci/cloudbuild/run_test.sh",
    ]
