Skip to content

Commit d1bf5b6

Browse files
committed
fix: Update ZMK version more thoroughly
Provided the user is still using the default GitHub workflow, the "zmk version" command will now update that to point to the correct revision of ZMK as well. Also reworked the logic for updating the version in the West manifest to set manifest.defaults.revision instead of setting the revision on the ZMK project. This matches what is now done in the config template, which allows updating the version in one place for any modules that tag commits to match ZMK versions.
1 parent 2ec97cb commit d1bf5b6

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

zmk/commands/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _print_current_version(repo: Repo):
7070

7171
def _set_version(repo: Repo, revision: str):
7272
repo.set_zmk_version(revision)
73-
repo.run_west("update", "zmk")
73+
repo.run_west("update")
7474

7575
rich.print()
7676
rich.print(f'ZMK is now using revision "{revision}"')

zmk/repo.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
_APP_DIR_NAME = "app"
1818
_BUILD_MATRIX_PATH = "build.yaml"
19+
_BUILD_WORKFLOW_PATH = ".github/workflows/build.yml"
1920
_CONFIG_DIR_NAME = "config"
2021
_PROJECT_MANIFEST_PATH = f"{_CONFIG_DIR_NAME}/west.yml"
2122
_MODULE_MANIFEST_PATH = "zephyr/module.yml"
@@ -151,6 +152,11 @@ def build_matrix_path(self) -> Path:
151152
"""Path to the "build.yaml" file."""
152153
return self.path / _BUILD_MATRIX_PATH
153154

155+
@property
156+
def build_workflow_path(self) -> Path:
157+
"""Path to the GitHub workflow build.yml file."""
158+
return self.path / _BUILD_WORKFLOW_PATH
159+
154160
@property
155161
def config_path(self) -> Path:
156162
"""Path to the "config" folder."""
@@ -228,7 +234,8 @@ def ensure_west_ready(self) -> None:
228234

229235
def set_zmk_version(self, revision: str) -> None:
230236
"""
231-
Modifies the "west.yml" file to change the revision for the "zmk" project.
237+
Modifies the "west.yml" file to change the default revision for projects
238+
and modifies the GitHub workflow file to match.
232239
233240
This does not automatically check out the new revision. Run
234241
Repo.run_west("update") after calling this.
@@ -241,16 +248,42 @@ def set_zmk_version(self, revision: str) -> None:
241248
if not remote.revision_exists(revision):
242249
raise ValueError(f'Revision "{revision}" does not exist in {zmk.url}')
243250

251+
# Update the project manifest
244252
yaml = YAML()
245253
data = yaml.load(self.project_manifest_path)
246254

255+
if not "defaults" in data["manifest"]:
256+
data["manifest"]["defaults"] = yaml.map()
257+
258+
data["manifest"]["defaults"]["revision"] = revision
259+
247260
for project in data["manifest"]["projects"]:
248261
if project["name"] == "zmk":
249-
project["revision"] = revision
262+
try:
263+
del project["revision"]
264+
except KeyError:
265+
pass
250266
break
251267

252268
yaml.dump(data, self.project_manifest_path)
253269

270+
# Update the build workflow to match. The user may have customized this
271+
# file, so only update it if it looks like it's using the default workflow,
272+
# and ignore any errors to read or update it.
273+
try:
274+
yaml = YAML()
275+
data = yaml.load(self.build_workflow_path)
276+
277+
build = data["jobs"]["build"]
278+
workflow, _, _ = build["uses"].rpartition("@")
279+
280+
if workflow.endswith(".github/workflows/build-user-config.yml"):
281+
build["uses"] = f"{workflow}@{revision}"
282+
283+
yaml.dump(data, self.build_workflow_path)
284+
except KeyError:
285+
pass
286+
254287
@overload
255288
def _run_west(self, *args: str, capture_output: Literal[False] = False) -> None: ...
256289

0 commit comments

Comments
 (0)