Skip to content

Commit f677ca0

Browse files
committed
Refactor size check
1 parent b6db8e1 commit f677ca0

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

ci/cloudbuild/vizzu-devenv-prebuild-docker.yaml

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,35 @@ steps:
5959
- name: gcr.io/cloud-builders/gsutil
6060
args:
6161
- cp
62-
- 'gs://vizzu-lib-main/lib-size/size.txt'
62+
- 'gs://vizzu-lib-main/lib/size.txt'
6363
- '/workspace/build/cmake-wasm/weblib/size_downloaded.txt'
6464
id: download_size
6565
waitFor:
6666
- wasm_make
6767
- name: vizzu/vizzu-devenv:v0.8.x
6868
args:
69-
- bash
69+
- python3
7070
- '-c'
7171
- |
72-
threshold=1.05
73-
while IFS= read -r line; do
74-
file=$(echo "$line" | cut -d ' ' -f 1)
75-
actual_size=$(echo "$line" | cut -d ' ' -f 2)
76-
downloaded_size=$(grep "$file" /workspace/build/cmake-wasm/weblib/size_downloaded.txt | cut -d ' ' -f 2)
77-
if [[ -n "$downloaded_size" && $(echo "$actual_size > $downloaded_size * $threshold" | bc -l) -eq 1 ]]; then
78-
echo "Error: File $file size exceeds the threshold."
79-
exit 1
80-
fi
81-
done < /workspace/build/cmake-wasm/weblib/size.txt
72+
threshold = 1.05
73+
with open('/workspace/build/cmake-wasm/weblib/size.txt', 'r') as size_file:
74+
for line in size_file:
75+
file, actual_size = line.strip().split()
76+
downloaded_line = next(
77+
(d_line for d_line in open('/workspace/build/cmake-wasm/weblib/size_downloaded.txt', 'r') if d_line.startswith(file)),
78+
None
79+
)
80+
if downloaded_line:
81+
downloaded_size = downloaded_line.split()[1]
82+
if float(actual_size) > float(downloaded_size) * threshold:
83+
print(f"Error: File {file} size exceeds the threshold.")
84+
exit(1)
85+
else:
86+
print(f"Success: File {file} size comparison passed. Actual: {actual_size}, Downloaded: {downloaded_size}")
87+
else:
88+
print(f"Warning: Downloaded size not found for file {file}. Skipping comparison. Actual: {actual_size}")
89+
8290
id: check_size
83-
dir: /workspace/build/cmake-wasm
8491
waitFor:
8592
- download_size
8693
- name: vizzu/vizzu-devenv:v0.8.x
@@ -146,7 +153,7 @@ steps:
146153
echo $SHORT_SHA > sha.txt
147154
fi
148155
dir: /workspace/example
149-
id: sha_generate
156+
id: meta_generate
150157
waitFor:
151158
- test_integration
152159
entrypoint: bash
@@ -157,10 +164,11 @@ steps:
157164
if [ $BRANCH_NAME == "main" ]
158165
then
159166
gsutil -m cp '/workspace/example/sha.txt' 'gs://vizzu-lib-main/lib'
167+
gsutil -m cp '/workspace/build/cmake-wasm/weblib/size.txt' 'gs://vizzu-lib-main/lib'
160168
fi
161-
id: sha_upload
169+
id: meta_upload
162170
waitFor:
163-
- sha_generate
171+
- meta_generate
164172
entrypoint: bash
165173
- name: gcr.io/cloud-builders/gsutil
166174
args:
@@ -169,7 +177,6 @@ steps:
169177
if [ $BRANCH_NAME == "main" ]
170178
then
171179
gsutil -m cp -r '/workspace/example/lib/*' 'gs://vizzu-lib-main/lib'
172-
gsutil -m cp '/workspace/build/cmake-wasm/weblib/size.txt' 'gs://vizzu-lib-main/lib-size/size.txt'
173180
fi
174181
id: lib_upload
175182
waitFor:

0 commit comments

Comments
 (0)