From 2ad4e9ffdec74ac6be18cfc6d8690078fe545388 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 21 Jan 2024 15:33:58 -0500 Subject: [PATCH] replace gbp docker image with tools docker image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Ɓukasz Langa --- dockerfiles/Dockerfile.gbp | 12 ------------ dockerfiles/Dockerfile.tools | 1 + import-dsc | 12 ++++++------ import-upstream | 6 +++--- nightly-update-branch | 11 ++++++----- refresh-patches | 16 +++++++++------- gbp => tools | 28 ++++++++++++++++++++++------ 7 files changed, 47 insertions(+), 39 deletions(-) delete mode 100644 dockerfiles/Dockerfile.gbp rename gbp => tools (52%) diff --git a/dockerfiles/Dockerfile.gbp b/dockerfiles/Dockerfile.gbp deleted file mode 100644 index c6a5a10..0000000 --- a/dockerfiles/Dockerfile.gbp +++ /dev/null @@ -1,12 +0,0 @@ -FROM ubuntu:focal -RUN : \ - && apt-get update -qq \ - && DEBIAN_FRONTEND=noninteractive apt-get install \ - -qq -y --no-install-recommends \ - git-buildpackage \ - pristine-tar \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* -ENV HOME=/homedir LANG=C.UTF-8 -RUN git config --system --add safe.directory /tmp/src -WORKDIR /tmp/src diff --git a/dockerfiles/Dockerfile.tools b/dockerfiles/Dockerfile.tools index 1faa9d5..3955baf 100644 --- a/dockerfiles/Dockerfile.tools +++ b/dockerfiles/Dockerfile.tools @@ -1,3 +1,4 @@ +# we use the oldest supported distribution for pristine-tar FROM ubuntu:focal RUN : \ && apt-get update -qq \ diff --git a/import-dsc b/import-dsc index c378542..53a311a 100755 --- a/import-dsc +++ b/import-dsc @@ -6,7 +6,7 @@ import os.path import subprocess import tempfile -HERE = os.path.abspath(os.path.dirname(__file__)) +TOOLS = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tools') def _quiet(*cmd: str) -> None: @@ -26,19 +26,19 @@ def main() -> int: dsc, = (f for f in os.listdir(td) if f.endswith('.dsc')) subprocess.check_call(( - os.path.join(HERE, 'gbp'), '--volume', f'{td}:{td}:ro', - 'import-dsc', os.path.join(td, dsc), + TOOLS, '--volume', f'{td}:{td}:ro', + 'gbp', 'import-dsc', os.path.join(td, dsc), '--create-missing-branches', '--upstream-branch', 'upstream', '--pristine-tar', '--debian-branch', args.branch_name, )) _quiet('git', 'checkout', '-q', args.branch_name) - _quiet('gbp', 'pq', 'import') + _quiet(TOOLS, 'gbp', 'pq', 'import') _quiet('git', 'checkout', '-q', args.branch_name) _quiet('git', 'merge', '--no-edit', 'upstream') - _quiet('gbp', 'pq', 'rebase') - _quiet('gbp', 'pq', 'export') + _quiet(TOOLS, 'gbp', 'pq', 'rebase') + _quiet(TOOLS, 'gbp', 'pq', 'export') if subprocess.call(('git', 'diff', '--quiet')): _quiet('git', 'add', 'debian/patches') _quiet('git', 'commit', '-m', 'Refresh patches.') diff --git a/import-upstream b/import-upstream index 31dc276..5593e28 100755 --- a/import-upstream +++ b/import-upstream @@ -8,7 +8,7 @@ import subprocess import tempfile from typing import NamedTuple -HERE = os.path.abspath(os.path.dirname(__file__)) +TOOLS = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tools') VERSION_RE = re.compile(r'^(\d+\.\d+\.\d+)((?:a|b|rc)\d+)?$') @@ -78,9 +78,9 @@ def main() -> int: )) subprocess.check_call(( - os.path.join(HERE, 'gbp'), + TOOLS, '--volume', f'{dest}:{dest}:ro', - 'import-orig', dest, '--pristine-tar', '--no-interactive', + 'gbp', 'import-orig', dest, '--pristine-tar', '--no-interactive', '--no-symlink-orig', '--no-merge', )) diff --git a/nightly-update-branch b/nightly-update-branch index 5065ae9..a4d24f9 100755 --- a/nightly-update-branch +++ b/nightly-update-branch @@ -3,10 +3,11 @@ from __future__ import annotations import argparse import datetime -import os +import os.path import re import subprocess +TOOLS = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tools') VERSION_RE = re.compile(r'^v(\d+\.\d+\.\d+)((?:a|b|rc)\d+)?(.*)$') @@ -47,16 +48,16 @@ def main() -> int: deadsnakes_tag = f'deadsnakes/v{v_match[1]}{v_match[3]}' subprocess.check_call(('git', 'tag', deadsnakes_tag, 'origin/upstream')) - subprocess.check_call(('gbp', 'pq', 'import')) + subprocess.check_call((TOOLS, 'gbp', 'pq', 'import')) subprocess.check_call(('git', 'checkout', args.branch)) subprocess.check_call(('git', 'merge', 'origin/upstream', '--no-edit')) - subprocess.check_call(('gbp', 'pq', 'rebase')) - subprocess.check_call(('gbp', 'pq', 'export')) + subprocess.check_call((TOOLS, 'gbp', 'pq', 'rebase')) + subprocess.check_call((TOOLS, 'gbp', 'pq', 'export')) subprocess.check_call(('git', 'add', 'debian/patches')) if subprocess.call(('git', 'diff', '--staged', '--quiet')): subprocess.check_call(('git', 'commit', '-m', 'Refresh patches')) subprocess.check_call(( - 'dch', '--newversion', debian_version, '--distribution', dist, + TOOLS, 'dch', '--newversion', debian_version, '--distribution', dist, f'Update to {current_tag} ({datetime.date.today()}).', )) subprocess.check_call(( diff --git a/refresh-patches b/refresh-patches index 374d56d..657b407 100755 --- a/refresh-patches +++ b/refresh-patches @@ -2,9 +2,11 @@ from __future__ import annotations import argparse -import os +import os.path import subprocess +TOOLS = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tools') + def _release_message(version: str) -> str: version, _, prerelease = version.partition('~') @@ -34,10 +36,10 @@ def main() -> int: _quiet('git', 'checkout', '-q', 'upstream') _quiet('git', 'checkout', '-q', args.branch_name) - _quiet('gbp', 'pq', 'import') + _quiet(TOOLS, 'gbp', 'pq', 'import') _quiet('git', 'checkout', '-q', args.branch_name) _quiet('git', 'merge', '--no-edit', 'upstream') - if subprocess.call(('gbp', 'pq', 'rebase')): + if subprocess.call((TOOLS, 'gbp', 'pq', 'rebase')): print('*' * 79) print('Did not rebase cleanly!') print('- to cancel: `git rebase --abort` and `exit 1`') @@ -46,7 +48,7 @@ def main() -> int: ret = subprocess.call(os.environ.get('SHELL', 'bash')) if ret: return ret - _quiet('gbp', 'pq', 'export') + _quiet(TOOLS, 'gbp', 'pq', 'export') _quiet('git', 'add', 'debian/patches') if subprocess.call(('git', 'diff', '--staged', '--quiet')): _quiet('git', 'commit', '-m', 'Refresh patches.') @@ -54,16 +56,16 @@ def main() -> int: cmd = ('git', 'log', '-1', '--format=%s', 'upstream') version = subprocess.check_output(cmd).decode().split()[-1] - _quiet('sed', '-i', f's/^SVER=.*$/SVER={version}/g', 'debian/rules') + _quiet(TOOLS, 'sed', '-i', f's/^SVER=.*$/SVER={version}/g', 'debian/rules') _quiet('git', 'commit', '-am', f'Update SVER to {version}') print(f'- SVER updated to {version}') dist = subprocess.check_output(( - 'dpkg-parsechangelog', '--show-field=distribution', + TOOLS, 'dpkg-parsechangelog', '--show-field=distribution', )).decode().strip() debian_version = f'{version}-1+{dist}1' _quiet( - 'dch', '--newversion', debian_version, '--distribution', dist, + TOOLS, 'dch', '--newversion', debian_version, '--distribution', dist, _release_message(version), ) _quiet('git', 'commit', '-am', f'Finish changelog for {debian_version}') diff --git a/gbp b/tools similarity index 52% rename from gbp rename to tools index 2b817d4..7c20c7b 100755 --- a/gbp +++ b/tools @@ -8,25 +8,41 @@ import sys from typing import NoReturn HERE = os.path.abspath(os.path.dirname(__file__)) -IMG = 'ghcr.io/deadsnakes/gbp' +IMG = 'ghcr.io/deadsnakes/tools' + + +def _git_cfg(s: str) -> str: + cmd = ('git', 'config', s) + return subprocess.check_output(cmd).decode().strip() def main() -> NoReturn: parser = argparse.ArgumentParser() - parser.add_argument('-v', '--volume', dest='volumes', action='append') + parser.add_argument( + '-v', '--volume', + dest='volumes', + action='append', + default=[], + ) args, rest = parser.parse_known_args() - # we use the oldest supported distribution for pristine-tar + name = _git_cfg('user.name') + email = _git_cfg('user.email') + subprocess.check_call((os.path.join(HERE, 'pull-image'), IMG)) - gitconfig = os.path.expanduser('~/.gitconfig') interactive = '-ti' if sys.stdin.isatty() else '-i' cmd = ( 'docker', 'run', '--rm', interactive, - '--volume', f'{gitconfig}:/homedir/.gitconfig:ro', '--volume', f'{os.getcwd()}:/tmp/src:rw', + '--env', f'GIT_AUTHOR_NAME={name}', + '--env', f'GIT_AUTHOR_EMAIL={email}', + '--env', f'GIT_COMMITTER_NAME={name}', + '--env', f'GIT_COMMITTER_EMAIL={email}', + '--env', f'DEBFULLNAME={name}', + '--env', f'DEBEMAIL={email}', *(f'--volume={volume}' for volume in args.volumes), - IMG, 'gbp', *rest, + IMG, *rest, ) os.execvp(cmd[0], cmd)