Skip to content

Commit 735d5e7

Browse files
authored
Clean up CCI cache handling (#1238)
1. Add `generate_cachekey` and `fetch_cachekey` command that abstracts away the way cache key is generated. 2. Fix the daily cache key. `date +%D` (the previous `"+%Y-%d"` does not change on daily basis) 3. Remove conda environment cache for simplicity (this is no longer the bottleneck and having cached conda env often causes more trouble when macOS test is enabled.)
1 parent 34ccda8 commit 735d5e7

File tree

2 files changed

+97
-313
lines changed

2 files changed

+97
-313
lines changed

.circleci/config.yml

Lines changed: 48 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ commands:
3939
if [[ "${PYTHON_VERSION}" = *3.9* ]]; then
4040
echo "export CONDA_CHANNEL_FLAGS=-c=conda-forge" >> ${BASH_ENV}
4141
fi
42+
generate_cachekey:
43+
description: "Generate .cachekey file that changes on daily basis"
44+
steps:
45+
- run:
46+
name: Generate CCI cache key
47+
command: echo "$(date "+%D")" > .cachekey
48+
- persist_to_workspace:
49+
root: .
50+
paths:
51+
- .cachekey
52+
fetch_cachekey:
53+
description: "Fetch the .cachekey file that is generated by generate_cachekey job"
54+
steps:
55+
- attach_workspace:
56+
at: .
4257

4358
binary_common: &binary_common
4459
parameters:
@@ -356,64 +371,34 @@ jobs:
356371
- checkout
357372
- designate_upload_channel
358373
- load_conda_channel_flags
359-
- run:
360-
name: Generate cache key
361-
# This will refresh cache on Sundays, nightly build should generate new cache.
362-
command: |
363-
echo "$(date +"Year-Week %Y-%U")" > .circleci-weekly
364-
echo "$(date +"Year-Date %Y-%d")" > .circleci-daily-linux
365-
- persist_to_workspace:
366-
root: .
367-
paths:
368-
- .circleci-daily-linux
374+
- generate_cachekey
369375
- restore_cache:
370376
keys:
371377

372-
- data-linux-v1-{{ checksum ".circleci-daily-linux" }}
378+
- v1-linux-cache-index-{{ checksum ".cachekey" }}
373379

374380
- run:
375-
name: Exit if cache exists
381+
name: Generate cache
382+
no_output_timeout: 30m
376383
command: |
377-
FILE=.data/cache_status_file.json
378-
if test -f "$FILE"; then
379-
cat $FILE
380-
circleci step halt
381-
else
382-
echo "$FILE does not exists"
384+
if [ ! -f .data/cache_status_file.json ] ; then
385+
.circleci/unittest/linux/scripts/setup_env.sh
386+
.circleci/unittest/linux/scripts/install.sh
387+
.circleci/unittest/linux/scripts/generate_cache.sh
383388
fi
384-
- restore_cache:
385-
386-
keys:
387-
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
388-
389-
- run:
390-
name: Setup
391-
command: .circleci/unittest/linux/scripts/setup_env.sh
389+
cat .data/cache_status_file.json
392390
- save_cache:
393391

394-
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
392+
key: v1-linux-dataset-{{ checksum ".cachekey" }}
395393

396394
paths:
397-
- conda
398-
- env
399-
- run:
400-
name: Install torchtext
401-
command: .circleci/unittest/linux/scripts/install.sh
402-
- run:
403-
name: Generate daily data Cache
404-
no_output_timeout: 30m
405-
command: |
406-
.circleci/unittest/linux/scripts/generate_cache.sh
407-
cat .data/cache_status_file.json
395+
- .data
408396
- save_cache:
409397

410-
key: data-linux-v1-{{ checksum ".circleci-daily-linux" }}
398+
key: v1-linux-cache-index-{{ checksum ".cachekey" }}
411399

412400
paths:
413-
- .data
414-
- run:
415-
name: Post process
416-
command: .circleci/unittest/linux/scripts/post_process.sh
401+
- .data/cache_status_file.json
417402

418403
unittest_linux:
419404
<<: *binary_common
@@ -424,40 +409,18 @@ jobs:
424409
- checkout
425410
- designate_upload_channel
426411
- load_conda_channel_flags
427-
- attach_workspace:
428-
at: .
429-
- run:
430-
name: Generate cache key
431-
# This will refresh cache on Sundays, nightly build should generate new cache.
432-
command: |
433-
echo "$(date +"Year-Week %Y-%U")" > .circleci-weekly
434-
- restore_cache:
435-
436-
keys:
437-
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
438-
412+
- fetch_cachekey
439413
- run:
440414
name: Setup
441415
command: .circleci/unittest/linux/scripts/setup_env.sh
442-
- save_cache:
443-
444-
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
445-
446-
paths:
447-
- conda
448-
- env
449416
- run:
450417
name: Install torchtext
451418
command: .circleci/unittest/linux/scripts/install.sh
452419
- restore_cache:
453420
keys:
454421

455-
- data-linux-v1-{{ checksum ".circleci-daily-linux" }}
456-
457-
- restore_cache:
458-
keys:
459-
460-
- data-vector-linux-v1-{{ checksum ".circleci-daily-linux" }}
422+
- v1-linux-dataset-vector-{{ checksum ".cachekey" }}
423+
- v1-linux-dataset-{{ checksum ".cachekey" }}
461424

462425
- run:
463426
name: Run tests
@@ -466,7 +429,7 @@ jobs:
466429
command: .circleci/unittest/linux/scripts/run_test.sh
467430
- save_cache:
468431

469-
key: data-vector-linux-v1-{{ checksum ".circleci-daily-linux" }}
432+
key: v1-linux-dataset-vector-{{ checksum ".cachekey" }}
470433

471434
paths:
472435
- .vector_cache
@@ -485,67 +448,34 @@ jobs:
485448
- checkout
486449
- designate_upload_channel
487450
- load_conda_channel_flags
488-
- run:
489-
name: Generate cache key
490-
# This will refresh cache on Sundays, nightly build should generate new cache.
491-
command: |
492-
echo "$(date +"Year-Week %Y-%U")" > .circleci-weekly
493-
echo "$(date +"Year-Date %Y-%d")" > .circleci-daily-win
494-
- persist_to_workspace:
495-
root: .
496-
paths:
497-
- .circleci-daily-win
451+
- generate_cachekey
498452
- restore_cache:
499453
keys:
500454

501-
- data-windows-v1-{{ checksum ".circleci-daily-win" }}
502-
503-
- run:
504-
name: Exit if cache exists
505-
command: |
506-
FILE=.data/cache_status_file.json
507-
if test -f "$FILE"; then
508-
cat $FILE
509-
circleci step halt
510-
else
511-
echo "$FILE does not exists"
512-
fi
513-
- restore_cache:
514-
515-
keys:
516-
- env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
517-
518-
- run:
519-
name: Setup
520-
command: .circleci/unittest/windows/scripts/setup_env.sh
521-
- save_cache:
522-
523-
key: env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
455+
- v1-windows-cache-index-{{ checksum ".cachekey" }}
524456

525-
paths:
526-
- conda
527-
- env
528-
- run:
529-
name: Install torchtext
530-
command: .circleci/unittest/windows/scripts/install.sh
531457
- run:
532458
name: Generate daily data Cache
533459
no_output_timeout: 30m
534460
command: |
535-
.circleci/unittest/windows/scripts/generate_cache.sh
461+
if [ ! -f .data/cache_status_file.json ] ; then
462+
.circleci/unittest/windows/scripts/setup_env.sh
463+
.circleci/unittest/windows/scripts/install.sh
464+
.circleci/unittest/windows/scripts/generate_cache.sh
465+
fi
536466
cat .data/cache_status_file.json
537467
- save_cache:
538468

539-
key: data-windows-v1-{{ checksum ".circleci-daily-win" }}
469+
key: v1-windows-dataset-{{ checksum ".cachekey" }}
540470

541471
paths:
542472
- .data
543-
- run:
544-
name: Post process
545-
command: .circleci/unittest/windows/scripts/post_process.sh
546-
473+
- save_cache:
547474

475+
key: v1-windows-cache-index-{{ checksum ".cachekey" }}
548476

477+
paths:
478+
- .data/cache_status_file.json
549479

550480
unittest_windows:
551481
<<: *binary_common
@@ -555,40 +485,18 @@ jobs:
555485
- checkout
556486
- designate_upload_channel
557487
- load_conda_channel_flags
558-
- attach_workspace:
559-
at: .
560-
- run:
561-
name: Generate cache key
562-
# This will refresh cache on Sundays, nightly build should generate new cache.
563-
command: |
564-
echo "$(date +"Year-Week %Y-%U")" > .circleci-weekly
565-
- restore_cache:
566-
567-
keys:
568-
- env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
569-
488+
- fetch_cachekey
570489
- run:
571490
name: Setup
572491
command: .circleci/unittest/windows/scripts/setup_env.sh
573-
- save_cache:
574-
575-
key: env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
576-
577-
paths:
578-
- conda
579-
- env
580492
- run:
581493
name: Install torchtext
582494
command: .circleci/unittest/windows/scripts/install.sh
583495
- restore_cache:
584496
keys:
585497

586-
- data-windows-v1-{{ checksum ".circleci-daily-win" }}
587-
588-
- restore_cache:
589-
keys:
590-
591-
- data-vector-windows-v1-{{ checksum ".circleci-daily-win" }}
498+
- v1-windows-dataset-vector-{{ checksum ".cachekey" }}
499+
- v1-windows-dataset-{{ checksum ".cachekey" }}
592500

593501

594502
- run:
@@ -598,7 +506,7 @@ jobs:
598506
command: .circleci/unittest/windows/scripts/run_test.sh
599507
- save_cache:
600508

601-
key: data-vector-windows-v1-{{ checksum ".circleci-daily-win" }}
509+
key: v1-windows-dataset-vector-{{ checksum ".cachekey" }}
602510

603511
paths:
604512
- .vector_cache
@@ -617,25 +525,9 @@ jobs:
617525
steps:
618526
- checkout
619527
- designate_upload_channel
620-
- run:
621-
name: Generate cache key
622-
# This will refresh cache on Sundays, nightly build should generate new cache.
623-
command: echo "$(date +"Year-Week %Y-%U")" > .circleci-weekly
624-
- restore_cache:
625-
626-
keys:
627-
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
628-
629528
- run:
630529
name: Setup
631530
command: .circleci/unittest/linux/scripts/setup_env.sh
632-
- save_cache:
633-
634-
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
635-
636-
paths:
637-
- conda
638-
- env
639531
- run:
640532
name: Run style check
641533
command: .circleci/unittest/linux/scripts/run_style_checks.sh

0 commit comments

Comments
 (0)