Annotation of buildman/bma, revision 1.5

1.1       snw         1: #!/bin/sh
                      2: 
                      3: # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
                      4: # SPDX-FileCopyrightText: (C) 2025 Serena Willis
                      5: #
                      6: # SPDX-License-Identifier: AGPL-3.0
                      7: 
                      8: #
                      9: # BuildMan 0.0.1
                     10: #  Distributed CI/CD system with portability to older UNIX systems
                     11: #
                     12: #  bma - buildman agent
                     13: #
                     14: # Copyright (C) 2025 Coherent Logic Development LLC
                     15: #
                     16: # Author: Serena Willis <snw@coherent-logic.com>
                     17: #
                     18: 
                     19: PROGN=`basename $0`
                     20: 
                     21: if [ -f "/etc/default/bm" ]
                     22: then
                     23:     . /etc/default/bm
                     24: else
                     25:     echo "${PROGN} error:  no /etc/default/bm"
                     26:     exit 1
                     27: fi
                     28: 
                     29: if [ -z ${BUILDMAN_BASE} ]
                     30: then
                     31:     echo "${PROGN} error:  BUILDMAN_BASE undefined"
                     32:     exit 1
                     33: fi
                     34: 
                     35: if [ -z ${BUILDMAN_UID} ]
                     36: then
                     37:     echo "${PROGN} error:  BUILDMAN_UID undefined"
                     38:     exit 1
                     39: fi
                     40: 
                     41: if [ -z ${BUILDMAN_GID} ]
                     42: then
                     43:     echo "${PROGN} error:  BUILDMAN_GID undefined"
                     44:     exit 1
                     45: fi
                     46: 
1.3       snw        47: #if [ $EUID -ne ${BUILDMAN_UID} ]
                     48: #then
                     49: #    echo "${PROGN} error:  must be run as user \"${BUILDMAN_USER}\""
                     50: #    exit 1
                     51: #fi
1.1       snw        52: 
                     53: OS=`uname`
                     54: DT=`date +"%Y%m%d"`
                     55: 
                     56: if [ "$OS" = "SCO_SV" ] ; then
                     57:     THOST=`hostname -s`
                     58:     PATH=/usr/gnu/bin:$PATH
                     59:     export PATH
                     60: else
                     61:     if [ "$OS" = "SunOS" ] ; then
                     62:         THOST=`hostname`
                     63:     else    
                     64:         THOST=`hostname -s`
                     65:     fi
                     66: fi
                     67: 
                     68: tmphost=`echo ${THOST} | cut -d. -f1`
                     69: THOST="${tmphost}"
                     70: 
                     71: cd "${BUILDMAN_BASE}/projects"
                     72: PROJECTS=`ls -1 -d *`
                     73: 
                     74: for PROJECT in $PROJECTS
                     75: do
                     76:     HOSTDIR="${BUILDMAN_BASE}/projects/${PROJECT}/hosts/${THOST}"
                     77:     BUILD_WANTED="${HOSTDIR}/build-wanted"
                     78:     
                     79:     if [ -d "${HOSTDIR}" ]
                     80:     then
                     81:         echo "$PROGN:  project ${PROJECT} references build host ${THOST}"
                     82: 
                     83:         if [ -f "${BUILD_WANTED}" ]
                     84:         then
                     85:             echo "$PROGN:  project ${PROJECT} has a build request pending"
                     86:             rm -f "${BUILD_WANTED}"
                     87: 
                     88:             DT=`date +"%Y%m%d%H%M%S"`
                     89:             JOBID="$$-${DT}"
                     90: 
                     91:             echo "$PROGN:  creating job ${JOBID}"
                     92:             JOBDIR="${HOSTDIR}/jobs/${JOBID}"
                     93:             JLOG="${JOBDIR}/job.log"
1.4       snw        94:             JSCR="${BUILDMAN_BASE}/projects/${PROJECT}/scripts/build.sh"
1.1       snw        95:             
                     96:             mkdir -p "${JOBDIR}"            
1.2       snw        97:             cd "${JOBDIR}"
1.5     ! snw        98: 
        !            99:             echo "Coherent Logic Development BuildMan" >> "${JLOG}"
        !           100:             echo "Build agent is running job ID ${JOBID} for project ${PROJECT} on node ${THOST}" >> "${JLOG}"
1.2       snw       101:             
1.1       snw       102:             echo "${JOBID}" > "${HOSTDIR}/build-running"
                    103:             echo "${JOBID}" > "${JOBDIR}/running"
                    104:             
                    105:             if [ -f "${JSCR}" ]
                    106:             then
                    107:                 echo "$PROGN:  running build script ${JSCR} for project ${PROJECT} [job id ${JOBID}]"
1.5     ! snw       108:                 sh "${JSCR}" >> ${JLOG}
1.1       snw       109:                 RETCODE=$?
                    110: 
                    111:                 rm -f "${HOSTDIR}/build-running"
                    112:                 rm -f "${JOBDIR}/running"
1.5     ! snw       113: 
        !           114:                 rm -f "${HOSTDIR}/build-failing"
        !           115:                 rm -f "${HOSTDIR}/build-passing"
        !           116:                 
1.1       snw       117:                 case $RETCODE in
                    118: 
                    119:                     0)
                    120:                         echo "${JOBID}" > "${HOSTDIR}/build-passing"
                    121:                         echo "${JOBID}" > "${JOBDIR}/passing"
                    122:                         ;;
                    123:                     *)
                    124:                         echo "${JOBID}" > "${HOSTDIR}/build-failing"
                    125:                         echo "${JOBID}" > "${JOBDIR}/failing"
                    126:                         ;;
                    127: 
                    128:                 esac
                    129:             else
                    130:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]"
                    131:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${HOSTDIR}/build-failing"
                    132:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${JOBDIR}/failing"
                    133:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" >> "${JLOG}"
                    134:                 rm -f "${HOSTDIR}/build-running"
                    135:                 rm -f "${JOBDIR}/running"
                    136: 
                    137:             fi
                    138:         fi
                    139:     fi
                    140:     
                    141: done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>