From 9df88756461e8c58839498a478eefe34d2b753c4 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 4 Dec 2023 18:03:19 +0000 Subject: [PATCH] feat: allow specifying cache directories --- .bazelignore | 1 + .gitlab-ci.yml | 3 --- README.md | 16 ++++++++++++++-- template.yml | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/.bazelignore b/.bazelignore index d020514..826a06a 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1,2 +1,3 @@ rules_download rules_toolchain +.cache diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f9ffccc..a3c3765 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,9 +14,6 @@ bootstrap: image: node:lts variables: NPM_CACHE: "${CI_PROJECT_DIR}/.cache/npm" - cache: - key: "bazelisk-node-0" - paths: !reference [.bazelisk, cache, paths] before_script: - | cat <<"EOF" | tee /usr/local/bin/bazelisk diff --git a/README.md b/README.md index 46c947e..1dd4462 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,20 @@ custom: extends: .bazelisk script: - !reference [.bazelisk-fragment, rc] - - bazelisk build //... - - bazelisk run //... + - | + bazelisk \ + --output_user_root=$BAZEL_OUTPUT_USER_ROOT \ + build \ + --disk_cache=$BAZEL_DISK_CACHE \ + --repository_cache=$BAZEL_REPOSITORY_CACHE \ + //... + - | + bazelisk \ + --output_user_root=$BAZEL_OUTPUT_USER_ROOT \ + run \ + --disk_cache=$BAZEL_DISK_CACHE \ + --repository_cache=$BAZEL_REPOSITORY_CACHE \ + //... ``` [gitlab-ci-reference]: https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags diff --git a/template.yml b/template.yml index 9c44a05..a0e5a36 100644 --- a/template.yml +++ b/template.yml @@ -18,8 +18,22 @@ spec: default: //... root: default: . - key: - default: "bazelisk-1" + bazelisk_home: + default: "$CI_PROJECT_DIR/.cache/bazelisk" + bazelisk_home_key: + default: "bazelisk-home" + output_user_root: + default: "$CI_PROJECT_DIR/.cache/bazel-output-user-root" + output_user_root_key: + default: "bazel-output-user-root" + disk_cache: + default: "$CI_PROJECT_DIR/.cache/bazel-disk-cache" + disk_cache_key: + default: "bazel-disk-cache" + repository_cache: + default: "$CI_PROJECT_DIR/.cache/bazel-repository-cache" + repository_cache_key: + default: "bazel-repository-cache" --- .bazelisk-fragment: rc: @@ -34,7 +48,12 @@ spec: execute: - cd "${ROOT}" - > - "$[[inputs.bazelisk]]" "$[[inputs.command]]" "$[[inputs.target]]" + "$[[inputs.bazelisk]]" \ + "--output_user_root=$[[inputs.output_user_root]]" \ + "$[[inputs.command]]" \ + "--disk_cache=$[[inputs.disk_cache]]" \ + "--repository_cache=$[[inputs.repository_cache]]" \ + "$[[inputs.target]]" - cd - testlogs: # https://gitlab.com/gitlab-org/gitlab/-/issues/19746 - | @@ -57,12 +76,27 @@ spec: image: "$[[inputs.image]]:$[[inputs.tag]]" variables: ROOT: "$[[inputs.root]]" - BAZELISK_HOME: "${CI_PROJECT_DIR}/.cache/bazelisk" + BAZELISK_HOME: "$[[inputs.bazelisk_home]]" + BAZEL_OUTPUT_USER_ROOT: "$[[inputs.output_user_root]]" + BAZEL_DISK_CACHE: "$[[inputs.disk_cache]]" + BAZEL_REPOSITORY_CACHE: "$[[inputs.repository_cache]]" cache: - key: "$[[inputs.key]]" - paths: - - ".cache" - when: always + - key: "$[[inputs.bazelisk_home_key]]" + paths: + - "$[[inputs.bazelisk_home]]" + when: always + - key: "$[[inputs.output_user_root_key]]" + paths: + - "$[[inputs.output_user_root]]" + when: always + - key: "$[[inputs.repository_cache_key]]" + paths: + - "$[[inputs.repository_cache]]" + when: always + - key: "$[[inputs.disk_cache_key]]" + paths: + - "$[[inputs.disk_cache]]" + when: always script: - !reference [.bazelisk-fragment, rc] - !reference [.bazelisk-fragment, execute] -- GitLab