testing/jobs.pr.cloudbuild.yaml (71 lines of code) (raw):

# 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 # # https://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. steps: - id: 'Lint' name: 'golang:1.18-alpine' dir: 'job/' entrypoint: /bin/sh args: - '-c' - | go install golang.org/x/tools/cmd/goimports@latest if [ -n "$(goimports -d .)" ]; then echo 'To fix this check, run "goimports -w ."' exit 1 fi - id: 'Unit Tests' name: 'golang:1.18-alpine' dir: 'job/' args: ['test', '-v'] - id: 'Build Container Image' name: 'gcr.io/${PROJECT_ID}/pack:latest' dir: 'job/' args: ['build', '--builder', 'gcr.io/buildpacks/builder:google-22', 'gcr.io/${PROJECT_ID}/${_IMAGE}:${SHORT_SHA}'] # Tag docker image with git commit sha - id: 'Push Container Image to Container Registry' name: 'gcr.io/cloud-builders/docker:latest' args: ['push', 'gcr.io/${PROJECT_ID}/${_IMAGE}:${SHORT_SHA}'] - id: 'Deploy to Cloud Run' name: 'gcr.io/cloud-builders/gcloud:$_CLOUDSDK_VERSION' entrypoint: /bin/bash args: - '-c' - | gcloud components install --quiet gcloud run jobs create ${_IMAGE}-${SHORT_SHA} \ --image gcr.io/${PROJECT_ID}/${_IMAGE}:${SHORT_SHA} \ --project ${PROJECT_ID} \ --region ${_REGION} \ --tasks 2 \ --set-env-vars=SLEEP_MS=1000 \ --max-retries 0 \ --wait - id: 'Check Job Logs' name: 'gcr.io/cloud-builders/gcloud:$_CLOUDSDK_VERSION' entrypoint: /bin/bash args: - '-c' - | output=$(gcloud logging read \ "resource.type=cloud_run_job \ AND resource.labels.job_name=${_IMAGE}-${SHORT_SHA} \ AND resource.labels.location=${_REGION} \ AND Task #" \ --limit 10 --format 'value(textPayload)') echo $output if [[ $output ]]; then echo "Logs Found." else exit 1 fi - id: 'Teardown' name: 'gcr.io/cloud-builders/gcloud:$_CLOUDSDK_VERSION' entrypoint: '/bin/bash' args: - '-c' - | set -x gcloud --quiet container images delete gcr.io/${PROJECT_ID}/${_IMAGE}:${SHORT_SHA} --force-delete-tags gcloud --quiet run jobs delete ${_IMAGE}-${SHORT_SHA} --region ${_REGION} set +x substitutions: _IMAGE: job-pr _REGION: us-central1 _CLOUDSDK_VERSION: latest