]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Make MinimumVersion= a git commit
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 8 Apr 2025 11:02:54 +0000 (13:02 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 23 Jun 2025 18:49:24 +0000 (03:49 +0900)
With the latest mkosi it's possible for MinimumVersion= to be a git
commit so let's start making use of that. This will make mkosi fail
if it's executed within the systemd repository and the checked out
commit is too old.

Putting the mkosi commit sha in mkosi/mkosi.conf also allows retrieving
it without having the full source tree available.

We also make a bunch of improvements to the fetch-mkosi.py script.

(cherry picked from commit 278d5bfd7e04d1eacd2996573729193b4396b6c0)

.github/workflows/coverage.yml
.github/workflows/mkosi.yml
mkosi/mkosi.conf
tools/fetch-distro.py
tools/fetch-mkosi.py

index 80c7c1d62050f1dc1331c05e11b30b05ac777b9c..0a2f3b3c6bddfc662c7215d72d20a695d50a4a7d 100644 (file)
@@ -24,7 +24,7 @@ jobs:
 
     steps:
       - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
-      - uses: systemd/mkosi@a1a7e1f63e1726d88d5770fa06b29201d73e31a3
+      - uses: systemd/mkosi@32105855f386c980069d134d1b0f8fea4db2129e
 
       # Freeing up disk space with rm -rf can take multiple minutes. Since we don't need the extra free space
       # immediately, we remove the files in the background. However, we first move them to a different location
index 7d58ee5b077959f7dc7edda7db7284fb78e95c4c..601f18ee9c744a5815fd969f6513b4ce6a81204d 100644 (file)
@@ -113,7 +113,7 @@ jobs:
 
     steps:
       - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
-      - uses: systemd/mkosi@a1a7e1f63e1726d88d5770fa06b29201d73e31a3
+      - uses: systemd/mkosi@32105855f386c980069d134d1b0f8fea4db2129e
 
       # Freeing up disk space with rm -rf can take multiple minutes. Since we don't need the extra free space
       # immediately, we remove the files in the background. However, we first move them to a different location
index 64c8116f7b08312720360d482baaaf18801ba0e2..84a6242a2b48310c09f72dfb3b05e317c1a029bf 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
 [Config]
-MinimumVersion=25~devel
+MinimumVersion=commit:32105855f386c980069d134d1b0f8fea4db2129e
 Dependencies=
         exitrd
         initrd
index 88af386be08d94f79df7071846042493341dc2b4..9b2617d58ba80e981bf9db753ec56d63c7eebdc3 100755 (executable)
@@ -44,7 +44,7 @@ def read_config(distro: str):
 
 def commit_file(distro: str, files: list[Path], commit: str, changes: str):
     message = '\n'.join((
-        f'mkosi: update {distro} commit reference',
+        f'mkosi: update {distro} commit reference to {commit}',
         '',
         changes))
 
index 97ce401e8b7d84b3ec3486a00ea070c4e9f54210..90c318227fb47f231475aa8fdf2e793869e34759 100755 (executable)
@@ -14,7 +14,8 @@ from pathlib import Path
 
 URL = 'https://github.com/systemd/mkosi'
 BRANCH = 'main'  # We only want to ever use commits on upstream 'main' branch
-FILENAME = Path('.github/workflows/mkosi.yml')
+CONFIG = Path('mkosi/mkosi.conf')
+WORKFLOWS = [Path('.github/workflows/mkosi.yml'), Path('.github/workflows/coverage.yml')]
 
 def parse_args():
     p = argparse.ArgumentParser(
@@ -32,29 +33,21 @@ def parse_args():
     return p.parse_args()
 
 def read_config():
-    print(f'Reading {FILENAME}…')
+    print(f'Reading {CONFIG}…')
     matches = [m.group(1)
-               for line in open(FILENAME)
-               if (m := re.match('^- uses: systemd/mkosi@([a-z0-9]{40})$',
+               for line in open(CONFIG)
+               if (m := re.match('^MinimumVersion=commit:([a-z0-9]{40})$',
                                  line.strip()))]
     assert len(matches) == 1
     return matches[0]
 
-def commit_file(args, file: Path, commit: str, changes: str):
-    cmd = [
-        'git', '-C', args.dir.as_posix(),
-        'describe',
-        '--always',
-        commit]
-    print(f"+ {shlex.join(cmd)}")
-    desc = subprocess.check_output(cmd, text=True).strip()
-
+def commit_file(files: list[Path], commit: str, changes: str):
     message = '\n'.join((
-        f'mkosi: update mkosi commit reference to {desc}',
+        f'mkosi: update mkosi commit reference to {commit}',
         '',
         changes))
 
-    cmd = ['git', 'commit', '-m', message, file.as_posix()]
+    cmd = ['git', 'commit', '-m', message, *(str(file) for file in files)]
     print(f"+ {shlex.join(cmd)}")
     subprocess.check_call(cmd)
 
@@ -88,13 +81,15 @@ def update_mkosi(args):
     print(f"+ {shlex.join(cmd)}")
     changes = subprocess.check_output(cmd, text=True).strip()
 
-    s = FILENAME.read_text()
-    assert old_commit in s
-    print(f'mkosi: {FILENAME}: found old hash, updating…')
-    new = s.replace(old_commit, new_commit)
-    assert new != s
-    FILENAME.write_text(new)
-    commit_file(args, FILENAME, new_commit, changes)
+    for f in [CONFIG, *WORKFLOWS]:
+        s = f.read_text()
+        assert old_commit in s
+        print(f'mkosi: {f}: found old hash, updating…')
+        new = s.replace(old_commit, new_commit)
+        assert new != s
+        f.write_text(new)
+
+    commit_file([CONFIG, *WORKFLOWS], new_commit, changes)
 
 if __name__ == '__main__':
     args = parse_args()