| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced |
| 4 |
# at the Lawrence Livermore National Laboratory. All Rights reserved. See files |
| 5 |
# LICENSE and NOTICE for details. LLNL-CODE-806117. |
| 6 |
# |
| 7 |
# This file is part of the MFEM library. For more information and source code |
| 8 |
# availability visit https://mfem.org. |
| 9 |
# |
| 10 |
# MFEM is free software; you can redistribute it and/or modify it under the |
| 11 |
# terms of the BSD-3 license. We welcome feedback and contributions, see file |
| 12 |
# CONTRIBUTING.md for details. |
| 13 |
|
| 14 |
function info_msg () |
| 15 |
{ |
| 16 |
echo "[Information:] ${1}" |
| 17 |
} |
| 18 |
|
| 19 |
function error_msg () |
| 20 |
{ |
| 21 |
echo "[Error:] ${1}" |
| 22 |
} |
| 23 |
|
| 24 |
# Perform a report while holding a lock file to prevent concurrency on |
| 25 |
# the destination. |
| 26 |
# Usage: |
| 27 |
# locked_clone <report_function> <lock_name> |
| 28 |
function locked_report () |
| 29 |
{ |
| 30 |
if ! command -v flock |
| 31 |
then |
| 32 |
error_msg "Required command 'flock' not found" |
| 33 |
exit 1 |
| 34 |
fi |
| 35 |
|
| 36 |
info_msg "Will report ${1} while holding a lock in ${2}" |
| 37 |
|
| 38 |
( date; info_msg "Waiting to acquire lock on '${PWD}/${2}.lock' ..." |
| 39 |
# try to get an exclusive lock on fd 9 (mfem-data.lock) repeating the |
| 40 |
# try every 5 seconds; we may want to add a counter for the number of |
| 41 |
# retries to interrupt a potential infinite loop |
| 42 |
while ! flock -n 9; do sleep 5; done |
| 43 |
date; info_msg "Acquired lock on '${PWD}/${2}.lock'" |
| 44 |
|
| 45 |
report ${1} |
| 46 |
err=$? |
| 47 |
|
| 48 |
# sleep for a period to allow NFS to propagate the above changes; |
| 49 |
# clearly, there is no guarantee that other NFS clients will see the |
| 50 |
# changes even after the timeout |
| 51 |
sleep 10 |
| 52 |
exit $err |
| 53 |
) 9> ${2}.lock |
| 54 |
} |
| 55 |
|
| 56 |
function report () |
| 57 |
{ |
| 58 |
if [[ "${1}" == "SUCCESS" ]] |
| 59 |
then |
| 60 |
info_msg "All the ${MACHINE_NAME} jobs passed" |
| 61 |
status_msg="The 'build-and-test' jobs on ${MACHINE_NAME} were SUCCESSFUL." |
| 62 |
elif [[ "${1}" == "FAILURE" ]] |
| 63 |
then |
| 64 |
info_msg "At least one failure on ${MACHINE_NAME}" |
| 65 |
status_msg="Some 'build-and-test' jobs on ${MACHINE_NAME} FAILED." |
| 66 |
else |
| 67 |
error_msg "Unknown status: ${1} ... aborting" |
| 68 |
exit 1 |
| 69 |
fi |
| 70 |
|
| 71 |
cd ${AUTOTEST_ROOT}/autotest || \ |
| 72 |
{ error_msg "Invalid 'autotest' dir: ${AUTOTEST_ROOT}/autotest"; exit 1; } |
| 73 |
mkdir -p ${MACHINE_NAME} |
| 74 |
|
| 75 |
rundir="${MACHINE_NAME}/$(date +%Y-%m-%d)-gitlab-ci-${CI_COMMIT_REF_SLUG}" |
| 76 |
rundir=$(${CI_PROJECT_DIR}/.gitlab/scripts/safe_create_rundir $rundir) |
| 77 |
|
| 78 |
printf "%s\n" "${status_msg}" \ |
| 79 |
"Pipeline URL:" "$CI_PIPELINE_URL" > ${rundir}/gitlab.err |
| 80 |
|
| 81 |
msg="GitLab CI log for build-and-test on ${MACHINE_NAME} ($(date +%Y-%m-%d))" |
| 82 |
|
| 83 |
if [[ "${1}" == "FAILURE" ]] |
| 84 |
then |
| 85 |
# Create 'autotest-email.html' to indicate failure: |
| 86 |
cp ${rundir}/gitlab.err ${rundir}/autotest-email.html |
| 87 |
fi |
| 88 |
|
| 89 |
# Note: in some cases, the content of AUTOTEST_COMMIT can be |
| 90 |
# '${AUTOTEST_COMMIT}', so we need to treat that value as the default |
| 91 |
# value of 'ON'. |
| 92 |
if [[ "$AUTOTEST_COMMIT" == '${AUTOTEST_COMMIT}' ]]; then |
| 93 |
AUTOTEST_COMMIT="ON" |
| 94 |
fi |
| 95 |
if [[ "$AUTOTEST_COMMIT" == "ON" || "$AUTOTEST_COMMIT" == "YES" ]]; then |
| 96 |
git pull && \ |
| 97 |
git add ${rundir} && \ |
| 98 |
git commit -m "${msg}" && \ |
| 99 |
${CI_PROJECT_DIR}/.gitlab/scripts/git_try_to_push |
| 100 |
else |
| 101 |
for file in ${rundir}/*; do |
| 102 |
echo "------------------------------" |
| 103 |
echo "Content of '$file'" |
| 104 |
echo "******************************" |
| 105 |
cat $file |
| 106 |
echo "******************************" |
| 107 |
done |
| 108 |
rm -rf ${rundir} || true |
| 109 |
fi |
| 110 |
} |
| 111 |
|
| 112 |
export MACHINE_NAME=${CI_MACHINE} |
| 113 |
info_msg "MACHINE_NAME is ${MACHINE_NAME}" |
| 114 |
info_msg "AUTOTEST_ROOT is ${AUTOTEST_ROOT}" |
| 115 |
info_msg "AUTOTEST=$AUTOTEST" |
| 116 |
info_msg "AUTOTEST_COMMIT=$AUTOTEST_COMMIT" |
| 117 |
|
| 118 |
cd ${AUTOTEST_ROOT} && locked_report ${1} autotest |