73 lines
3.4 KiB
Python
Executable File
73 lines
3.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Build the next numbered dev build and publish it to a test project's repository: dev-build.py.
|
|
|
|
The test number in tmp/test-number goes up by one for each build that succeeds. The build's version
|
|
is the newest changelog entry's with ~devN before its Debian revision, 0.41.0-1 becoming
|
|
0.41.0~dev7-1, so the release of that entry is newer than all its dev builds. ./build.sh builds it
|
|
with CONTAINER_RUNTIME and DOCKER_CONTEXT from the environment; the build is moved to out/dev/,
|
|
copied into the repository container of the project (--project or LXD_PROJECT, lm-dev by default)
|
|
made by lxd-project.py, and published there.
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
HERE = pathlib.Path(__file__).resolve().parent
|
|
ROOT = HERE.parent.parent
|
|
NUMBER = ROOT / 'tmp' / 'test-number'
|
|
CHANGELOG = ROOT / 'debian-package' / 'debian' / 'changelog'
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument('--project', default=os.environ.get('LXD_PROJECT', 'lm-dev'),
|
|
help='the test project made by lxd-project.py (LXD_PROJECT, default lm-dev)')
|
|
args = parser.parse_args()
|
|
state_file = ROOT / 'tmp' / f'lxd-project-{args.project}.json'
|
|
if not state_file.is_file():
|
|
sys.exit(f'no {state_file}; create the project with lxd-project.py create')
|
|
state = json.loads(state_file.read_text(encoding='utf-8'))
|
|
|
|
# The newest entry's first line is "package (version) distribution; urgency=...".
|
|
match = re.match(r'(\S+) \(([^)]+)\)', CHANGELOG.read_text(encoding='utf-8'))
|
|
if not match:
|
|
sys.exit(f'no version in the first line of {CHANGELOG}')
|
|
package, version = match.groups()
|
|
number = int(NUMBER.read_text(encoding='utf-8').strip()) + 1 if NUMBER.is_file() else 1
|
|
upstream, dash, revision = version.rpartition('-')
|
|
dev = f'{upstream}~dev{number}-{revision}' if dash else f'{version}~dev{number}'
|
|
|
|
print(f'building {package} {dev}')
|
|
if subprocess.run(['./build.sh', '--build-arg', f'DEB_VERSION={dev}'], cwd=ROOT).returncode != 0:
|
|
sys.exit(f'the build of {dev} failed; the test number stays {number - 1}')
|
|
NUMBER.write_text(f'{number}\n', encoding='utf-8')
|
|
|
|
# The dev build leaves out/ to out/dev/, so out/ keeps the release builds.
|
|
target = ROOT / 'out' / 'dev'
|
|
target.mkdir(exist_ok=True)
|
|
for artifact in (ROOT / 'out').glob(f'{package}_{dev}_*'):
|
|
artifact.replace(target / artifact.name)
|
|
deb = target / f'{package}_{dev}_all.deb'
|
|
if not deb.is_file():
|
|
sys.exit(f'the build made no {deb.name}')
|
|
|
|
where = ['--project', state['project']]
|
|
pushed = subprocess.run(['lxc', 'file', 'push', str(deb), f'{state["remote"]}:repo/var/www/html/pool/main/{deb.name}',
|
|
'--mode', '0644', *where], capture_output=True, text=True)
|
|
if pushed.returncode != 0:
|
|
sys.exit(f'could not copy {deb.name} into the repository: {pushed.stderr.strip()}')
|
|
published = subprocess.run(['lxc', 'exec', f'{state["remote"]}:repo', *where, '-T', '--',
|
|
'linux-manager-repo-publish'], capture_output=True, text=True)
|
|
if published.returncode != 0:
|
|
sys.exit(f'the repository was not published: {published.stderr.strip()}')
|
|
print(f'{package} {dev} is published at {state["repository"]} (resolute main)')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|