diff --git a/.github/workflows/run_testsuite_workflow.yml b/.github/workflows/run_testsuite_workflow.yml index 447a459d8..ddf2f9cfe 100644 --- a/.github/workflows/run_testsuite_workflow.yml +++ b/.github/workflows/run_testsuite_workflow.yml @@ -59,7 +59,7 @@ jobs: rm -rf ./* rm -rf ./.??* ls -la ./ - - name: Check out Tutorials for them system tests (tools/tests/) + - name: Check out Tutorials for the system tests (tools/tests/) uses: actions/checkout@v4 with: repository: precice/tutorials diff --git a/.github/workflows/system-tests-pr.yml b/.github/workflows/system-tests-pr.yml index 920b7fab5..f7d0531f9 100644 --- a/.github/workflows/system-tests-pr.yml +++ b/.github/workflows/system-tests-pr.yml @@ -109,6 +109,7 @@ jobs: echo "\`\`\`" >> $GITHUB_STEP_SUMMARY echo "### Tutorials" >> $GITHUB_STEP_SUMMARY echo "Reference (pull request): \`${{ github.event.pull_request.head.sha }}\`" >> $GITHUB_STEP_SUMMARY + echo "Pull request number: [${{ github.event.number }}](https://github.com/precice/tutorials/pull/${{ github.event.number }})" >> $GITHUB_STEP_SUMMARY run-system-tests: name: Trigger system tests @@ -127,6 +128,7 @@ jobs: OPENFOAM_ADAPTER_REF:${{ needs.gather-refs.outputs.ref-openfoam-adapter }},\ SU2_VERSION:7.5.1,\ SU2_ADAPTER_REF:${{ needs.gather-refs.outputs.ref-su2-adapter }},\ + TUTORIALS_PR:${{ github.event.number }},\ TUTORIALS_REF:${{ github.event.pull_request.head.sha }}" system_tests_branch: develop log_level: "INFO" \ No newline at end of file diff --git a/changelog-entries/638.md b/changelog-entries/638.md new file mode 100644 index 000000000..7c77b1a05 --- /dev/null +++ b/changelog-entries/638.md @@ -0,0 +1 @@ +- Added support for running the system tests in forks [#638](https://github.com/precice/tutorials/pull/638) \ No newline at end of file diff --git a/tools/tests/components.yaml b/tools/tests/components.yaml index 904c035ec..74da0c6c4 100644 --- a/tools/tests/components.yaml +++ b/tools/tests/components.yaml @@ -2,15 +2,15 @@ bare: # A default component used when the solver does not have any dependencies repository: https://github.com/precice/precice template: component-templates/bare.yaml build_arguments: # these things mean something to the docker-service + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" @@ -19,35 +19,35 @@ python-bindings: repository: https://github.com/precice/python-bindings template: component-templates/python-bindings.yaml build_arguments: + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" PYTHON_BINDINGS_REF: - semnantic: Git ref of the pythonbindings to use + semnantic: Git ref of the Python bindings to use default: "master" openfoam-adapter: repository: https://github.com/precice/openfoam-adapter template: component-templates/openfoam-adapter.yaml build_arguments: + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" @@ -56,28 +56,27 @@ openfoam-adapter: description: exectuable of openfoam to use default: "openfoam2306" OPENFOAM_ADAPTER_REF: - description: Reference/tag of the actual OpenFOAM adapter + description: Reference/tag of the OpenFOAM adapter to use default: "master" - fenics-adapter: repository: https://github.com/precice/fenics-adapter template: component-templates/fenics-adapter.yaml build_arguments: + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" PYTHON_BINDINGS_REF: - semnantic: Git ref of the pythonbindings to use + semnantic: Git ref of the Python bindings to use default: "master" FENICS_ADAPTER_REF: semnantic: Git ref of the fenics adapter to use @@ -87,35 +86,35 @@ nutils-adapter: repository: https://github.com/precice/nutils-adapter template: component-templates/nutils-adapter.yaml build_arguments: + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" PYTHON_BINDINGS_REF: - semnantic: Git ref of the pythonbindings to use - + semnantic: Git ref of the Python bindings to use + default: "master" calculix-adapter: repository: https://github.com/precice/calculix-adapter template: component-templates/calculix-adapter.yaml build_arguments: + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" @@ -130,15 +129,15 @@ su2-adapter: repository: https://github.com/precice/su2-adapter template: component-templates/su2-adapter.yaml build_arguments: + PLATFORM: + description: Dockerfile platform used + default: "ubuntu_2404" PRECICE_REF: description: Version of preCICE to use default: "main" PRECICE_PRESET: description: CMake preset of preCICE default: "production-audit" - PLATFORM: - description: Dockerfile platform used - default: "ubuntu_2404" TUTORIALS_REF: description: Tutorial git reference to use default: "master" diff --git a/tools/tests/dockerfiles/ubuntu_2204/Dockerfile b/tools/tests/dockerfiles/ubuntu_2204/Dockerfile index b20eeb57c..4b313e7d4 100644 --- a/tools/tests/dockerfiles/ubuntu_2204/Dockerfile +++ b/tools/tests/dockerfiles/ubuntu_2204/Dockerfile @@ -47,12 +47,14 @@ RUN python3 -m pip install --user --upgrade pip FROM precice_dependecies AS precice # Install & build precice into /home/precice/precice +ARG PRECICE_PR ARG PRECICE_REF ARG PRECICE_PRESET USER precice WORKDIR /home/precice RUN git clone https://github.com/precice/precice.git precice && \ cd precice && \ + if [ -n "${PRECICE_PR}" ]; then git fetch origin pull/${PRECICE_PR}/head; fi && \ git checkout ${PRECICE_REF} && \ mkdir build && cd build &&\ cmake .. --preset=${PRECICE_PRESET} -DCMAKE_INSTALL_PREFIX=/home/precice/.local/ -DPRECICE_PETScMapping=OFF -DBUILD_TESTING=OFF && \ @@ -67,12 +69,14 @@ RUN apt-get update &&\ ln -s $(which ${OPENFOAM_EXECUTABLE} ) /usr/bin/openfoam USER precice COPY --from=precice /home/precice/.local/ /home/precice/.local/ +ARG OPENFOAM_ADAPTER_PR ARG OPENFOAM_ADAPTER_REF # Build the OpenFOAM adapter USER precice WORKDIR /home/precice RUN git clone https://github.com/precice/openfoam-adapter.git &&\ cd openfoam-adapter && \ + if [ -n "${OPENFOAM_ADAPTER_PR}" ]; then git fetch origin pull/${OPENFOAM_ADAPTER_PR}/head; fi && \ git checkout ${OPENFOAM_ADAPTER_REF} && \ /usr/bin/${OPENFOAM_EXECUTABLE} ./Allwmake -j $(nproc) @@ -119,10 +123,12 @@ RUN wget http://www.dhondt.de/ccx_${CALCULIX_VERSION}.src.tar.bz2 && \ tar xvjf ccx_${CALCULIX_VERSION}.src.tar.bz2 && \ rm -fv ccx_${CALCULIX_VERSION}.src.tar.bz2 +ARG CALCULIX_ADAPTER_PR ARG CALCULIX_ADAPTER_REF WORKDIR /home/precice RUN git clone https://github.com/precice/calculix-adapter.git && \ cd calculix-adapter && \ + if [ -n "${CALCULIX_ADAPTER_PR}" ]; then git fetch origin pull/${CALCULIX_ADAPTER_PR}/head; fi && \ git checkout ${CALCULIX_ADAPTER_REF} &&\ make CXX_VERSION=${CALCULIX_VERSION} ADDITIONAL_FFLAGS="-fallow-argument-mismatch" -j $(nproc) && \ ln -s /home/precice/calculix-adapter/bin/ccx_preCICE /home/precice/.local/bin/ccx_preCICE @@ -141,6 +147,7 @@ RUN wget https://github.com/su2code/SU2/archive/refs/tags/v${SU2_VERSION}.tar.gz tar xvzf v${SU2_VERSION}.tar.gz && \ rm -fv v${SU2_VERSION}.tar.gz RUN pip3 install --user mpi4py +ARG SU2_ADAPTER_PR ARG SU2_ADAPTER_REF WORKDIR /home/precice ENV SU2_RUN="/home/precice/SU2_RUN" @@ -149,6 +156,7 @@ ENV PATH="/home/precice/su2-adapter/run:$SU2_RUN:$PATH" ENV PYTHONPATH="$SU2_RUN:$PYTHONPATH" RUN git clone https://github.com/precice/su2-adapter.git && \ cd su2-adapter &&\ + if [ -n "${SU2_ADAPTER_PR}" ]; then git fetch origin pull/${SU2_ADAPTER_PR}/head; fi && \ git checkout ${SU2_ADAPTER_REF} &&\ ./su2AdapterInstall RUN cd "${SU2_HOME}" &&\ diff --git a/tools/tests/dockerfiles/ubuntu_2404/Dockerfile b/tools/tests/dockerfiles/ubuntu_2404/Dockerfile index 50c55ada0..11f4657c1 100644 --- a/tools/tests/dockerfiles/ubuntu_2404/Dockerfile +++ b/tools/tests/dockerfiles/ubuntu_2404/Dockerfile @@ -45,12 +45,14 @@ USER precice FROM precice_dependecies AS precice # Install & build precice into /home/precice/precice +ARG PRECICE_PR ARG PRECICE_REF ARG PRECICE_PRESET USER precice WORKDIR /home/precice RUN git clone https://github.com/precice/precice.git precice && \ cd precice && \ + if [ -n "${PRECICE_PR}" ]; then git fetch origin pull/${PRECICE_PR}/head; fi && \ git checkout ${PRECICE_REF} && \ mkdir build && cd build &&\ cmake .. --preset=${PRECICE_PRESET} -DCMAKE_INSTALL_PREFIX=/home/precice/.local/ -DPRECICE_PETScMapping=OFF -DBUILD_TESTING=OFF && \ @@ -65,12 +67,14 @@ RUN apt-get update &&\ ln -s $(which ${OPENFOAM_EXECUTABLE} ) /usr/bin/openfoam USER precice COPY --from=precice /home/precice/.local/ /home/precice/.local/ +ARG OPENFOAM_ADAPTER_PR ARG OPENFOAM_ADAPTER_REF # Build the OpenFOAM adapter USER precice WORKDIR /home/precice RUN git clone https://github.com/precice/openfoam-adapter.git &&\ cd openfoam-adapter && \ + if [ -n "${OPENFOAM_ADAPTER_PR}" ]; then git fetch origin pull/${OPENFOAM_ADAPTER_PR}/head; fi && \ git checkout ${OPENFOAM_ADAPTER_REF} && \ /usr/bin/${OPENFOAM_EXECUTABLE} ./Allwmake -j $(nproc) @@ -123,10 +127,12 @@ RUN wget http://www.dhondt.de/ccx_${CALCULIX_VERSION}.src.tar.bz2 && \ tar xvjf ccx_${CALCULIX_VERSION}.src.tar.bz2 && \ rm -fv ccx_${CALCULIX_VERSION}.src.tar.bz2 +ARG CALCULIX_ADAPTER_PR ARG CALCULIX_ADAPTER_REF WORKDIR /home/precice RUN git clone https://github.com/precice/calculix-adapter.git && \ cd calculix-adapter && \ + if [ -n "${CALCULIX_ADAPTER_PR}" ]; then git fetch origin pull/${CALCULIX_ADAPTER_PR}/head; fi && \ git checkout ${CALCULIX_ADAPTER_REF} &&\ make CXX_VERSION=${CALCULIX_VERSION} ADDITIONAL_FFLAGS="-fallow-argument-mismatch" -j $(nproc) && \ ln -s /home/precice/calculix-adapter/bin/ccx_preCICE /home/precice/.local/bin/ccx_preCICE @@ -147,6 +153,7 @@ RUN wget https://github.com/su2code/SU2/archive/refs/tags/v${SU2_VERSION}.tar.gz rm -fv v${SU2_VERSION}.tar.gz RUN python3 -m venv /home/precice/venv && \ . /home/precice/venv/bin/activate +ARG SU2_ADAPTER_PR ARG SU2_ADAPTER_REF WORKDIR /home/precice ENV SU2_RUN="/home/precice/SU2_RUN" @@ -155,6 +162,7 @@ ENV PATH="/home/precice/su2-adapter/run:$SU2_RUN:$PATH" ENV PYTHONPATH="$SU2_RUN:$PYTHONPATH" RUN git clone https://github.com/precice/su2-adapter.git && \ cd su2-adapter &&\ + if [ -n "${SU2_ADAPTER_PR}" ]; then git fetch origin pull/${SU2_ADAPTER_PR}/head; fi && \ git checkout ${SU2_ADAPTER_REF} &&\ ./su2AdapterInstall RUN cd "${SU2_HOME}" &&\ diff --git a/tools/tests/systemtests/Systemtest.py b/tools/tests/systemtests/Systemtest.py index 49e30f2e8..78ff9680f 100644 --- a/tools/tests/systemtests/Systemtest.py +++ b/tools/tests/systemtests/Systemtest.py @@ -146,30 +146,26 @@ def __post_init__(self): def __init_args_to_use(self): """ - Checks if all required parameters for the realisation of the cases are supplied in the cmdline arguments. - If a parameter is missing and it's required, an exception is raised. - Otherwise, the default value is used if available. + Forwards the command-line arguments to the params_to_use dictionary, substituting any missing arguments with their defaults. - In the end it populates the args_to_use dict - - Raises: - Exception: If a required parameter is missing. + Previously, this function was also checking if all required parameters were provided, and was raising exceptions for parameters not provided and not having a default value. This check made adding optional parameters with empty defaults (e.g., the TUTORIALS_PR) complicated, and it was removed. """ - self.params_to_use = {} + + # Forward all provided arguments to params_to_use + provided_arguments = self.arguments.arguments + self.params_to_use = provided_arguments + + # Find out which parameters are needed needed_parameters = set() for case in self.case_combination.cases: needed_parameters.update(case.component.parameters) + # Substitute defaults for non-provided, needed arguments for needed_param in needed_parameters: - if self.arguments.contains(needed_param.key): - self.params_to_use[needed_param.key] = self.arguments.get( - needed_param.key) - else: - if needed_param.required: - raise Exception( - f"{needed_param} is needed to be given via --params to instantiate the systemtest for {self.tutorial.name}") - else: - self.params_to_use[needed_param.key] = needed_param.default + if not needed_param.key in provided_arguments: + logging.warning( + f"No argument provided for needed parameter {needed_param.key}. Substituting with {needed_param.default}") + self.params_to_use[needed_param.key] = needed_param.default def __get_docker_services(self) -> Dict[str, str]: """ @@ -249,6 +245,19 @@ def _get_git_ref(self, repository: Path, abbrev_ref=False) -> Optional[str]: except Exception as e: raise RuntimeError(f"An error occurred while getting the current Git ref: {e}") from e + def _fetch_pr(self, repository: Path, pr: str): + try: + result = subprocess.run([ + "git", + "-C", os.fspath(repository.resolve()), + "fetch", + "origin", + "pull/" + pr + "/head" + ], check=True, timeout=60) + + except Exception as e: + raise RuntimeError(f"git command returned code {result.returncode}") + def _fetch_ref(self, repository: Path, ref: str): try: result = subprocess.run([ @@ -282,6 +291,10 @@ def __copy_tutorial_into_directory(self, run_directory: Path): """ current_time_string = datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.run_directory = run_directory + pr_requested = self.params_to_use.get("TUTORIALS_PR") + if pr_requested: + logging.debug(f"Fetching the PR {pr_requested} HEAD reference") + self._fetch_pr(PRECICE_TUTORIAL_DIR, pr_requested) current_ref = self._get_git_ref(PRECICE_TUTORIAL_DIR) ref_requested = self.params_to_use.get("TUTORIALS_REF") if ref_requested: