|
| 1 | +#!/usr/bin/env bash |
| 2 | +#============================================================================= |
| 3 | +# Copyright (C) 2025-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) |
| 4 | +# |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without |
| 8 | +# modification, are permitted provided that the following conditions are met: |
| 9 | +# * Redistributions of source code must retain the above copyright notice, |
| 10 | +# this list of conditions and the following disclaimer. |
| 11 | +# * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation |
| 13 | +# and/or other materials provided with the distribution. |
| 14 | +# * Neither the names of CEA, nor the names of the contributors may be used to |
| 15 | +# endorse or promote products derived from this software without specific |
| 16 | +# prior written permission. |
| 17 | +# |
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | +# POSSIBILITY OF SUCH DAMAGE. |
| 29 | +#============================================================================= |
| 30 | + |
| 31 | +# Use "./run-local-CI.sh" to run CI locally from a container |
| 32 | + |
| 33 | +set -euo pipefail |
| 34 | + |
| 35 | +# ----------- Config ------------------ |
| 36 | +IMAGE="ghcr.io/pdidev/ubuntu/rolling/openmpi/all:v4" |
| 37 | +TMP_DIR="/tmp_dir_test" |
| 38 | +BINARY_PATH="bin/build_and_run_all_tests" |
| 39 | +# ------------------------------------ |
| 40 | + |
| 41 | +if command -v podman &>/dev/null; then |
| 42 | + CONTAINER_CMD="podman" |
| 43 | + USERNS_ARGS="--userns=keep-id" |
| 44 | +elif command -v docker &>/dev/null; then |
| 45 | + CONTAINER_CMD="docker" |
| 46 | + USERNS_ARGS="--user $(id -u):$(id -g)" |
| 47 | +else |
| 48 | + echo "Error: neither podman nor docker found in PATH." >&2 |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +REPO_ROOT=$(git rev-parse --show-toplevel) |
| 53 | + |
| 54 | +if [[ ! -f "$REPO_ROOT/$BINARY_PATH" ]]; then |
| 55 | + echo "Script not found at $REPO_ROOT/$BINARY_PATH" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +echo -e "Running CI tests (using $CONTAINER_CMD)\n" |
| 60 | + |
| 61 | +$CONTAINER_CMD run --rm \ |
| 62 | + $USERNS_ARGS \ |
| 63 | + -v "$REPO_ROOT":/src \ |
| 64 | + --tmpfs "$TMP_DIR:exec" \ |
| 65 | + -e MAKEFLAGS="-j 4" \ |
| 66 | + -e TEST_DIR="/tmp_dir_test" \ |
| 67 | + -e CMAKE_FLAGS="-DBUILD_DOCUMENTATION=OFF" \ |
| 68 | + "$IMAGE" \ |
| 69 | + /src/bin/build_and_run_all_tests |
| 70 | + |
| 71 | +echo -e "\nDone" |
0 commit comments