Compute the "task ID" only when needed

This commit is contained in:
Simon Sapin 2019-05-23 18:40:51 +02:00 committed by Josh Matthews
parent 0edf865deb
commit 0ed6cdbb42
2 changed files with 27 additions and 27 deletions

View file

@ -57,21 +57,23 @@ class Config:
self.git_ref = os.environ.get("GIT_REF")
self.git_sha = os.environ.get("GIT_SHA")
def init_task_id(self):
def task_id(self):
if hasattr(self, "_task_id"):
return self._task_id
# If the head commit is a merge, we want to generate a unique task id which incorporates
# the merge parents rather that the actual sha of the merge commit. This ensures that tasks
# can be reused if the tree is in an identical state. Otherwise, if the head commit is
# not a merge, we can rely on the head commit sha for that purpose.
merge_parents_output = subprocess.check_output(["git", "show", "--format=%P", "HEAD"])
merge_parents = merge_parents_output.decode("utf8").strip().split(' ')
self.task_id = self.git_sha
self._task_id = self.git_sha
if len(merge_parents) > 1:
self.task_id = '-'.join(merge_parents)
self._task_id = '-'.join(merge_parents)
return self._task_id
def git_sha_is_current_head(self):
output = subprocess.check_output(["git", "rev-parse", "HEAD"])
self.git_sha = output.decode("utf8").strip()
self.init_task_id()
class Shared: