From e31134b5f2a10fb61b09075b8629a626cc3eb328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 12 Sep 2024 10:49:41 +0200 Subject: [PATCH 1/2] mkosi: add helper script to update mkosi hash This is very similar to tools/fetch-distro.py. The idea is that we extend the commit to update the mkosi hash with a git log --pretty=oneline output, so that the reader can know what changes were actually included. The motivation is that I'm always wondering what changed in mkosi when I see a commit updating the hash, and it's nicer to have this information shown directly in the commit. The script does _not_ pull changes from upstream, on the assumption that the person doing the commit always has a fresh checkout and that they tested with that checkout. --- tools/fetch-mkosi.py | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 tools/fetch-mkosi.py diff --git a/tools/fetch-mkosi.py b/tools/fetch-mkosi.py new file mode 100755 index 00000000000..97ce401e8b7 --- /dev/null +++ b/tools/fetch-mkosi.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1-or-later + +""" +Check out mkosi into specified location. +With -u, if changed, commit the latest hash. +""" + +import argparse +import shlex +import subprocess +import re +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') + +def parse_args(): + p = argparse.ArgumentParser( + description=__doc__, + ) + p.add_argument( + 'dir', + type=Path, + ) + p.add_argument( + '--update', '-u', + action='store_true', + default=False, + ) + return p.parse_args() + +def read_config(): + print(f'Reading {FILENAME}…') + matches = [m.group(1) + for line in open(FILENAME) + if (m := re.match('^- uses: systemd/mkosi@([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() + + message = '\n'.join(( + f'mkosi: update mkosi commit reference to {desc}', + '', + changes)) + + cmd = ['git', 'commit', '-m', message, file.as_posix()] + print(f"+ {shlex.join(cmd)}") + subprocess.check_call(cmd) + +def checkout_mkosi(args): + if args.dir.exists(): + print(f'{args.dir} already exists.') + return + + cmd = [ + 'git', 'clone', URL, + f'--branch={BRANCH}', + args.dir.as_posix(), + ] + print(f"+ {shlex.join(cmd)}") + subprocess.check_call(cmd) + +def update_mkosi(args): + old_commit = read_config() + + cmd = ['git', '-C', args.dir.as_posix(), 'rev-parse', f'refs/remotes/origin/{BRANCH}'] + print(f"+ {shlex.join(cmd)}") + new_commit = subprocess.check_output(cmd, text=True).strip() + + if old_commit == new_commit: + print(f'mkosi: commit {new_commit!s} is still fresh') + return + + cmd = ['git', '-C', args.dir.as_posix(), 'log', '--graph', + '--pretty=oneline', '--no-decorate', '--abbrev-commit', '--abbrev=10', + f'{old_commit}..{new_commit}'] + 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) + +if __name__ == '__main__': + args = parse_args() + checkout_mkosi(args) + if args.update: + update_mkosi(args) From 37bf958e7be8e624a65a1faf169e5ca8d6e4e5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 12 Sep 2024 10:46:24 +0200 Subject: [PATCH 2/2] mkosi: update mkosi commit reference to v24.3-158-g2c9954fa51 * 2c9954fa51 mkosi-initrd: correct `--debug-shell` help output * 671708a10b Merge pull request #2990 from behrmann/allthemanuals |\ | * 2671849125 initrd: add --show-documentation option | * e2238f5dc7 Move show_docs to its own module | * e366093b1c doc: make documentation command take an argument * | 9fcff08b34 Update documentation links * | 113f7f67dd Only write to /etc/machine-id if /etc exists |/ * 62a610c0e5 Merge pull request #3005 from DaanDeMeyer/mypy |\ | * 9b569c93bb Don't delete reader in _tempfile() backport | * 16f4c94930 Mark all class variables as Final | * ca7021e9a7 Annotate two more variables that need it | * fec368dd4d Move KeySource.Type out of KeySource | * ff5f7b06b8 user: Drop lru_cache() for home() and name() | * 8f7c7b366f Move code backported from cpython upstream to backport.py | * f66212e9c2 Drop listify() | * 4293866df2 mypy: Disable allow_redefinition | * 2700337f11 Fix mypyc warnings in sandbox.py |/ * 025483af04 sandbox: Use separate variable name when we change types * b04800cd30 Merge pull request #3003 from DaanDeMeyer/initrd |\ | * fd64be9b60 mkosi-initrd: Ignore gnupg subdirectory | * 7a8a21f8f6 mkosi-initrd: Only set --cacheonly=metadata when running as root | * 156880c398 mkosi-initrd: Add --debug-shell argument |/ * a32c8f393a Merge pull request #3002 from DaanDeMeyer/cherry-pick |\ | * 1d8bfabc97 news: add note to change where the manual pages are | * 8917d65db1 initrd: flatten module into a single file | * 76085b788a sandbox: flatten module into a single file | * 9f48afa4a7 cli: add missing completion stubs to pyproject.toml | * 6e21cceb03 doc: move man pages to resources/man | * 25d1c6b579 cli: use ellipsis ligature instead of writing out ... |/ * 013d9b5595 Move various functions to bootloader.py * 508ad85475 Update NEWS.md * f25b8dee6f Simplify package cache dir mirror key * dce4c8af51 Merge pull request #2998 from DaanDeMeyer/ci |\ | * f4934828f7 tests: Show debug messages on console | * fa3ae22598 ci: Drop machine-id commit timeout drop-in * dba01269de base64 encode mirror if we put it in package cache dir key * 364b65f7bb Add 'login' to Debian/Ubuntu/Kali package list * ee07b5b6d2 Bump github/codeql-action from 3.25.15 to 3.26.6 --- .github/workflows/mkosi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mkosi.yml b/.github/workflows/mkosi.yml index d76a935a401..26d905fb3e3 100644 --- a/.github/workflows/mkosi.yml +++ b/.github/workflows/mkosi.yml @@ -105,7 +105,7 @@ jobs: steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - - uses: systemd/mkosi@31b4e756c1484c302435653da5d3b9bdfae38518 + - uses: systemd/mkosi@2c9954fa51a3a995bbdc02db6ef51f5bd27bc1ba # 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