-
Notifications
You must be signed in to change notification settings - Fork 15
/
build
executable file
·78 lines (67 loc) · 2.41 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import os.path
import subprocess
from typing import NoReturn
HERE = os.path.abspath(os.path.dirname(__file__))
TOOLS = os.path.join(HERE, 'tools')
DOCKER_RUN = os.path.join(HERE, 'docker-run')
def _gpg_volumes() -> list[str]:
def _gpg(f: str, *, home: str = os.path.expanduser('~')) -> str:
return os.path.join(home, '.gnupg', f)
for paths in (
('pubring.kbx', 'private-keys-v1.d'), # new format
# TODO: deadsnakes GHA still uses this
('pubring.gpg', 'secring.gpg'), # old format
):
if all(os.path.exists(_gpg(p)) for p in paths):
return [
f'--volume={_gpg(p)}:{_gpg(p, home="/root")}:ro'
for p in paths
]
else:
raise AssertionError('no gpg keys found?')
def main() -> NoReturn:
parser = argparse.ArgumentParser()
parser.add_argument('--source', action='store_true')
parser.add_argument('--git-build', action='store_true')
args = parser.parse_args()
print('*' * 79)
print('Parsing target distribution')
print('*' * 79)
dist = subprocess.check_output((
TOOLS, 'dpkg-parsechangelog', '--show-field=distribution',
)).decode().strip()
print('*' * 79)
print('Running build (results will be in ../dist)')
print('*' * 79)
os.makedirs('../dist', exist_ok=True)
pwd = os.getcwd()
gbp_args = '' if args.source else '-us -uc'
gbp_args += (
'' if not args.git_build else
' --git-pristine-tar-commit '
"--git-upstream-tag='deadsnakes/v%(version%~%_)s'"
)
extra = '--git-builder="debuild -S -sa"' if args.source else ''
prog = (
f'chmod 700 ~/.gnupg && '
f'apt-get update -qq && '
f'mk-build-deps --install --remove --tool "apt-get --yes" /code/debian/control && ' # noqa: E501
f'cp -r /code /tmp && '
f'cd /tmp/code && '
f'git clean -fxfd && '
f'gbp buildpackage {gbp_args} --git-pristine-tar --git-debian-branch=ubuntu/{dist} {extra} && ' # noqa
f'find .. -maxdepth 1 -type f | xargs --replace cp {{}} /dist'
)
cmd = (
DOCKER_RUN,
*_gpg_volumes(),
'-v', f'{pwd}:/code:ro',
'-v', f'{pwd}/../dist:/dist:rw',
f'ghcr.io/deadsnakes/{dist}', 'bash', '-euxc', prog,
)
os.execvp(cmd[0], cmd)
if __name__ == '__main__':
raise SystemExit(main())