Skip to content

Commit d765bda

Browse files
LucasG0dgarros
authored andcommitted
WIP: Run CI tests against multiple versions
1 parent 984285f commit d765bda

File tree

5 files changed

+111
-16
lines changed

5 files changed

+111
-16
lines changed

.github/workflows/ci.yml

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jobs:
174174
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
175175

176176
# ------------------------------------------ Integration Tests ------------------------------------------
177-
integration-tests:
177+
integration-tests-latest-infrahub:
178178
if: |
179179
always() && !cancelled() &&
180180
!contains(needs.*.result, 'failure') &&
@@ -202,8 +202,87 @@ jobs:
202202
pip install invoke toml codecov
203203
- name: "Install Package"
204204
run: "poetry install --all-extras"
205+
- name: "Set environment variables for python_testcontainers"
206+
run: |
207+
echo INFRAHUB_TESTING_IMAGE_VER=latest >> $GITHUB_ENV
205208
- name: "Integration Tests"
206-
run: "poetry run pytest --cov infrahub_sdk tests/integration/"
209+
run: |
210+
poetry run pytest --cov infrahub_sdk tests/integration/
211+
- name: "Upload coverage to Codecov"
212+
run: |
213+
codecov --flags integration-tests
214+
env:
215+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
216+
217+
integration-tests-local-infrahub:
218+
if: |
219+
always() && !cancelled() &&
220+
!contains(needs.*.result, 'failure') &&
221+
!contains(needs.*.result, 'cancelled') &&
222+
needs.files-changed.outputs.python == 'true' &&
223+
(github.base_ref == 'stable' || github.base_ref == 'develop')
224+
needs: ["files-changed", "yaml-lint", "python-lint"]
225+
runs-on:
226+
group: "huge-runners"
227+
timeout-minutes: 30
228+
steps:
229+
- name: "Check out repository code"
230+
uses: "actions/checkout@v4"
231+
232+
- name: "Extract target branch name"
233+
id: extract_branch
234+
run: echo "TARGET_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV
235+
236+
- name: "Checkout infrahub repository"
237+
uses: "actions/checkout@v4"
238+
with:
239+
repository: "opsmill/infrahub"
240+
path: "infrahub-server"
241+
ref: ${{ github.base_ref }}
242+
submodules: true
243+
244+
- name: Set up Python
245+
uses: actions/setup-python@v5
246+
with:
247+
python-version: "3.12"
248+
249+
- name: "Setup git credentials prior dev.build"
250+
run: |
251+
cd infrahub-server
252+
git config --global user.name 'Infrahub'
253+
git config --global user.email '[email protected]'
254+
git config --global --add safe.directory '*'
255+
git config --global credential.usehttppath true
256+
git config --global credential.helper /usr/local/bin/infrahub-git-credential
257+
258+
- name: "Set environment variables prior dev.build"
259+
run: |
260+
echo "INFRAHUB_BUILD_NAME=infrahub-${{ runner.name }}" >> $GITHUB_ENV
261+
RUNNER_NAME=$(echo "${{ runner.name }}" | grep -o 'ghrunner[0-9]\+' | sed 's/ghrunner\([0-9]\+\)/ghrunner_\1/')
262+
echo "PYTEST_DEBUG_TEMPROOT=/var/lib/github/${RUNNER_NAME}/_temp" >> $GITHUB_ENV
263+
echo "INFRAHUB_IMAGE_VER=local-${{ runner.name }}-${{ github.sha }}" >> $GITHUB_ENV
264+
echo "INFRAHUB_TESTING_IMAGE_VER=local-${{ runner.name }}-${{ github.sha }}" >> $GITHUB_ENV
265+
echo "INFRAHUB_TESTING_DOCKER_IMAGE=opsmill/infrahub" >> $GITHUB_ENV
266+
267+
- name: "Build container"
268+
run: |
269+
cd infrahub-server
270+
inv dev.build
271+
272+
- name: "Setup environment"
273+
run: |
274+
pipx install poetry==1.8.5
275+
poetry config virtualenvs.create true --local
276+
pip install invoke toml codecov
277+
278+
- name: "Install Package"
279+
run: "poetry install --all-extras"
280+
281+
- name: "Integration Tests"
282+
run: |
283+
echo "Running tests for version: $INFRAHUB_TESTING_IMAGE_VER"
284+
poetry run pytest --cov infrahub_sdk tests/integration/
285+
207286
- name: "Upload coverage to Codecov"
208287
run: |
209288
codecov --flags integration-tests

infrahub_sdk/testing/docker.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1+
from __future__ import annotations
2+
3+
import os
4+
15
import pytest
26
from infrahub_testcontainers.helpers import TestInfrahubDocker
7+
from packaging.version import InvalidVersion, Version
38

49
from .. import Config, InfrahubClient, InfrahubClientSync
510

11+
INFRAHUB_VERSION = os.getenv("INFRAHUB_TESTING_IMAGE_VER", "latest")
12+
13+
14+
def skip_version(min_infrahub_version: str | None = None, max_infrahub_version: str | None = None) -> bool:
15+
"""
16+
Check if a test should be skipped depending on infrahub version.
17+
"""
18+
try:
19+
version = Version(INFRAHUB_VERSION)
20+
except InvalidVersion:
21+
# We would typically end up here for development purpose while running a CI test against
22+
# unreleased versions of infrahub, like `stable` or `develop` branch.
23+
# For now, we consider this means we are testing against the most recent version of infrahub,
24+
# so we skip if the test should not be ran against a maximum version.
25+
return max_infrahub_version is None
26+
27+
if min_infrahub_version is not None and version < Version(min_infrahub_version):
28+
return True
29+
30+
return max_infrahub_version is not None and version > Version(max_infrahub_version)
31+
632

733
class TestInfrahubDockerClient(TestInfrahubDocker):
34+
@pytest.fixture(scope="class")
35+
def infrahub_version(self) -> str:
36+
return INFRAHUB_VERSION
37+
838
@pytest.fixture(scope="class")
939
def client(self, infrahub_port: int) -> InfrahubClient:
1040
return InfrahubClient(

tests/integration/test_infrahub_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717

1818
class TestInfrahubNode(TestInfrahubDockerClient, SchemaAnimal):
19-
@pytest.fixture(scope="class")
20-
def infrahub_version(self) -> str:
21-
return "1.1.0"
22-
2319
@pytest.fixture(scope="class")
2420
async def base_dataset(
2521
self,

tests/integration/test_node.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99

1010

1111
class TestInfrahubNode(TestInfrahubDockerClient, SchemaCarPerson):
12-
@pytest.fixture(scope="class")
13-
def infrahub_version(self) -> str:
14-
return "1.1.0"
15-
1612
@pytest.fixture(scope="class")
1713
async def initial_schema(self, default_branch: str, client: InfrahubClient, schema_base: SchemaRoot) -> None:
1814
await client.schema.wait_until_converged(branch=default_branch)

tests/integration/test_repository.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import TYPE_CHECKING
44

5-
import pytest
6-
75
from infrahub_sdk.testing.docker import TestInfrahubDockerClient
86
from infrahub_sdk.testing.repository import GitRepo
97
from infrahub_sdk.utils import get_fixtures_dir
@@ -13,10 +11,6 @@
1311

1412

1513
class TestInfrahubRepository(TestInfrahubDockerClient):
16-
@pytest.fixture(scope="class")
17-
def infrahub_version(self) -> str:
18-
return "1.1.0"
19-
2014
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir):
2115
src_directory = get_fixtures_dir() / "integration/mock_repo"
2216
repo = GitRepo(name="mock_repo", src_directory=src_directory, dst_directory=remote_repos_dir)

0 commit comments

Comments
 (0)