Skip to content

Commit

Permalink
Removing secrets from CICD: Part I Docs and local (#2583)
Browse files Browse the repository at this point in the history
* Testing student version in doc build

* testing student version in local build

* fix more stuff

* adding username

* trying to not reach user limit on student license.

* atempt to fix MPI error

* test mpi fix

* Allowing missing licenses in check

* removing stuff

* remvoing smp variable

* using it own starting script

* returning to previous start_mapdl

* git fix permission

* skipping test if on CICD

* removing smp

* Skipping another test because it takes too long to check

* Setting student version

* wrong skipif

* Avoiding globbing and codecov issues

* Adding support to v24.1

* skipping another test
  • Loading branch information
germa89 authored Dec 22, 2023
1 parent 3116017 commit d08bdd4
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 36 deletions.
12 changes: 12 additions & 0 deletions .ci/start_mapdl_student.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
docker pull "$MAPDL_IMAGE"
docker run \
--name mapdl \
--restart always \
-e ANSYS_LOCK="OFF" \
-p "$PYMAPDL_PORT":50052 \
-p "$PYMAPDL_DB_PORT":50055 \
--shm-size=2gb \
-e P_SCHEMA=/ansys_inc/v241/ansys/ac4/schema \
"$MAPDL_IMAGE" > log.txt &
# grep -q 'Server listening on' <(timeout 60 tail -f log.txt)
47 changes: 24 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ env:
DPF_START_SERVER: False
DPF_PORT: 21002
DOCKER_PACKAGE: ghcr.io/ansys/mapdl
DOCKER_IMAGE_VERSION_DOCS_BUILD: v23.1.0
DOCKER_IMAGE_VERSION_DOCS_BUILD: v24.1-ubuntu-student
ON_CI: True
PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=1 --reruns 1 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html'
PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=5 --reruns 2 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html'

# Following env vars when changed will "reset" the mentioned cache,
# by changing the cache file name. It is rendered as ...-v%RESET_XXX%-...
Expand Down Expand Up @@ -143,13 +143,12 @@ jobs:
uses: docker/login-action@v3.0.0
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "Pull, launch, and validate MAPDL service"
run: .ci/start_mapdl.sh
run: .ci/start_mapdl_student.sh
env:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
MAPDL_IMAGE: '${{ env.DOCKER_PACKAGE }}:${{ env.DOCKER_IMAGE_VERSION_DOCS_BUILD }}'

- name: "Retrieve PyMAPDL version"
Expand Down Expand Up @@ -472,15 +471,16 @@ jobs:
committed: ${{ steps.attatch-to-pr.outputs.committed }}
commit_long_sha: ${{ steps.attatch-to-pr.outputs.commit_long_sha }}
container:
image: ghcr.io/ansys/mapdl:v22.2-ubuntu
image: ghcr.io/ansys/mapdl:v24.1-ubuntu-student
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
credentials:
username: ${{ secrets.GH_USERNAME }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
ON_LOCAL: true
ON_UBUNTU: true
P_SCHEMA: "/ansys_inc/v222/ansys/ac4/schema"
ON_STUDENT: true
P_SCHEMA: "/ansys_inc/v241/ansys/ac4/schema"
PYTEST_TIMEOUT: 120 # seconds. Limit the duration for each unit test

steps:
Expand Down Expand Up @@ -533,12 +533,12 @@ jobs:
run: |
unset PYMAPDL_PORT
unset PYMAPDL_START_INSTANCE
export ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}
# export ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}
export AWP_ROOT222=/ansys_inc
xvfb-run pytest -k "not test_dpf" \
${{ env.PYTEST_ARGUMENTS }} \
--reset_only_failed --add_missing_images \
--cov-report=xml:ubuntu-v22.2.0-local.xml
--cov-report=xml:ubuntu-v24.1.0-local.xml
- name: "Adding the directory as safe directory for later step"
run: |
Expand Down Expand Up @@ -578,14 +578,14 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
root_dir: ${{ github.workspace }}
name: ubuntu-v22.2.0-local.xml
flags: ubuntu,local,v22.2.0
name: ubuntu-v24.1.0-local.xml
flags: ubuntu,local,v24.1.0

- name: 'Upload coverage artifacts'
uses: actions/upload-artifact@v4
with:
name: ubuntu-v22.2.0-local.xml
path: ./ubuntu-v22.2.0-local.xml
name: ubuntu-v24.1.0-local.xml
path: ./ubuntu-v24.1.0-local.xml

- name: 'Upload minimal requirements file'
# To include it in the release
Expand All @@ -601,16 +601,17 @@ jobs:
if: github.ref != 'refs/heads/main' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
timeout-minutes: 55
container:
image: ghcr.io/ansys/mapdl:v22.2-ubuntu
image: ghcr.io/ansys/mapdl:v24.1-ubuntu-student
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
credentials:
username: ${{ secrets.GH_USERNAME }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
ON_LOCAL: true
ON_UBUNTU: true
ON_STUDENT: true
# Because there is no 'ansys-tools-path' we need to input the executable path.
PYMAPDL_MAPDL_EXEC: /ansys_inc/v222/ansys/bin/ansys222
PYMAPDL_MAPDL_EXEC: /ansys_inc/v241/ansys/bin/ansys241

steps:
- name: "Install Git and checkout project"
Expand Down Expand Up @@ -647,24 +648,24 @@ jobs:
- name: "Unit testing"
run: |
unset PYMAPDL_START_INSTANCE
export ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}
# export ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}
pytest -k "not test_dpf" \
${{ env.PYTEST_ARGUMENTS }} \
--cov-report=xml:ubuntu-v22.2.0-local-minimal.xml
--cov-report=xml:ubuntu-v24.1.0-local-minimal.xml
- uses: codecov/codecov-action@v3
name: "Upload coverage to Codecov"
with:
token: ${{ secrets.CODECOV_TOKEN }}
root_dir: ${{ github.workspace }}
name: ubuntu-v22.2.0-local-minimal.xml
flags: ubuntu,local,v22.2.0,minimal
name: ubuntu-v24.1.0-local-minimal.xml
flags: ubuntu,local,v24.1.0,minimal

- name: 'Upload coverage artifacts'
uses: actions/upload-artifact@v4
with:
name: ubuntu-v22.2.0-local-minimal.xml
path: ./ubuntu-v22.2.0-local-minimal.xml
name: ubuntu-v24.1.0-local-minimal.xml
path: ./ubuntu-v24.1.0-local-minimal.xml


test-windows:
Expand Down
1 change: 1 addition & 0 deletions src/ansys/mapdl/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# In descending order
SUPPORTED_ANSYS_VERSIONS = {
241: "2024R1",
232: "2023R2",
231: "2023R1",
222: "2022R2",
Expand Down
4 changes: 4 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def support_plotting():
return False


def is_running_on_student():
return os.environ.get("ON_STUDENT", "NO").upper().strip() in ["YES", "TRUE"]


def testing_minimal():
return os.environ.get("TESTING_MINIMAL", "NO").upper().strip() in ["YES", "TRUE"]

Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
is_on_ci,
is_on_local,
is_on_ubuntu,
is_running_on_student,
is_smp,
support_plotting,
testing_minimal,
Expand All @@ -32,6 +33,7 @@

ON_LOCAL = is_on_local()
ON_CI = is_on_ci()
ON_STUDENT = is_running_on_student()

ON_UBUNTU = is_on_ubuntu() # Tells if MAPDL is running on Ubuntu system or not.
# Whether PyMAPDL is running on an ubuntu or different machine is irrelevant.
Expand Down Expand Up @@ -82,6 +84,11 @@
not ON_CI, reason="This test requires to be on CICD"
)

skip_if_running_student_version = pytest.mark.skipif(
ON_STUDENT,
reason="This tests does not work on student version. Maybe because license limitations",
)


def has_dependency(requirement):
try:
Expand Down Expand Up @@ -125,6 +132,9 @@ def requires(requirement: str):
elif "nowindows" == requirement:
return skip_on_windows

elif "nostudent" == requirement:
return skip_if_running_student_version

elif "console" == requirement:
return pytest.mark.console

Expand Down
34 changes: 23 additions & 11 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import os
import tempfile
from time import sleep

import pytest

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core.errors import LicenseServerConnectionError
from ansys.mapdl.core.errors import LicenseServerConnectionError, MapdlDidNotStart
from ansys.mapdl.core.launcher import (
_check_license_argument,
_force_smp_student_version,
Expand Down Expand Up @@ -144,24 +145,34 @@ def test_launch_console(version):


@requires("local")
@requires("nostudent")
def test_license_type_keyword():
checks = []
for license_name, license_description in LICENSES.items():
mapdl = launch_mapdl(
license_type=license_name,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

# Using first line to ensure not picking up other stuff.
checks.append(license_description in mapdl.__str__().split("\n")[0])
mapdl.exit()
del mapdl
try:
mapdl = launch_mapdl(
license_type=license_name,
start_timeout=start_timeout,
additional_switches=QUICK_LAUNCH_SWITCHES,
)

# Using first line to ensure not picking up other stuff.
checks.append(license_description in mapdl.__str__().split("\n")[0])
mapdl.exit()
del mapdl
sleep(2)

except MapdlDidNotStart as e:
if "ANSYS license not available" in str(e):
continue
else:
raise e

assert any(checks)


@requires("local")
@requires("nostudent")
def test_license_type_keyword_names():
# This test might became a way to check available licenses, which is not the purpose.

Expand All @@ -184,6 +195,7 @@ def test_license_type_keyword_names():


@requires("local")
@requires("nostudent")
def test_license_type_additional_switch():
# This test might became a way to check available licenses, which is not the purpose.
successful_check = False
Expand Down
1 change: 1 addition & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,7 @@ def test_igesin_whitespace(mapdl, cleared, tmpdir):


@requires("local")
@requires("nostudent")
def test_save_on_exit(mapdl, cleared):
mapdl2 = launch_mapdl(
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

from conftest import has_dependency
from conftest import ON_STUDENT, has_dependency

if has_dependency("ansys-tools-path"):
from ansys.tools.path import find_ansys
Expand All @@ -15,7 +15,7 @@
else:
EXEC_FILE = os.environ.get("PYMAPDL_MAPDL_EXEC")

if not EXEC_FILE:
if not EXEC_FILE or ON_STUDENT:
pytest.skip(allow_module_level=True)

from ansys.mapdl.core import LocalMapdlPool, examples
Expand Down

0 comments on commit d08bdd4

Please sign in to comment.