From: Daan De Meyer Date: Tue, 8 Apr 2025 11:02:54 +0000 (+0200) Subject: mkosi: Make MinimumVersion= a git commit X-Git-Tag: v258-rc1~867 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=278d5bfd7e04d1eacd2996573729193b4396b6c0;p=thirdparty%2Fsystemd.git mkosi: Make MinimumVersion= a git commit 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. --- diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index a6634fc9d73..fa71f2bffd2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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 diff --git a/.github/workflows/mkosi.yml b/.github/workflows/mkosi.yml index 984851d4152..fff7067ae89 100644 --- a/.github/workflows/mkosi.yml +++ b/.github/workflows/mkosi.yml @@ -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 diff --git a/mkosi/mkosi.conf b/mkosi/mkosi.conf index a1b5ab7523d..a94ee0a0f65 100644 --- a/mkosi/mkosi.conf +++ b/mkosi/mkosi.conf @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Config] -MinimumVersion=25~devel +MinimumVersion=commit:32105855f386c980069d134d1b0f8fea4db2129e Dependencies= exitrd initrd diff --git a/tools/fetch-distro.py b/tools/fetch-distro.py index fce9decd82d..fa60e60db7d 100755 --- a/tools/fetch-distro.py +++ b/tools/fetch-distro.py @@ -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)) diff --git a/tools/fetch-mkosi.py b/tools/fetch-mkosi.py index 97ce401e8b7..90c318227fb 100755 --- a/tools/fetch-mkosi.py +++ b/tools/fetch-mkosi.py @@ -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()