Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/infra/recipes/uprev_baguette_image.py
5392 views
1
# -*- coding: utf-8 -*-
2
# Copyright 2025 The ChromiumOS Authors
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
6
"""Recipe for uploading uprevs of the baguette image."""
7
8
import os
9
import re
10
import pathlib
11
from typing import Generator
12
13
from PB.recipes.crosvm.uprev_baguette_image import UprevBaguetteImageProperties
14
from recipe_engine import post_process
15
from recipe_engine.recipe_api import RecipeApi
16
from recipe_engine.recipe_api import StepFailure
17
from recipe_engine.recipe_test_api import RecipeTestApi
18
from recipe_engine.recipe_test_api import TestData
19
20
21
DEPS = [
22
"recipe_engine/buildbucket",
23
"recipe_engine/context",
24
"recipe_engine/path",
25
"recipe_engine/properties",
26
"recipe_engine/step",
27
"depot_tools/git",
28
]
29
30
PROPERTIES = UprevBaguetteImageProperties
31
32
_PLATFORM2_REPO_URL = "https://chromium.googlesource.com/chromiumos/platform2/"
33
_UPREV_SCRIPT_PATH = "vm_tools/baguette_image/src/uprev-version-pin.sh"
34
_VERSION_FILE_PATH = "vm_tools/concierge/baguette_version.h"
35
36
37
def RunSteps(api: RecipeApi, properties: UprevBaguetteImageProperties) -> None:
38
# Clone the repo in a temp dir
39
checkout = api.path.mkdtemp()
40
api.git.checkout(_PLATFORM2_REPO_URL, dir_path=checkout, depth=1)
41
42
with api.context(cwd=checkout):
43
# Ensure the commit hook is configured
44
api.step(
45
"Install commit hook",
46
[
47
"curl",
48
"-Lo",
49
".git/hooks/commit-msg",
50
"https://chromium-review.googlesource.com/tools/hooks/commit-msg",
51
],
52
)
53
api.step("Make commit hook executable", ["chmod", "+x", ".git/hooks/commit-msg"])
54
55
# Run the uprev script
56
api.step("Run uprev-image-version.sh", ["bash", _UPREV_SCRIPT_PATH])
57
58
# Check if the uprev made any changes to the version file
59
diff_result = api.git("diff", "--exit-codes", "-q", _VERSION_FILE_PATH, ok_ret="any")
60
if diff_result.retcode == 0:
61
diff_result.presentation.step_text = "Nothing to submit"
62
return
63
64
commit_lines = [
65
f"vm_tools: Uprev baguette_image version",
66
"",
67
f"Generated by {api.buildbucket.build_url()}.",
68
]
69
70
# Create a commit with the new version file
71
api.git("add", _VERSION_FILE_PATH)
72
api.git("commit", "-m", "\n".join(commit_lines))
73
74
# Push the change to gerrit
75
if properties.push:
76
gerrit_params = ["[email protected]"]
77
if properties.bot:
78
gerrit_params += ["l=Bot-Commit+1", "l=Commit-Queue+2"]
79
else:
80
gerrit_params += ["l=Commit-Queue+1"]
81
api.git("push", "origin", f"HEAD:refs/for/main%{','.join(gerrit_params)}")
82
83
84
def GenTests(api: RecipeTestApi) -> Generator[TestData, None, None]:
85
yield api.test(
86
"Submit test uprev",
87
api.properties(push=True, bot=False),
88
api.step_data("git diff", retcode=1),
89
)
90
yield api.test(
91
"Submit bot uprev",
92
api.properties(push=True, bot=True),
93
api.step_data("git diff", retcode=1),
94
)
95
96
yield api.test(
97
"Nothing to submit",
98
api.properties(push=True),
99
api.step_data("git diff", retcode=0),
100
)
101
102