forked from bitrise-steplib/steps-cache-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitrise.yml
485 lines (440 loc) · 15.2 KB
/
bitrise.yml
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
format_version: 6
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
app:
envs:
# define these in your .bitrise.secrets.yml
- BITRISE_CACHE_API_URL: $BITRISE_CACHE_API_URL # use file url scheme (file://) to create a cache archive in a local directory
- ORIG_BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR
workflows:
test:
before_run:
- audit-this-step
after_run:
- smoke_test
- ignore_path_test
- generic_fs_checks
- test-stack-version
# - backward_compatibility_test
steps:
- go-list:
- golint:
- errcheck:
- go-test:
- codecov:
run_if: .IsCI
inputs:
- other_options: -f ${GO_CODE_COVERAGE_REPORT_PATH}
- CODECOV_TOKEN: "$CODECOV_UPLOAD_TOKEN"
backward_compatibility_test:
description: |
Tests if the cache descriptor file is not changed compared to the previous stable step version.
envs:
- TMP_DIR: $ORIG_BITRISE_SOURCE_DIR/_tmp3
- CACHE_PATH: |
$BITRISE_CACHE_DIR
./_sample_artifacts/filestructure -> ./_sample_artifacts/filestructure/build/findme.test
./DoesNotExist/
./DoesNotExist
~/DoesNotExist
/Does/not/exists
~/.android -> ~/.lockfile
./_sample_artifacts/ipas
./_sample_artifacts/ipas/
./_sample_artifacts/filestructure/build/test.bin
- IGNORE_PATH: |-
./_sample_artifacts/filestructure/sub-dir
~/DoesNotExists/This
!~/.android/dir
*.apk
!./_sample_artifacts/filestructure/*.txt
steps:
- script:
title: Cleanup $TMP_DIR and archive tmp files
inputs:
- content: rm -rf "$TMP_DIR" "/tmp/cache-archive.tar" "/tmp/cache-info.json"
- change-workdir:
title: Switch working dir to $TMP_DIR
inputs:
- path: $TMP_DIR
- is_create_path: true
- script:
title: Download assets
inputs:
- content: git clone https://github.com/bitrise-samples/sample-artifacts.git $TMP_DIR/_sample_artifacts
- cache-push:
title: Latest released version
run_if: true
is_skippable: false
inputs:
- is_debug_mode: true
- cache_paths: $CACHE_PATH
- ignore_check_on_paths: $IGNORE_PATH
- script:
title: Extract cache and save the cache descriptor
is_always_run: true
inputs:
- content: |-
#!/bin/bash
set -ex
# extract the archive to get the current stable step version's cache descriptor file
tar -xPf /tmp/cache-archive.tar
mv "/tmp/cache-info.json" "/tmp/cache-info_orig.json"
# restore the workdir for the in-progress step version
rm -rf $TMP_DIR/*
git clone https://github.com/bitrise-samples/sample-artifacts.git $TMP_DIR/_sample_artifacts
- path::./:
title: in-progress version
run_if: true
is_skippable: false
inputs:
- is_debug_mode: true
- cache_paths: $CACHE_PATH
- ignore_check_on_paths: $IGNORE_PATH
- script:
title: Compare cache descriptors
run_if: true
inputs:
- content: |-
#!/bin/bash
set -ex
# extract the archive to get the in-progress version's cache descriptor file
tar -xPf /tmp/cache-archive.tar
# check if the current stable step version's cache descriptor file is identical to the
# in-progress step version's cache descriptor file
if [ "$(cat /tmp/cache-info_orig.json)" != "$(cat /tmp/cache-info.json)" ] ; then
echo "Cache descriptor file changed"
cp "/tmp/cache-info.json" "$BITRISE_DEPLOY_DIR/cache-info.json"
cp "/tmp/cache-info_orig.json" "$BITRISE_DEPLOY_DIR/cache-info_orig.json"
exit 1
fi
smoke_test:
description: |
Simple test to make sure the step is able to cache files
using some exclude and include paths.
envs:
- TMP_DIR: $ORIG_BITRISE_SOURCE_DIR/_tmp1
steps:
- script:
title: Cleanup $TMP_DIR and archive tmp files
inputs:
- content: rm -rf "$TMP_DIR" "/tmp/cache-archive.tar" "/tmp/cache-info.json"
- change-workdir:
title: Switch working dir to $TMP_DIR
inputs:
- path: $TMP_DIR
- is_create_path: true
- script:
title: Download assets
inputs:
- content: git clone https://github.com/bitrise-samples/sample-artifacts.git $TMP_DIR/_sample_artifacts
- change-workdir:
title: Switch working dir to $TMP_DIR/_workdir
run_if: true
inputs:
- path: $TMP_DIR/_workdir
- is_create_path: true
- path::./:
title: Step Test
run_if: true
is_skippable: false
inputs:
- is_debug_mode: true
- cache_paths: |
$BITRISE_CACHE_DIR
../_sample_artifacts/filestructure -> ../_sample_artifacts/filestructure/build/findme.test
./DoesNotExist/
./DoesNotExist
~/DoesNotExist
/Does/not/exists
~/.android -> ~/.lockfile
../_sample_artifacts/ipas
../_sample_artifacts/ipas/
../_sample_artifacts/filestructure/build/test.bin
- ignore_check_on_paths: |-
../_sample_artifacts/filestructure/sub-dir
~/DoesNotExists/This
!~/.android/dir
*.apk
ignore_path_test:
description: |
Tests if ignored file's change does not triggers new cache creation.
An ignored file (in the cache archive) should remain as it was originally,
even if it gets modified (locally) betweeen two cache push step runs.
envs:
- TMP_DIR: $ORIG_BITRISE_SOURCE_DIR/_tmp2
- CACHE_PATH: |
$TMP_DIR
- IGNORE_PATH: |
$TMP_DIR/test_ignorechanges.txt
!*.mp3
steps:
- script:
title: Cleanup $TMP_DIR and archive tmp files
inputs:
- content: rm -rf "$TMP_DIR" "/tmp/cache-archive.tar" "/tmp/cache-info.json"
- change-workdir:
title: Switch working dir to $TMP_DIR
inputs:
- path: $TMP_DIR
- is_create_path: true
- script:
title: Create sample files
is_always_run: true
inputs:
- content: |-
#!/bin/bash
set -ex
# should follow changes
echo "content" > $TMP_DIR/test_file1.txt
# should not exists
echo "content" > $TMP_DIR/test_exclude_ext.mp3
# should exists but ignore changes
echo "content" > $TMP_DIR/test_ignorechanges.txt
- path::./:
title: Step Test
is_always_run: true
run_if: true
is_skippable: false
inputs:
- compress_archive: true
- is_debug_mode: true
- cache_paths: $CACHE_PATH
- ignore_check_on_paths: $IGNORE_PATH
- script:
title: Store MD5 hash of an ignored file and modify it
is_always_run: true
inputs:
- content: |-
#!/bin/bash
set -ex
# remove TMP_DIR to cleanup test_ignorechanges.txt file
rm -rf $TMP_DIR
# extract the archive to get the archived test_ignorechanges.txt file
tar -xPf /tmp/cache-archive.tar
# export the MD5 hash of test_ignorechanges.txt file
# this file's content should remain as it is (in the archive) even if it gets modified
# since this files is in ignore list and no other files changed
mymd5=`which md5sum` || mymd5=`which md5`
FILEMD5=`$mymd5 < $TMP_DIR/test_ignorechanges.txt`
envman add --key MD5PREVIOUSLY --value "${FILEMD5}"
# following cache should not update the archive even if this file changes
echo "content" >> $TMP_DIR/test_ignorechanges.txt
# .mp3 is part of the exclude list, should not exists
if [ -f $TMP_DIR/test_exclude_ext.mp3 ]; then
echo "File exists."
exit 1
fi
- path::./:
title: Step Test
is_always_run: true
run_if: true
is_skippable: false
inputs:
- compress_archive: true
- is_debug_mode: true
- cache_paths: $CACHE_PATH
- ignore_check_on_paths: $IGNORE_PATH
- script:
title: Check if MD5 matches the previous one
is_always_run: true
inputs:
- content: |-
#!/bin/bash
set -ex
# remove TMP_DIR to cleanup test_ignorechanges.txt file
rm -rf $TMP_DIR
# extract the archive to get the archived test_ignorechanges.txt file
tar -xPf /tmp/cache-archive.tar
# test_ignorechanges.txt was part of the ignore list, so it's change should not present in the archive
mymd5=`which md5sum` || mymd5=`which md5`
MD5CURRENT=`$mymd5 < $TMP_DIR/test_ignorechanges.txt`
if [ "$MD5CURRENT" != "$MD5PREVIOUSLY" ]; then
echo "MD5 changed."
exit 1
fi
# .mp3 is part of the exclude list, should not exists
if [ -f $TMP_DIR/test_exclude_ext.mp3 ]; then
echo "File exists."
exit 1
fi
generic_fs_checks:
description: |
Tests if most of the FS file types are supported.
envs:
- TMP_DIR: $ORIG_BITRISE_SOURCE_DIR/_tmp_fs_check
- CACHE_PATH: $TMP_DIR/cache
- LINKED_FILES: $TMP_DIR/target
steps:
- script:
title: Cleanup $TMP_DIR and archive tmp files
inputs:
- content: rm -rf "$TMP_DIR" "/tmp/cache-archive.tar" "/tmp/cache-info.json"
- change-workdir:
title: Switch working dir to $CACHE_PATH
inputs:
- path: $CACHE_PATH
- is_create_path: true
- script:
title: Create sample files
is_always_run: true
inputs:
- content: |-
#!/bin/bash
set -ex
# file in root
echo "content" > $CACHE_PATH/test_file1.txt
# big file in root
head -c 1073741825 </dev/urandom > $CACHE_PATH/test_big_random_file1.data
# file in subdir
mkdir $CACHE_PATH/subdir
echo "content" > $CACHE_PATH/subdir/test_file.mp3
# single dir
mkdir $CACHE_PATH/single_dir
mkdir $LINKED_FILES
# symlink to a temp file
rm -rf $LINKED_FILES/test_cache_file.txt
echo "content" > $LINKED_FILES/test_cache_file.txt
ln -s $LINKED_FILES/test_cache_file.txt $CACHE_PATH/mysymlink
ln $LINKED_FILES/test_cache_file.txt $CACHE_PATH/myhardlink
# symlink to a non-existent file
cd $CACHE_PATH
ln -s nonexistent_target $CACHE_PATH/invalid_symlink
# symlink to a directory
ln -s $LINKED_FILES $CACHE_PATH/symlink_dir
- path::./:
title: Step Test
is_always_run: true
run_if: true
is_skippable: false
inputs:
- compress_archive: true
- is_debug_mode: true
- cache_paths: $CACHE_PATH
- script:
title: Check if stored structure exists
is_always_run: true
inputs:
- content: |-
#!/bin/bash
set -ex
# remove CACHE_PATH to cleanup
rm -rf $CACHE_PATH
mkdir $CACHE_PATH
cd $CACHE_PATH
# extract the archive
tar -xPf /tmp/cache-archive.tar
if [ ! -d $CACHE_PATH/single_dir ]; then
echo "dir should exist"
exit 1
fi
if [ ! -f $CACHE_PATH/test_file1.txt ]; then
echo "file should exist"
exit 1
fi
if [ ! -f $CACHE_PATH/test_big_random_file1.data ]; then
echo "file should exist"
exit 1
fi
if [ ! -f $CACHE_PATH/subdir/test_file.mp3 ]; then
echo "file should exist"
exit 1
fi
if [ ! -f $CACHE_PATH/mysymlink ]; then
echo "file should exist"
exit 1
fi
if [ ! -f $CACHE_PATH/myhardlink ]; then
echo "file should exist"
exit 1
fi
if [ "$(< $CACHE_PATH/myhardlink)" != "$(< $LINKED_FILES/test_cache_file.txt)" ]; then
echo "file content mismatch"
exit 1
fi
if [ "$($CACHE_PATH/mysymlink)" != "$($LINKED_FILES/test_cache_file.txt)" ]; then
echo "symlink path mismatch"
exit 1
fi
if [ ! -L $CACHE_PATH/invalid_symlink ]; then
echo "symlink does not exist"
exit 1
fi
if [ $(cd -P "$CACHE_PATH/symlink_dir" && pwd) != "$LINKED_FILES" ]; then
echo "symlink directory path mismatch"
exit 1
fi
test-stack-version:
description: |
Test that archive_info.json containing stack ID is created.
envs:
- TMP_DIR: $ORIG_BITRISE_SOURCE_DIR/_tmp_stack_version
- CACHE_PATH: |
$TMP_DIR
steps:
- script:
title: Cleanup $TMP_DIR and archive tmp files
inputs:
- content: rm -rf "$TMP_DIR" "/tmp/cache-archive.tar" "/tmp/cache-info.json"
- change-workdir:
title: Switch working dir to $TMP_DIR
inputs:
- path: $TMP_DIR
- is_create_path: true
- script:
title: Create sample files
inputs:
- content: |-
#!/bin/bash
set -ex
# file in root
echo "content" > $TMP_DIR/test_file1.txt
- path::./:
title: Step Test
is_always_run: true
run_if: true
is_skippable: false
inputs:
- compress_archive: true
- is_debug_mode: true
- cache_paths: $CACHE_PATH
- script:
title: Check that archive_info.json exists
inputs:
- content: |-
#!/bin/env bash
set -ex
# remove TMP_DIR to cleanup
rm -rf $TMP_DIR
# extract the archive
firstfile="$(tar -b 1024 -tf /tmp/cache-archive.tar | while read item ; do [[ "$item" =~ .* ]] && echo "$item" && break ; done )"
echo $firstfile
if [ $firstfile != "/tmp/archive_info.json" ]; then
echo "archive_info.json not found as first file in archive"
exit 1
fi
# ----------------------------------------------------------------
# --- Utility workflows
dep-update:
title: Dep update
description: |
Used for updating bitrise dependencies with dep
steps:
- script:
title: Dependency update
inputs:
- content: |-
#!/bin/bash
set -ex
go get -u -v github.com/golang/dep/cmd/dep
dep ensure -v
dep ensure -v -update
# ----------------------------------------------------------------
# --- workflows to Share this step into a Step Library
audit-this-step:
steps:
- script:
inputs:
- content: |-
#!/bin/bash
set -ex
stepman audit --step-yml ./step.yml