Skip to content

Commit e90acb4

Browse files
committed
WIP: Run CI tests against multiple versions
1 parent dbbe385 commit e90acb4

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
@@ -173,7 +173,7 @@ jobs:
173173
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
174174

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

1212

1313
class TestInfrahubNode(TestInfrahubDockerClient, SchemaCarPerson):
14-
@pytest.fixture(scope="class")
15-
def infrahub_version(self) -> str:
16-
return "1.1.0"
17-
1814
@pytest.fixture(scope="class")
1915
async def initial_schema(self, default_branch: str, client: InfrahubClient, schema_base: SchemaRoot) -> None:
2016
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)