diff --git a/AUTHORS b/AUTHORS index 402523718..6b364fe10 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,8 +4,9 @@ spirit, we list here in alphabetical order a condensed list of their contributio Julian Auriac - CEA (julian.auriac@cea.fr) * Add mock PDI * Fix CI bug where tests.xml file could not be written -* Improvement of a Decl'HDF5 test to work on OSX -* Addition of API tests +* Add local CI +* Improve a Decl'HDF5 test to work on OSX +* Add API tests Julien Bigot - CEA (julien.bigot@cea.fr) * Initial design and implementation diff --git a/bin/build_and_run_all_tests b/bin/build_and_run_all_tests index b77e6ae57..b7f2ab232 100755 --- a/bin/build_and_run_all_tests +++ b/bin/build_and_run_all_tests @@ -35,7 +35,11 @@ set -xe # Setup our directories -SRCDIR="${PWD}" +# Set SRCDIR only if not provided +if [[ -z "${SRCDIR:-}" ]]; then + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + SRCDIR="$(cd "$SCRIPT_DIR/.." && pwd)" +fi if [ -z "${TEST_DIR}" ] then @@ -46,10 +50,6 @@ else TEST_DIR="${PWD}" fi -cd "${SRCDIR}" -cd "$(dirname "$0")/.." -SRCDIR="${PWD}" - cd "${TEST_DIR}" diff --git a/run-local-CI-indent.sh b/run-local-CI-indent.sh new file mode 100755 index 000000000..105076e06 --- /dev/null +++ b/run-local-CI-indent.sh @@ -0,0 +1,24 @@ +set -euo pipefail + +IMAGE="ghcr.io/pdidev/run_clang_format:v4" + +echo "Collecting files from git..." + +FILES=$(git ls-files \ + | grep -v '^vendor/' \ + | grep -E '\.(c|h|cc|hh|cpp|hpp|cxx|hxx)$') + +if [ -z "$FILES" ]; then + echo "No files to check." + exit 0 +fi + +echo "Running clang-format container..." + +podman run --rm \ + --userns=keep-id \ + -v "$PWD":/src \ + -w /src \ + "$IMAGE" \ + "$@" \ + $FILES diff --git a/run-local-CI.sh b/run-local-CI.sh new file mode 100755 index 000000000..cb739ef9d --- /dev/null +++ b/run-local-CI.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +#============================================================================= +# Copyright (C) 2025-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the names of CEA, nor the names of the contributors may be used to +# endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +set -euo pipefail + +# ----------- Config ------------------ +IMAGE="ghcr.io/pdidev/ubuntu/rolling/openmpi/all:v4" +SCRIPT_NAME="run.sh" +SCRIPT_DIR="./.ci_tmp" +REPORT_FILE="tests.xml" +TMP_DIR="/tmp_dir_test" +BINARY_PATH="./bin/build_and_run_all_tests" +# ------------------------------------ + +mkdir -p "$SCRIPT_DIR" +rm -f "$SCRIPT_DIR/$SCRIPT_NAME" "$REPORT_FILE" + +# Make sure the binary exists and is executable +if [[ ! -f "$BINARY_PATH" ]]; then + echo "Binary not found at $BINARY_PATH" + exit 1 +fi + +echo "Generating $SCRIPT_NAME in $SCRIPT_DIR..." +cat < "$SCRIPT_DIR/$SCRIPT_NAME" +#!/bin/bash +set -xe + +JOBID="\$(echo "manual-run" | md5sum | cut -b 1)" +if [[ "01234567" == *"\${JOBID}"* ]]; then + export PDI_PLUGIN_PATH=/tmp/pdi_plugins +fi + +export MAKEFLAGS='-j 4' +export CTEST_FLAGS="--output-junit /tmp/tests.xml" +export TEST_DIR="/tmp_dir_test" +export SRCDIR="/src" +export CMAKE_FLAGS="-DBUILD_DOCUMENTATION=OFF" + +chmod +x /tmp/build_and_run_all_tests +/tmp/build_and_run_all_tests +EOF + +chmod +x "$SCRIPT_DIR/$SCRIPT_NAME" + +echo "Creating and preparing container..." +CONTAINER_ID=$(podman create \ + --userns=keep-id \ + -v "$PWD":/src \ + --tmpfs "$TMP_DIR:exec" \ + "$IMAGE" \ + bash /tmp/run.sh) + +echo "Copying script and binary into container..." +podman cp "$SCRIPT_DIR/$SCRIPT_NAME" "$CONTAINER_ID:/tmp/run.sh" +podman cp "$BINARY_PATH" "$CONTAINER_ID:/tmp/build_and_run_all_tests" + +echo "Starting container and running script..." +podman start --attach "$CONTAINER_ID" + +echo "Attempting to extract test report from container..." +if podman cp "$CONTAINER_ID":/tmp/tests.xml "$REPORT_FILE"; then + echo "Test report saved as $REPORT_FILE" +else + echo "Test report not found in container." +fi + +echo "Cleaning up container..." +podman rm "$CONTAINER_ID" >/dev/null 2>&1 || true