]> 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)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 8 Apr 2025 16:35:04 +0000 (18:35 +0200)
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.

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

index a6634fc9d73a94258773cf53e3116fbe4f532bb1..fa71f2bffd2e250e4c2552eab16ec07e1fe340ed 100644 (file)
@@ -25,7 +25,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 984851d41523864cc48eae12aa7c78476a3ca679..fff7067ae894fe5431608c8d7ec2be2c87047d49 100644 (file)
@@ -120,7 +120,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 a1b5ab7523deafadd03d3795369005612724f6ad..a94ee0a0f65c43844dabe5acbe60a93d6c028a23 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 fce9decd82d9cc4d454f19f1bc049234d6e7871e..fa60e60db7df8ca03d7ffac6c7ae4703dae1b1d9 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()