diff --git a/.ci/build_matrix.sh b/.ci/build_matrix.sh index 67189fda44..a94781cf9c 100755 --- a/.ci/build_matrix.sh +++ b/.ci/build_matrix.sh @@ -7,7 +7,7 @@ # List of versions versions=( # if added more "latest", change "$LATEST" - 'latest-ubuntu' + 'v25.2-ubuntu-cicd' 'latest-ubuntu-student' 'v25.2.0' 'v25.1.0' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0b1d8f741..1d77c37176 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -223,7 +223,7 @@ jobs: strategy: fail-fast: false matrix: - mapdl-version: ['latest-ubuntu', 'v25.1-ubuntu'] + mapdl-version: ['v25.2-ubuntu-cicd', 'v25.1-ubuntu'] secrets: license-server: ${{ secrets.LICENSE_SERVER }} codecov-token: ${{ secrets.CODECOV_TOKEN }} @@ -245,7 +245,7 @@ jobs: strategy: fail-fast: false matrix: - mapdl-version: ['latest-ubuntu', 'v25.1-ubuntu'] + mapdl-version: ['v25.2-ubuntu-cicd', 'v25.1-ubuntu'] secrets: license-server: ${{ secrets.LICENSE_SERVER }} codecov-token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/test-local.yml b/.github/workflows/test-local.yml index 657eeb8a79..9273d1046c 100644 --- a/.github/workflows/test-local.yml +++ b/.github/workflows/test-local.yml @@ -48,9 +48,31 @@ on: tags: description: | Tags to add to the coverage report. - required: true + required: false type: string + codecov-report: + description: | + Whether to upload the coverage report to Codecov or not. If `true`, then the + appropriate token is needed. + required: false + default: true + type: boolean + + package-registry: + description: | + Package registry for the container. + required: false + type: string + default: ghcr.io/ansys/mapdl + + runner: + description: | + Runner to use. + required: false + type: string + default: ubuntu-22.04 + secrets: license-server: description: | @@ -74,7 +96,7 @@ on: jobs: test-local: - runs-on: ubuntu-22.04 + runs-on: ${{ inputs.runner }} env: ON_CI: True ON_LOCAL: true @@ -85,9 +107,11 @@ jobs: P_SCHEMA: "/ansys_inc/v241/ansys/ac4/schema" PYTEST_TIMEOUT: 120 # seconds. Limit the duration for each unit test PYTEST_ARGUMENTS: '-vvv -rxXsa --color=yes --durations=30 --random-order --random-order-bucket=class --maxfail=10 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html --timeout=180 --profile-svg --profile' + OMPI_ALLOW_RUN_AS_ROOT: 1 + OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1 container: - image: ghcr.io/ansys/mapdl:${{ inputs.mapdl-version }} + image: "${{ inputs.package-registry }}:${{ inputs.mapdl-version }}" options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash credentials: username: ${{ secrets.username }} @@ -96,6 +120,8 @@ jobs: steps: - name: "Install Git and checkout project" uses: actions/checkout@v4.2.2 + with: + repository: ansys/pymapdl - name: "Get if running student version" id: student_check @@ -115,13 +141,13 @@ jobs: shell: bash if: inputs.testing-minimal == true run: | - sudo apt-get update && apt install -y libgomp1 graphviz + apt-get update && apt install -y libgomp1 graphviz - name: "Installing OS packages" shell: bash if: inputs.testing-minimal == false run: | - sudo apt-get update && apt install -y libgl1-mesa-glx xvfb libgomp1 graphviz + apt-get update && apt install -y libgl1-mesa-glx xvfb libgomp1 graphviz - name: "Setup Python" uses: actions/setup-python@v5 @@ -228,6 +254,7 @@ jobs: - uses: codecov/codecov-action@v5 name: "Upload coverage to Codecov" + if: inputs.codecov-report == true with: token: ${{ secrets.codecov-token }} # required root_dir: ${{ github.workspace }} @@ -236,6 +263,7 @@ jobs: - name: "Upload coverage artifacts" uses: actions/upload-artifact@v4 + if: inputs.codecov-report == true with: name: ${{ inputs.file-name }}.xml path: ./${{ inputs.file-name }}.xml diff --git a/doc/changelog.d/3805.maintenance.md b/doc/changelog.d/3805.maintenance.md new file mode 100644 index 0000000000..aec4a60607 --- /dev/null +++ b/doc/changelog.d/3805.maintenance.md @@ -0,0 +1 @@ +ci: adapting workflow for new docker container \ No newline at end of file diff --git a/src/ansys/mapdl/core/launcher.py b/src/ansys/mapdl/core/launcher.py index 10486ea972..aa63a70e44 100644 --- a/src/ansys/mapdl/core/launcher.py +++ b/src/ansys/mapdl/core/launcher.py @@ -524,7 +524,7 @@ def launch_grpc( def check_mapdl_launch( - process: subprocess.Popen, run_location: str, timeout: int, cmd: str + process: subprocess.Popen[bytes], run_location: str, timeout: int, cmd: str ) -> None: """Check MAPDL launching process. @@ -554,7 +554,7 @@ def check_mapdl_launch( MAPDL did not start. """ LOG.debug("Generating queue object for stdout") - stdout_queue, thread = _create_queue_for_std(process.stdout) + stdout_queue, _ = _create_queue_for_std(process.stdout) # Checking connection try: @@ -564,7 +564,7 @@ def check_mapdl_launch( LOG.debug("Checking file error is created") _check_file_error_created(run_location, timeout) - if os.name == "posix" and not ON_WSL: + if os.name == "posix" and not ON_WSL and stdout_queue is not None: LOG.debug("Checking if gRPC server is alive.") _check_server_is_alive(stdout_queue, timeout) @@ -608,7 +608,7 @@ def _check_file_error_created(run_location, timeout): raise MapdlDidNotStart(msg) -def _check_server_is_alive(stdout_queue, timeout): +def _check_server_is_alive(stdout_queue: Queue[str], timeout: int): if not stdout_queue: LOG.debug("No STDOUT queue. Not checking MAPDL this way.") return @@ -644,11 +644,11 @@ def _check_server_is_alive(stdout_queue, timeout): raise MapdlDidNotStart("MAPDL failed to start the gRPC server") -def _get_std_output(std_queue, timeout=1): +def _get_std_output(std_queue: Queue[str], timeout: int = 1) -> List[str]: if not std_queue: - return [None] + return [""] - lines = [] + lines: List[str] = [] reach_empty = False t0 = time.time() while (not reach_empty) or (time.time() < (t0 + timeout)): diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 3507869e78..1980e94f52 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -615,7 +615,7 @@ def _multi_connect(self, n_attempts=5, timeout=15): # Process is alive raise MapdlConnectionError( msg - + f"The MAPDL process seems to be alive (PID: {self._mapdl_process.pid}) but PyMAPDL cannot connect to it." + + f" The MAPDL process seems to be alive (PID: {self._mapdl_process.pid}) but PyMAPDL cannot connect to it." ) else: pid_msg = ( diff --git a/tests/common.py b/tests/common.py index 9a7581f843..57c19f3fa2 100644 --- a/tests/common.py +++ b/tests/common.py @@ -26,7 +26,6 @@ import subprocess import time from typing import Dict, List -from warnings import warn import psutil @@ -268,13 +267,13 @@ def is_exited(mapdl: Mapdl): try: # to connect mapdl = Mapdl(port=port, ip=ip) - warn("MAPDL disconnected during testing, reconnected.") + LOG.warning("MAPDL disconnected during testing, reconnected.") except MapdlConnectionError as err: from conftest import DEBUG_TESTING, ON_LOCAL # Registering error. - LOG.info(str(err)) + LOG.warning(str(err)) # we cannot connect. # Kill the instance @@ -296,7 +295,7 @@ def is_exited(mapdl: Mapdl): log_apdl="pymapdl.apdl" if DEBUG_TESTING else None, mapdl_output="apdl.out" if (DEBUG_TESTING and ON_LOCAL) else None, ) - warn("MAPDL died during testing, relaunched.") + LOG.info("MAPDL died during testing, relaunched.") LOG.info("Successfully re-connected to MAPDL") diff --git a/tests/conftest.py b/tests/conftest.py index 87e6ed691d..6e9cb6f396 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,6 +77,7 @@ QUICK_LAUNCH_SWITCHES = "-smp -m 100 -db 100" VALID_PORTS = [] +ACCEPTABLE_FAILURE_RATE = 50 ## Skip ifs skip_on_windows = pytest.mark.skipif(ON_WINDOWS, reason="Skip on Windows") @@ -372,6 +373,24 @@ def pytest_collection_modifyitems(session, config, items): item.add_marker(skip_grpc) +@pytest.hookimpl() +def pytest_sessionfinish(session: pytest.Session, exitstatus: pytest.ExitCode): + if os.environ.get("ALLOW_FAILURE_RATE") is None: + return + + else: + acceptable_failure_rate = float( + os.environ.get("ALLOW_FAILURE_RATE", ACCEPTABLE_FAILURE_RATE) + ) + + if exitstatus != pytest.ExitCode.TESTS_FAILED: + return + + failure_rate = (100.0 * session.testsfailed) / session.testscollected + if failure_rate <= acceptable_failure_rate: + session.exitstatus = 0 + + ################################################################ # # Setting configuration fixtures diff --git a/tests/test_launcher.py b/tests/test_launcher.py index 88f5dc607f..8008560fa8 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -2072,7 +2072,7 @@ def test_check_server_is_alive_no_queue(): def test_get_std_output_no_queue(): from ansys.mapdl.core.launcher import _get_std_output - assert _get_std_output(None, 30) == [None] + assert _get_std_output(None, 30) == [""] def test_create_queue_for_std_no_queue():