osmo-ci/scripts/obs/lib/metapkg.py

105 lines
3.2 KiB
Python
Raw Normal View History

scripts/obs: rewrite pushing source pkgs to OBS Harald requested that the OBS scripts should not stop if building one specific source package fails, instead it should keep going and report at the end a non-success exit code. Given that the shell script code has historically grown and became hard to maintain, I decided to rewrite the scripts for implementing this feature. This rewrite solves additional problems: * No full checkout of an OBS project like network:osmocom:latest anymore, with lots of packages that won't get updated (e.g. the uhd package has a uhd-images_3.14.1.1.tar.xz file that is 108 MB). With the old code, developers had to wait minutes during the checkout before the script reaches code that is currently being developed. Now only single packages get checked out right before they get updated. * No need to clone git repositories over and over. With the new code, git repos only get cloned if needed (for latest it is not needed if the remote git tag is the same as the version in OBS). During development, the cloned git repositories are cached. * Output from commands like "git tag -l" is not written to the log unless they failed. This makes the log more readable, which is especially important when a package fails to build, we keep going and need to spot the build error in the middle of the log later on. * No more duplicated code for nightly and latest scripts that worked similar but had slight differences. Also the list of packages is not duplicated for nightly and latest anymore; nightly uses all packages and latest uses packages that have at least one git tag. * Building source packages is decoupled from uploading them. A separate script build_srcpkg.py can be used to just build the deb + rpm spec source packages, without interacting with the OBS server. * The scripts can optionally run in docker with a command-line switch, and this is used by jenkins. This way we don't need to install more dependencies on the host such as rebar3 which is now needed for erlang/osmo_dia2gsup. * Add erlang/osmo_dia2gsup and run its generate_build_dep.sh (SYS#6006) I have done the new implementation in python to make use of argparse and to be able to use try/except and print a trace when building one package fails. Example output: * https://jenkins.osmocom.org/jenkins/job/Osmocom_OBS_nightly_obs.osmocom.org/48/console * https://jenkins.osmocom.org/jenkins/job/Osmocom_OBS_latest_obs.osmocom.org/46/console Change-Id: I45a555d05a9da808c0fe0145aae665f583cb80d9
2022-07-13 10:50:21 +00:00
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright 2022 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
import os
import lib
import lib.config
import lib.debian
import lib.rpm_spec
def get_conflicts(feed):
ret = []
for f in lib.config.feeds:
if f == feed:
continue
ret += [f"osmocom-{f}"]
return ret
def prepare_source_dir(feed):
path = f"{lib.config.path_cache}/osmocom-{feed}"
if os.path.exists(path):
lib.run_cmd(["rm", "-rf", path])
os.makedirs(f"{path}/debian")
os.makedirs(f"{path}/contrib")
def generate_debian_pkg(feed, version):
path = f"{lib.config.path_cache}/osmocom-{feed}"
conflicts = get_conflicts(feed)
with open(f"{path}/debian/control", "w") as f:
f.write(f"Source: osmocom-{feed}\n")
f.write("Section: unknown\n")
f.write("Priority: optional\n")
f.write("Maintainer: Osmocom OBS scripts <info@osmocom.org>\n")
f.write("Build-Depends: debhelper (>= 10)\n")
f.write("Standards-Version: 3.9.8\n")
f.write("\n")
f.write(f"Package: osmocom-{feed}\n")
f.write("Depends: ${misc:Depends}\n")
f.write("Architecture: any\n")
f.write(f"Conflicts: {', '.join(conflicts)}\n")
f.write(f"Description: Dummy package, conflicts with {conflicts}\n")
with open(f"{path}/debian/changelog", "w") as f:
f.write(f"osmocom-{feed} ({version}) unstable; urgency=medium\n")
f.write("\n")
f.write(f" * Dummy package, which conflicts with: {conflicts}\n")
f.write("\n")
f.write(" -- Osmocom OBS scripts <info@osmocom.org> Tue, 25 Jul 2022"
" 15:48:00 +0200\n")
with open(f"{path}/debian/rules", "w") as f:
f.write("#!/usr/bin/make -f\n")
f.write("%:\n")
f.write("\tdh $@\n")
lib.run_cmd(["chmod", "+x", f"{path}/debian/rules"])
with open(f"{path}/debian/compat", "w") as f:
f.write("10\n")
def generate_rpm_spec(feed, version):
print(f"osmocom-{feed}: generating rpm spec file")
path = (f"{lib.config.path_cache}/osmocom-{feed}/contrib/osmocom-{feed}"
".spec.in")
conflicts = get_conflicts(feed)
with open(path, "w") as f:
f.write(f"Name: osmocom-{feed}\n")
f.write(f"Version: {version}\n")
f.write(f"Summary: Dummy package, conflicts with: {conflicts}\n")
f.write("Release: 0\n")
f.write("License: AGPL-3.0-or-later\n")
f.write("Group: Hardware/Mobile\n")
for conflict in conflicts:
f.write(f"Conflicts: {conflict}\n")
f.write("%description\n")
f.write(f"Dummy package, which conflicts with: {conflicts}\n")
f.write("%files\n")
def build(feed, conflict_version):
pkgname = f"osmocom-{feed}"
version = conflict_version if conflict_version else "1.0.0"
print(f"{pkgname}: generating meta package {version}")
prepare_source_dir(feed)
generate_debian_pkg(feed, version)
os.makedirs(lib.get_output_path(pkgname))
lib.remove_cache_extra_files()
lib.debian.build_source_package(pkgname)
lib.debian.move_files_to_output(pkgname)
generate_rpm_spec(feed, version)
lib.rpm_spec.copy_to_output(pkgname)
lib.remove_cache_extra_files()
return version