-
Notifications
You must be signed in to change notification settings - Fork 28
/
cloudbuild.yaml
98 lines (88 loc) · 3.08 KB
/
cloudbuild.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
# Copyright 2024 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:
# Truncate output table if the previous build failed.
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'bq'
- 'query'
- '--use_legacy_sql=false'
- 'CREATE OR REPLACE TABLE `bigquery-antipattern-test.antipattern_test_data.output_data` AS SELECT * FROM `bigquery-antipattern-test.antipattern_test_data.output_data` LIMIT 0'
entrypoint: 'bash'
id: 'truncate-run-output-table-init'
# Create new image in Artifact Registry.
- name: 'gcr.io/cloud-builders/mvn'
args: [
'clean',
'package',
'jib:build',
'-DskipTests',
'-Djib.to.image=us-central1-docker.pkg.dev/bigquery-antipattern-test/bigquery-antipattern-tool/$BUILD_ID'
]
id: 'build-new-image'
waitFor: ['truncate-run-output-table-init']
# Update the Antipattern Cloud Run Job with new image
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: 'gcloud'
args:
- 'beta'
- 'run'
- 'jobs'
- 'update'
- 'bigquery-antipattern-tool'
- '--image=us-central1-docker.pkg.dev/bigquery-antipattern-test/bigquery-antipattern-tool/$BUILD_ID'
- '--region=us-central1'
id: 'update-cloud-run-job'
waitFor: ['build-new-image']
# Run the Antipattern Cloud Run Job
- name: 'gcr.io/cloud-builders/gcloud'
args: [
'run',
'jobs',
'execute',
'bigquery-antipattern-tool',
'--region=us-central1'
]
id: 'execute-cloud-run-job'
waitFor: ['update-cloud-run-job']
# Check if output_data and output_data_reference match
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
sleep 20
result=$(bq query --use_legacy_sql=false "SELECT COUNT(*) = 0 AS is_empty FROM \`bigquery-antipattern-test.antipattern_test_data.test_results\`")
# Check the 'is_empty' column in the result
if [[ $result == *"true"* ]]; then
echo "true" # Table is empty
else
echo "false" # Table is not empty
exit 1
fi
id: 'check-table-empty'
waitFor: ['execute-cloud-run-job']
# Truncate output table for cleanup
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'bq'
- 'query'
- '--use_legacy_sql=false'
- 'CREATE OR REPLACE TABLE `bigquery-antipattern-test.antipattern_test_data.output_data` AS SELECT * FROM `bigquery-antipattern-test.antipattern_test_data.output_data` LIMIT 0'
entrypoint: 'bash'
id: 'truncate-run-output-table'
waitFor: ['check-table-empty']
options:
logging: CLOUD_LOGGING_ONLY