From add98469c3d1534a5977762a4c5f6f97a3c8a8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Sat, 27 Jul 2024 15:16:23 -0300 Subject: [PATCH 1/4] Updated save option changes in documentation --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c4e0f5..2512ee2 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,9 @@ steps: manifest: package-lock.json path: node_modules restore: pipeline - save: file + save: + - file + - branch - wait: ~ - label: ':test_tube: Run tests' command: npm test # does not save cache, not necessary From 857e43a00a6b30362d70f702493223b5c05d155b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Sat, 27 Jul 2024 15:17:05 -0300 Subject: [PATCH 2/4] Implemented call to exists before saving --- hooks/post-command | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hooks/post-command b/hooks/post-command index 320b598..11a23cd 100755 --- a/hooks/post-command +++ b/hooks/post-command @@ -49,6 +49,11 @@ fi for LEVEL in "${SAVE_LEVELS[@]}"; do KEY=$(build_key "${LEVEL}" "${CACHE_PATH}" "${COMPRESS}") - echo "Saving ${LEVEL}-level cache of ${CACHE_PATH}" - backend_exec save "${KEY}" "${ACTUAL_PATH}" + if [ "$(plugin_read_config FORCE 'false')" != 'false' ] || + ! backend_exec exists "${KEY}"; then + echo "Saving ${LEVEL}-level cache of ${CACHE_PATH}" + backend_exec save "${KEY}" "${ACTUAL_PATH}" + else + echo "Cache of ${LEVEL} already exists, skipping" + fi done From 712c7faa67956dfe8d1d34e6b831c1f476763bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Sat, 27 Jul 2024 15:17:43 -0300 Subject: [PATCH 3/4] Added test to avoid saving if the cache already exists --- tests/post-command-tgz.bats | 3 +++ tests/post-command-zip.bats | 3 +++ tests/post-command.bats | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/tests/post-command-tgz.bats b/tests/post-command-tgz.bats index ee75654..102bc65 100644 --- a/tests/post-command-tgz.bats +++ b/tests/post-command-tgz.bats @@ -15,6 +15,9 @@ setup() { export BUILDKITE_PLUGIN_CACHE_COMPRESSION=tgz export BUILDKITE_PLUGIN_CACHE_PATH=tests/data/my_files + # to make all test easier + export BUILDKITE_PLUGIN_CACHE_FORCE=true + # necessary for key-calculations export BUILDKITE_LABEL="step-label" export BUILDKITE_BRANCH="tests" diff --git a/tests/post-command-zip.bats b/tests/post-command-zip.bats index 14eddc6..7964ea3 100644 --- a/tests/post-command-zip.bats +++ b/tests/post-command-zip.bats @@ -15,6 +15,9 @@ setup() { export BUILDKITE_PLUGIN_CACHE_COMPRESSION=zip export BUILDKITE_PLUGIN_CACHE_PATH=tests/data/my_files + # to make all test easier + export BUILDKITE_PLUGIN_CACHE_FORCE=true + # necessary for key-calculations export BUILDKITE_LABEL="step-label" export BUILDKITE_BRANCH="tests" diff --git a/tests/post-command.bats b/tests/post-command.bats index ed45264..41e1b11 100644 --- a/tests/post-command.bats +++ b/tests/post-command.bats @@ -13,6 +13,9 @@ setup() { export BUILDKITE_PLUGIN_CACHE_BACKEND=dummy export BUILDKITE_PLUGIN_CACHE_PATH=tests/data/my_files + # to make all test easier + export BUILDKITE_PLUGIN_CACHE_FORCE=true + # necessary for key-calculations export BUILDKITE_LABEL="step-label" export BUILDKITE_BRANCH="tests" @@ -179,3 +182,18 @@ teardown() { assert_output --partial 'Invalid cache level unreal' refute_output --partial 'Saving pipeline-level cache' } + +@test "Saving is skipped when cache exists" { + export BUILDKITE_PLUGIN_CACHE_SAVE=all + export BUILDKITE_PLUGIN_CACHE_FORCE='false' + + stub cache_dummy \ + "exists \* \* : exit 0" + + run "$PWD/hooks/post-command" + + assert_success + refute_output --partial 'Saving all-level cache' + + unstub cache_dummy +} From 1c722139723a4e903e69436a679e23fb5b5a74bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Fri, 26 Jul 2024 20:23:06 -0300 Subject: [PATCH 4/4] Added option to plugin schema and documentation --- README.md | 4 ++++ plugin.yml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 2512ee2..ca01fa6 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,10 @@ Assuming the underlying executables are available, the allowed values are: * `tgz`: `tar` with gzip compression * `zip`: `(un)zip` compression +### `force` (boolean, optional, save only) + +Force saving the cache even if it exists. Default: `false`. + ### `manifest` (string, required if using `file` caching level) A path to a file or folder that will be hashed to create file-level caches. diff --git a/plugin.yml b/plugin.yml index fa886c8..500b494 100644 --- a/plugin.yml +++ b/plugin.yml @@ -21,6 +21,8 @@ configuration: - zip - tar - tgz + force: + type: boolean manifest: type: string path: