Skip to content

Commit d19d2ab

Browse files
committed
frontend: make coprdirs have their repo available in the buildroot
This is useful in general but especially for pull requests that build multiple packages which depend on each other (e.g. `python-copr` and `copr-cli`). Up until now, it had to be workarounded by building the dependency into the main copr repository.
1 parent c050d8a commit d19d2ab

File tree

7 files changed

+86
-10
lines changed

7 files changed

+86
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#! /bin/bash
2+
#
3+
# Copyright (c) 2025 Red Hat, Inc.
4+
#
5+
# This program is free software: you can redistribute it and/or
6+
# modify it under the terms of the GNU General Public License as
7+
# published by the Free Software Foundation, either version 2 of
8+
# the License, or (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be
11+
# useful, but WITHOUT ANY WARRANTY; without even the implied
12+
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13+
# PURPOSE. See the GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see http://www.gnu.org/licenses/.
17+
18+
19+
# Include Beaker environment
20+
. /usr/share/beakerlib/beakerlib.sh || exit 1
21+
22+
# Load config settings
23+
HERE=$(dirname "$(realpath "$0")")
24+
source "$HERE/config"
25+
source "$HERE/helpers"
26+
27+
28+
quick_package_script ()
29+
{
30+
cp "$HERE/files/quick-package.sh" script
31+
echo "$1" >> script
32+
}
33+
34+
35+
rlJournalStart
36+
rlPhaseStartSetup
37+
setup_checks
38+
rlAssertRpm "jq"
39+
setupProjectName "coprdir"
40+
rlPhaseEnd
41+
42+
rlPhaseStartTest
43+
# Test that CoprDirs have their own repositories in the buildroot
44+
tmp=`mktemp -d`
45+
rlRun "copr-cli create --chroot $CHROOT $PROJECT"
46+
47+
# For an ease of implementation, the dependency and the package that
48+
# requires it are both `hello`. In a real life the first package would
49+
# be something like `python-copr` or `python-copr-common`, and the
50+
# second package would be something like `copr-cli` or `copr-backend`.
51+
52+
# This is the dependency (e.g. python-copr)
53+
rlRun "curl https://src.fedoraproject.org/rpms/hello/raw/rawhide/f/hello.spec > $tmp/hello-1.spec"
54+
rlRun "sed -i '1s/^/Epoch: 6\n/' $tmp/hello-1.spec"
55+
rlRun "copr-cli build $PROJECT:custom:foo $tmp/hello-1.spec"
56+
57+
# And this is the package that builds on top of it (e.g. copr-cli)
58+
rlRun "curl https://src.fedoraproject.org/rpms/hello/raw/rawhide/f/hello.spec > $tmp/hello-2.spec"
59+
rlRun "sed -i '1s/^/BuildRequires: hello >= 6:\n/' $tmp/hello-2.spec"
60+
rlRun "copr-cli build $PROJECT:custom:foo $tmp/hello-2.spec"
61+
rlPhaseEnd
62+
63+
rlPhaseStartCleanup
64+
cleanProject
65+
rlPhaseEnd
66+
rlJournalPrintText
67+
rlJournalEnd

doc/user_documentation.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,8 @@ submit one build directly into the project, one build to the
733733
subproject.
734734

735735
The subproject builds are isolated from each other but they can all
736-
see builds from the main ``test`` project repository. For the time
737-
being, the builds in the ``test:custom:foo`` subproject don't see
738-
other builds from the same subproject. This is not a design choice but
739-
rather a missing feature.
736+
see builds from their own repository and from the main ``test`` project
737+
repository.
740738

741739
The subproject name has to start with the project name. It is followed
742740
by either ``:custom:`` or ``:pr:`` and a suffix. The suffix can be

frontend/coprs_frontend/coprs/logic/complex_logic.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ def create_object(self, clazz, from_object, exclude=list()):
588588

589589
class BuildConfigLogic(object):
590590
@classmethod
591-
def generate_build_config(cls, copr, chroot_id):
591+
def generate_build_config(cls, coprdir, chroot_id):
592592
""" Return dict with proper build config contents """
593+
copr = coprdir.copr
593594
chroot = None
594595
for i in copr.active_copr_chroots:
595596
if i.mock_chroot.name == chroot_id:
@@ -616,6 +617,13 @@ def generate_build_config(cls, copr, chroot_id):
616617
"name": "Copr buildroot",
617618
})
618619

620+
if not coprdir.main:
621+
repos.append({
622+
"id": "copr_coprdir",
623+
"baseurl": coprdir.repo_url + "/{}/".format(chroot_id),
624+
"name": "Coprdir repository",
625+
})
626+
619627
# None value of the priority won't show in API
620628
if copr.repo_priority in [None, DEFAULT_COPR_REPO_PRIORITY]:
621629
repo_priority = None

frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_build_chroots.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def to_dict(build_chroot):
3737

3838

3939
def build_config(build_chroot):
40-
config = BuildConfigLogic.generate_build_config(build_chroot.build.copr, build_chroot.name)
40+
config = BuildConfigLogic.generate_build_config(
41+
build_chroot.build.copr_dir, build_chroot.name)
4142
copr_chroot = CoprChrootsLogic.get_by_name_or_none(build_chroot.build.copr, build_chroot.name)
4243
dict_data = {
4344
"repos": config.get("repos"),

frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_project_chroots.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def to_dict(project_chroot):
5151

5252

5353
def to_build_config_dict(project_chroot):
54-
config = BuildConfigLogic.generate_build_config(project_chroot.copr, project_chroot.name)
54+
config = BuildConfigLogic.generate_build_config(
55+
project_chroot.copr.main_dir, project_chroot.name)
5556
config_dict = {
5657
"chroot": project_chroot.name,
5758
"repos": config["repos"],

frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ def get_build_record(task, for_backend=False):
185185
if modules:
186186
build_record["modules"] = {'toggle': modules}
187187

188-
build_config = BuildConfigLogic.generate_build_config(task.build.copr, task.mock_chroot.name)
188+
build_config = BuildConfigLogic.generate_build_config(
189+
task.build.copr_dir, task.mock_chroot.name)
189190
build_record["repos"] = build_config.get("repos")
190191
build_record["buildroot_pkgs"] = build_config.get("additional_packages")
191192
build_record["with_opts"] = build_config.get("with_opts")

frontend/coprs_frontend/tests/test_logic/test_complex_logic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ def test_generate_build_config_with_dep_mistake(self):
254254
"/results/user1/foocopr/fedora-18-x86_64/",
255255
"priority": None,
256256
}
257-
build_config = bcl.generate_build_config(self.c1, "fedora-18-x86_64")
257+
build_config = bcl.generate_build_config(self.c1.main_dir, "fedora-18-x86_64")
258258
assert build_config["repos"] == [main_repo]
259259

260260
self.c1.repos = "copr://non/existing"
261-
build_config = bcl.generate_build_config(self.c1, "fedora-18-x86_64")
261+
build_config = bcl.generate_build_config(self.c1.main_dir, "fedora-18-x86_64")
262262

263263
# We put the link there, even though baseurl points to 404. The build
264264
# will later fail on downloading the repository and user will be

0 commit comments

Comments
 (0)