Skip to content

Commit 413d1be

Browse files
authored
Runners: allow profile composition and renamed GitHub job (#18534)
Runners: allow profile composition and renamed GH job
1 parent 8f77b68 commit 413d1be

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

.github/workflows/linux-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ jobs:
9393
test-type: ${{ matrix.test-type }}
9494
tests: test/${{ matrix.test-type }}
9595

96-
linux_docker_tests:
96+
linux_runner_tests:
9797
needs: build_container
9898
runs-on: ubuntu-latest
9999
strategy:
100100
matrix:
101101
# Use modern versions due to docker incompatibility with python <3.8
102102
python-version: ${{ github.event_name != 'pull_request' && fromJson('["3.13", "3.9"]') || fromJson('["3.10"]') }}
103103

104-
name: Docker Runner Tests (${{ matrix.python-version }})
104+
name: Runner Tests (${{ matrix.python-version }})
105105
steps:
106106
- name: Checkout code
107107
uses: actions/checkout@v4
@@ -125,10 +125,10 @@ jobs:
125125
pip install -r conans/requirements_server.txt
126126
pip install -r conans/requirements_runner.txt
127127
128-
- name: Run tests
128+
- name: Run runner tests
129129
uses: ./.github/actions/test-coverage
130130
with:
131131
python-version: ${{ matrix.python-version }}
132-
test-type: docker
132+
test-type: runners
133133
tests: '-m docker_runner -rs'
134134
workers: 1

conan/internal/model/profile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
from collections import OrderedDict, defaultdict
33

4+
from conan.errors import ConanException
45
from conan.tools.env.environment import ProfileEnvironment
56
from conan.internal.model.conf import ConfDefinition
67
from conan.internal.model.options import Options
@@ -149,6 +150,11 @@ def compose_profile(self, other):
149150

150151
self.replace_requires.update(other.replace_requires)
151152
self.replace_tool_requires.update(other.replace_tool_requires)
153+
154+
runner_type = self.runner.get("type")
155+
other_runner_type = other.runner.get("type")
156+
if runner_type and other_runner_type and runner_type != other_runner_type:
157+
raise ConanException(f"Found different runner types in profile composition ({runner_type} and {other_runner_type})")
152158
self.runner.update(other.runner)
153159

154160
current_platform_tool_requires = {r.name: r for r in self.platform_tool_requires}

test/functional/command/runner_test.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
from conan.test.assets.sources import gen_function_h, gen_function_cpp
88

99

10+
def docker_from_env():
11+
try:
12+
return docker.from_env()
13+
except Exception:
14+
return docker.DockerClient(base_url=f'unix://{os.path.expanduser("~")}/.rd/docker.sock', version='auto') # Rancher
15+
16+
1017
def docker_skip(test_image='ubuntu:22.04'):
1118
try:
12-
try:
13-
docker_client = docker.from_env()
14-
except:
15-
docker_client = docker.DockerClient(base_url=f'unix://{os.path.expanduser("~")}/.rd/docker.sock', version='auto') # Rancher
19+
docker_client = docker_from_env()
1620
if test_image:
1721
docker_client.images.pull(test_image)
1822
except docker.errors.DockerException:
@@ -459,7 +463,7 @@ def test_create_docker_runner_from_configfile_with_args():
459463
client = TestClient()
460464

461465
# Ensure the network exists
462-
docker_client = docker.from_env()
466+
docker_client = docker_from_env()
463467
docker_client.networks.create("my-network")
464468

465469
configfile = textwrap.dedent(f"""
@@ -550,6 +554,45 @@ def test_create_docker_runner_default_build_profile():
550554
assert "Restore: pkg/0.2:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe metadata" in client.out
551555
assert "Removing container" in client.out
552556

557+
@pytest.mark.docker_runner
558+
@pytest.mark.skipif(docker_skip('ubuntu:22.04'), reason="Only docker running")
559+
def test_create_docker_runner_profile_composition():
560+
"""
561+
Tests the ``conan create . `` with profile composition
562+
"""
563+
client = TestClient()
564+
565+
profile = textwrap.dedent(f"""\
566+
[settings]
567+
arch={{{{ detect_api.detect_arch() }}}}
568+
build_type=Release
569+
compiler=gcc
570+
compiler.cppstd=gnu17
571+
compiler.libcxx=libstdc++11
572+
compiler.version=11
573+
os=Linux
574+
[runner]
575+
type=docker
576+
image=conan-runner-ninja-test
577+
""")
578+
579+
profile_extension = textwrap.dedent(f"""\
580+
[runner]
581+
type=docker
582+
dockerfile={dockerfile_path("Dockerfile_ninja")}
583+
build_context={conan_base_path()}
584+
cache=copy
585+
remove=True
586+
""")
587+
client.save({"profile": profile, "profile_extension": profile_extension})
588+
client.run("new cmake_lib -d name=pkg -d version=2.0")
589+
client.run("create . -pr:h profile -pr:h profile_extension")
590+
591+
assert "[100%] Built target example" in client.out
592+
assert "Restore: pkg/2.0 in pkgc6abef0178849" in client.out
593+
assert "Restore: pkg/2.0:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe" in client.out
594+
assert "Restore: pkg/2.0:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe metadata" in client.out
595+
553596

554597
@pytest.mark.docker_runner
555598
@pytest.mark.skipif(docker_skip(), reason="Only docker running")

0 commit comments

Comments
 (0)