-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
174 lines (167 loc) · 6.58 KB
/
cloudbuild.yaml
File metadata and controls
174 lines (167 loc) · 6.58 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Copyright 2021 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.
steps:
- name: 'gcr.io/cloud-builders/gcloud'
id: 'Turnstyle DevRel Pipeline'
entrypoint: 'bash'
args:
- '-c'
- |
if [ "$(gcloud builds list --ongoing --format='value(id)' | wc -l | xargs)" -gt "1" ]; then
echo "Pipeline is already running";
exit -1;
fi
- name: 'gcr.io/kaniko-project/executor:latest'
id: 'Build Pipeline Runner Image'
args:
- --dockerfile=./tools/pipeline-runner/Dockerfile
- --context=./tools/pipeline-runner
- --destination=${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest
- --cache=true
- --cache-ttl=12h
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Cleanup Org'
entrypoint: 'bash'
args:
- '-c'
- |-
if [ "$_CLEAN_ORG" = "true" ]; then
APIGEE_TOKEN=$(gcloud auth print-access-token)
PATH=$$PATH:"$$PWD/tools/apigee-sackmesser/bin"
sackmesser clean all --googleapi -t "$$APIGEE_TOKEN" -o "$_APIGEE_X_ORG" --quiet
sackmesser clean all --apigeeapi -u "$$APIGEE_USER" -p "$$APIGEE_PASS" -o "$_APIGEE_ORG" --quiet
fi
env:
- 'APIGEE_ORG=$_APIGEE_ORG'
- 'APIGEE_X_ORG=$_APIGEE_X_ORG'
secretEnv:
- 'APIGEE_USER'
- 'APIGEE_PASS'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Run Pipeline'
entrypoint: 'bash'
args:
- '-c'
- |-
set -e
max_duration=8760 # cloud build timeout minus 4m
if [ -n "$_PR_NUMBER" ]; then
PR_DATA="$(curl "https://api.github.com/repos/$_REPO_GH_ISSUE/issues/$_PR_NUMBER")"
FULL_PIPELINE_REQUIRED=$(printf '%s' "$$PR_DATA" | jq '.body |= ascii_downcase | .body | contains("[x] pr requires full pipeline run")' )
SELECTED_PROJECTS_FLAG=$(printf '%s' "$$PR_DATA" | jq '.body |= ascii_downcase | .body | contains("[x] test following projects (comma separated list):")')
# get a comma-separated list of folders of changed sub-projects
CHANGED_PROJECTS=$(list-repo-changes.sh)
# test only explicity subset of projects
if [ "$$SELECTED_PROJECTS_FLAG" = "true" ]; then
PROJECTS=$(printf "$$PR_DATA" | grep -o -i -E "test following projects \(comma separated list\): *.*" | cut -d ':' -f 2 | tr -d '[:space:]')
if [ -z "$$PROJECTS" ]; then
echo "SELECTED PROJECTS is empty. Please provide a list"
PROJECTS="$$CHANGED_PROJECTS"
fi
else
PROJECTS=$$CHANGED_PROJECTS
fi
if [ "$$FULL_PIPELINE_REQUIRED" = "true" ]; then
echo "Running Full Pipeline as required in the PR"
timeout "$$max_duration" run-pipelines.sh || true
elif [ -z "$$PROJECTS" ]; then
echo "TOTAL PIPELINE (no change);pass;0" > ./pipeline-result.txt
else
echo "PR testing changes in the following projects: $$PROJECTS"
timeout "$$max_duration" run-pipelines.sh "$$PROJECTS" || true
fi
elif [ "$_CI_PROJECT" = "all" ]; then
timeout "$$max_duration" run-pipelines.sh || true
else
timeout "$$max_duration" run-pipelines.sh "$_CI_PROJECT" || true
fi
if [ ! -f ./pipeline-result.txt ]; then
echo "No Results Reported;fail;N/A" > ./pipeline-result.txt;
elif ! grep -qF "TOTAL PIPELINE" ./pipeline-result.txt; then
echo "Pipeline Timeout;fail;[max duration]" >> ./pipeline-result.txt;
fi
env:
- 'APIGEE_ENV=$_APIGEE_ENV'
- 'APIGEE_ORG=$_APIGEE_ORG'
- 'APIGEE_X_ENV=$_APIGEE_X_ENV'
- 'APIGEE_X_HOSTNAME=$_APIGEE_X_HOSTNAME'
- 'APIGEE_X_ORG=$_APIGEE_X_ORG'
- 'HYBRID_GCP_PROJECT=$_HYBRID_GCP_PROJECT'
- 'X_TRIAL_GCP_PROJECT=$_X_TRIAL_GCP_PROJECT'
secretEnv:
- 'APIGEE_USER'
- 'APIGEE_PASS'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Write pipeline results to cloud logging'
entrypoint: 'sh'
args:
- '-c'
- |-
cat ./pipeline-result.txt | ./tools/pipeline-runner/cloud-logging.sh
env:
- 'RUN_TYPE=$_RUN_TYPE'
- 'BUILD_ID=$BUILD_ID'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Create GH Comment or Issue'
entrypoint: 'sh'
args:
- '-c'
- |-
cat ./pipeline-result.txt | ./tools/pipeline-runner/github-api.sh
env:
- 'BUILD_ID=$BUILD_ID'
- 'PROJECT_ID=$PROJECT_ID'
- 'PR_NUMBER=$_PR_NUMBER'
- 'SHORT_SHA=$SHORT_SHA'
- 'REPO_GH_ISSUE=$_REPO_GH_ISSUE'
- 'CREATE_GH_ISSUE=$_CREATE_GH_ISSUE'
- 'GH_BOT_NAME=$_GH_BOT_NAME'
secretEnv:
- 'GITHUB_TOKEN'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Explicitly Fail'
entrypoint: 'sh'
args:
- '-c'
- |-
! grep -q 'fail' ./pipeline-result.txt
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/devrel_apigee_pass/versions/latest
env: APIGEE_PASS
- versionName: projects/$PROJECT_ID/secrets/devrel_apigee_user/versions/latest
env: APIGEE_USER
- versionName: projects/$PROJECT_ID/secrets/devrel_github_token/versions/latest
env: GITHUB_TOKEN
options:
machineType: 'E2_HIGHCPU_8'
logging: GCS_ONLY
timeout: 9000s # 120min (needs to be updated with max_duration of pipeline)
images: ['${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline']
substitutions:
_APIGEE_ORG: my-org
_APIGEE_ENV: my-env
_APIGEE_X_ORG: my-org
_APIGEE_X_ENV: my-env
_APIGEE_X_HOSTNAME: my-hostname
_HYBRID_GCP_PROJECT: my-gcp-project
_X_TRIAL_GCP_PROJECT: my-gcp-project
_CI_PROJECT: all # all|[path]
_CLEAN_ORG: 'true' # true|false
_CREATE_GH_ISSUE: 'false' # true|false
_REPO_GH_ISSUE: 'apigee/devrel'
_GH_BOT_NAME: 'apigee-devrel-bot'
_REGISTRY_LOCATION: europe
_RUN_TYPE: unknown
#_PR_NUMBER: '' # automatically set for PRs