forked from apigee/devrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild.yaml
159 lines (156 loc) · 5.57 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
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
# 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/cloud-builders/docker'
id: 'Pull Image Cache'
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/$PROJECT_ID/devrel-pipeline:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
id: 'Build Image'
args:
- 'build'
- '-f'
- './tools/pipeline-runner/Dockerfile'
- '-t'
- 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- '--cache-from'
- 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- './tools/pipeline-runner'
- name: 'gcr.io/$PROJECT_ID/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: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
id: 'Run Pipeline'
entrypoint: "bash"
args:
- "-c"
- |-
max_duration=6960 # cloud build timeout minus 4m
if [ -n "$_PR_NUMBER" ]; then
FULL_PIPELINE_REQUIRED=$(curl "https://api.github.com/repos/$_REPO_GH_ISSUE/issues/$_PR_NUMBER" | jq '.body |= ascii_downcase | .body | contains("[x] pr requires full pipeline run")' )
PROJECTS=$(list-repo-changes.sh)
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 includes changes in $$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: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
id: 'Write pipeline results to cloud logging'
entrypoint: "bash"
args:
- "-c"
- |-
cat ./pipeline-result.txt | cloud-logging.sh
- name: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
id: 'Create GH Comment or Issue'
entrypoint: "bash"
args:
- "-c"
- |-
cat ./pipeline-result.txt | 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: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
id: 'Explicitly Fail'
entrypoint: "bash"
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: 7200s # 120min (needs to be updated with max_duration of pipeline)
images: ['gcr.io/$PROJECT_ID/devrel-pipeline:latest']
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"
_RUN_TYPE: "unknown"
#_PR_NUMBER: "" # automatically set for PRs