Use docker images cache from merged PRs in master and release branches

This commit is contained in:
Mikhail f. Shiryaev 2022-11-25 13:58:27 +01:00
parent 4081a5f9e9
commit 9584487a1e
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 16 additions and 1 deletions

View File

@ -441,11 +441,15 @@ def main():
result_images = {}
images_processing_result = []
additional_cache = ""
if pr_info.release_pr or pr_info.merged_pr:
additional_cache = str(pr_info.release_pr or pr_info.merged_pr)
for image in changed_images:
# If we are in backport PR, then pr_info.release_pr is defined
# We use it as tag to reduce rebuilding time
images_processing_result += process_image_with_parents(
image, image_versions, pr_info.release_pr, args.push
image, image_versions, additional_cache, args.push
)
result_images[image.repo] = result_version

View File

@ -64,6 +64,7 @@ def get_pr_for_commit(sha, ref):
class PRInfo:
default_event = {
"commits": 1,
"head_commit": {"message": "commit_message"},
"before": "HEAD~",
"after": "HEAD",
"ref": None,
@ -86,7 +87,9 @@ class PRInfo:
self.changed_files = set() # type: Set[str]
self.body = ""
self.diff_urls = []
# release_pr and merged_pr are used for docker images additional cache
self.release_pr = 0
self.merged_pr = 0
ref = github_event.get("ref", "refs/heads/master")
if ref and ref.startswith("refs/heads/"):
ref = ref[11:]
@ -158,6 +161,14 @@ class PRInfo:
self.diff_urls.append(github_event["pull_request"]["diff_url"])
elif "commits" in github_event:
# `head_commit` always comes with `commits`
commit_message = github_event["head_commit"]["message"]
if commit_message.startswith("Merge pull request #"):
merged_pr = commit_message.split(maxsplit=4)[3]
try:
self.merged_pr = int(merged_pr[1:])
except ValueError:
logging.error("Failed to convert %s to integer", merged_pr)
self.sha = github_event["after"]
pull_request = get_pr_for_commit(self.sha, github_event["ref"])
repo_prefix = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}"