"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "17c45c39ed5b3e26bf6240ef4a95bc97b4e7fe09"
Unverified Commit 30c172fc authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Separate CircleCI cache between `main` and `pull` (or other branches) (#24886)



* fix

* fix

* fix

---------
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
parent dd49404a
...@@ -86,6 +86,11 @@ class CircleCIJob: ...@@ -86,6 +86,11 @@ class CircleCIJob:
def to_dict(self): def to_dict(self):
env = COMMON_ENV_VARIABLES.copy() env = COMMON_ENV_VARIABLES.copy()
env.update(self.additional_env) env.update(self.additional_env)
cache_branch_prefix = os.environ.get("CIRCLE_BRANCH", "pull")
if cache_branch_prefix != "main":
cache_branch_prefix = "pull"
job = { job = {
"working_directory": self.working_directory, "working_directory": self.working_directory,
"docker": self.docker_image, "docker": self.docker_image,
...@@ -101,16 +106,21 @@ class CircleCIJob: ...@@ -101,16 +106,21 @@ class CircleCIJob:
{ {
"restore_cache": { "restore_cache": {
"keys": [ "keys": [
f"v{self.cache_version}-{self.cache_name}-pip-" + '{{ checksum "setup.py" }}', # check the fully-matched cache first
f"v{self.cache_version}-{self.cache_name}-pip-", f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-pip-" + '{{ checksum "setup.py" }}',
# try the partially-matched cache from `main`
f"v{self.cache_version}-{self.cache_name}-main-pip-",
# try the general partially-matched cache
f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-pip-",
] ]
} }
}, },
{ {
"restore_cache": { "restore_cache": {
"keys": [ "keys": [
f"v{self.cache_version}-{self.cache_name}-site-packages-" + '{{ checksum "setup.py" }}', f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-site-packages-" + '{{ checksum "setup.py" }}',
f"v{self.cache_version}-{self.cache_name}-site-packages-", f"v{self.cache_version}-{self.cache_name}-main-site-packages-",
f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-site-packages-",
] ]
} }
}, },
...@@ -119,7 +129,7 @@ class CircleCIJob: ...@@ -119,7 +129,7 @@ class CircleCIJob:
steps.append( steps.append(
{ {
"save_cache": { "save_cache": {
"key": f"v{self.cache_version}-{self.cache_name}-pip-" + '{{ checksum "setup.py" }}', "key": f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-pip-" + '{{ checksum "setup.py" }}',
"paths": ["~/.cache/pip"], "paths": ["~/.cache/pip"],
} }
} }
...@@ -127,7 +137,7 @@ class CircleCIJob: ...@@ -127,7 +137,7 @@ class CircleCIJob:
steps.append( steps.append(
{ {
"save_cache": { "save_cache": {
"key": f"v{self.cache_version}-{self.cache_name}-site-packages-" + '{{ checksum "setup.py" }}', "key": f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-site-packages-" + '{{ checksum "setup.py" }}',
"paths": ["~/.pyenv/versions/"], "paths": ["~/.pyenv/versions/"],
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment