forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 28
/
build-test-gcs-store.xml
186 lines (146 loc) · 5.49 KB
/
build-test-gcs-store.xml
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
175
176
177
178
179
180
181
182
183
184
185
186
<?xml version="1.0"?>
<project basedir="." name="portal-test-gcs-store" xmlns:antelope="antlib:ise.antelope.tasks">
<import file="build-test.xml" />
<macrodef name="delete-gcs-buckets">
<sequential>
<local name="bucket.list" />
<exec executable="gcloud" outputproperty="bucket.list">
<arg line="storage ls --project=liferay-qa-automated-tests --json" />
</exec>
<script language="javascript"><![CDATA[
var bucketList = project.getProperty("bucket.list");
var expiredBuckets = [];
var json = JSON.parse(bucketList);
for (var i = 0; i < json.length; i++) {
var bucket = json[i];
var name = JSON.stringify(bucket.metadata.name);
if (name.indexOf('lfr-qa-poshi-test') > -1) {
var createDate = bucket.metadata.timeCreated;
createDate = createDate.replace(/\..*/,'');
var currentDate = new Date();
var bucketDate = new Date(createDate);
var diffHours = (currentDate - bucketDate) / (1000 * 60 * 60);
if (diffHours > 12) {
expiredBuckets.push(name);
}
}
}
project.setProperty("expired.buckets", expiredBuckets.toString());]]>
</script>
<for list="${expired.buckets}" param="delete.name">
<sequential>
<echo>Expired Bucket: @{delete.name}</echo>
<exec executable="gsutil">
<arg line="rm -r gs://@{delete.name}" />
</exec>
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="generate-gcs-json">
<attribute default="${google.cloud.store.private.key.id}" name="google.cloud.store.private.key.id" />
<attribute default="${google.cloud.store.private.key.json}" name="google.cloud.store.private.key.json" />
<attribute default="${google.cloud.store.client.id}" name="google.cloud.store.client.id" />
<sequential>
<echo file="${liferay.home}/.gcs_key.json"><![CDATA[{
"type": "service_account",
"project_id": "liferay-qa-automated-tests",
"private_key_id": "${google.cloud.store.private.key.id}",
"private_key": "${google.cloud.store.private.key.json}",
"client_email": "liferay-qa-automated-tests@liferay-qa-automated-tests.iam.gserviceaccount.com",
"client_id": "${google.cloud.store.client.id}",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/liferay-qa-automated-tests%40liferay-qa-automated-tests.iam.gserviceaccount.com"
}]]></echo>
</sequential>
</macrodef>
<target name="assert-document-in-bucket">
<local name="bucket.objects" />
<exec executable="gcloud" outputproperty="bucket.objects">
<arg line="storage ls --recursive gs://lfr-qa-poshi-test-${gcs.bucket.id}/${company.id}/${group.id} --project=liferay-qa-automated-tests" />
</exec>
<echo>${bucket.objects}</echo>
<if>
<contains string="${bucket.objects}" substring="1.0" />
<then>
<echo>Document is in the bucket.</echo>
</then>
<else>
<fail>Document is not in the bucket.</fail>
</else>
</if>
</target>
<target name="assert-document-in-bucket-folder">
<local name="bucket.objects" />
<exec executable="gcloud" outputproperty="bucket.objects">
<arg line="storage ls --recursive gs://lfr-qa-poshi-test-${gcs.bucket.id}/${company.id}/${group.id}/${folder.name} --project=liferay-qa-automated-tests" />
</exec>
<echo>${bucket.objects}</echo>
<if>
<contains string="${bucket.objects}" substring="1.0" />
<then>
<echo>Document is in the bucket.</echo>
</then>
<else>
<fail>Document is not in the bucket.</fail>
</else>
</if>
</target>
<target name="assert-no-document-in-bucket">
<local name="bucket.objects" />
<exec executable="gcloud" outputproperty="bucket.objects">
<arg line="storage ls --recursive gs://lfr-qa-poshi-test-${gcs.bucket.id}/${company.id} --project=liferay-qa-automated-tests" />
</exec>
<echo>${bucket.objects}</echo>
<if>
<not>
<contains string="${bucket.objects}" substring="${group.id}" />
</not>
<then>
<echo>There is no document in bucket from Group ${group.id}</echo>
</then>
<else>
<fail>There is document in bucket from Group ${group.id}.</fail>
</else>
</if>
</target>
<target name="configure-gcs-cli">
<generate-gcs-json />
<exec executable="gcloud" outputproperty="configuration.output">
<arg line="auth activate-service-account liferay-qa-automated-tests@liferay-qa-automated-tests.iam.gserviceaccount.com --key-file=${liferay.home}/.gcs_key.json" />
</exec>
<if>
<contains string="${configuration.output}" substring="Activated service account credentials" />
<then>
<echo>Activated service account credentials.</echo>
</then>
<else>
<fail>Activation failed.</fail>
</else>
</if>
</target>
<target name="create-gcs-bucket">
<local name="bucket.create.output" />
<exec executable="gcloud" outputproperty="bucket.create.output">
<arg line="storage buckets create gs://lfr-qa-poshi-test-${gcs.bucket.id} --project=liferay-qa-automated-tests" />
</exec>
<echo>${bucket.create.output}</echo>
<if>
<not>
<contains string="${bucket.create.output}" substring="lfr-qa-poshi-test-${gcs.bucket.id}" />
</not>
<then>
<fail>Bucket was not created.</fail>
</then>
</if>
</target>
<target name="delete-gcs-bucket">
<exec executable="gsutil">
<arg line="rm -r gs://lfr-qa-poshi-test-${gcs.bucket.id}" />
</exec>
<delete-gcs-buckets />
<delete file="${liferay.home}/.gcs_key.json" />
</target>
</project>