commit 5217727aebc739382aba869bbbd5b4767040dc6a
parent 4665b1774ea915204810f8e76e1e8ab9f8c2073d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Fri, 11 Sep 2026 23:04:49 +0530
parent 4665b1774ea915204810f8e76e1e8ab9f8c2073d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Fri, 11 Sep 2026 23:04:49 +0530
Revert "Teach minci.sh to run Jobfiles" This reverts commit 4665b1774ea915204810f8e76e1e8ab9f8c2073d.
1 file changed, 379 insertions(+), 452 deletions(-)
diff --git a/minci.sh b/minci.sh @@ -7,31 +7,16 @@ # -r: run full check, but don't upload results # -v: more data while running # Use ~/.minci or /etc/minci for configuration, whichever comes first. -# -# Compatibility configuration: -# apikey = 12345 -# apisecret = abcdefghijklmnopqrstuvwxyz123456 -# server = https://example.org/cgi-bin/minci.cgi -# repo = https://example.org/my/repo.git -# bsdmake = bmake -# -# Extended configuration: -# branch = main -# staging = /var/tmp/minci -# jobfile = /etc/minci/Jobfile -# artifact-root = /srv/http/dl.nply.org -# artifact-url = https://nply.org/dl -# target = native -# -# Jobfile is POSIX sh and APKBUILD-like: lowercase variables, whitespace -# lists, function hooks, and !option negation. MAKE="make" API_SECRET= -DEP_BINS="openssl git curl" +DEP_BINS="mandoc openssl git curl" +# TODO: make sqlite3 be per-system. NOOP= NOREP= VERBOSE= +MINCI_REPO="https://github.com/kristapsdz/minci" +AUTOUP=1 API_KEY= SERVER= STAGING="$HOME/.local/cache/minci" @@ -40,16 +25,6 @@ CONFIG_LOCAL="$HOME/.minci" CONFIG_GLOBAL="/etc/minci" PROGNAME="$0" FORCE= -BRANCH="master" -JOBFILE= -ARTIFACT_ROOT= -ARTIFACT_URL= -TARGETS="native" -EVENT=${event:-${EVENT:-cron}} -REF=${ref:-${REF:-}} -OLDREV=${oldrev:-${OLDREV:-}} -NEWREV=${newrev:-${NEWREV:-}} -ACTOR=${actor:-${ACTOR:-}} msg() { @@ -62,513 +37,465 @@ fatal() exit 1 } -warning() -{ - echo "$PROGNAME: warning: $@" 1>&2 -} - debug() { - [ -z "$VERBOSE" ] || echo "$PROGNAME: $(date +"%F %T"): $@" -} - -trim() -{ - sed -e 's!^[ ]*!!' -e 's![ ]*$!!' -} - -config_value() -{ - _key=$1 - sed -n "s!^[ ]*$_key[ ]*=[ ]*!!p" "$CONFIG" | tail -1 -} - -config_values() -{ - _key=$1 - sed -n "s!^[ ]*$_key[ ]*=[ ]*!!p" "$CONFIG" -} - -has_word() -{ - _needle=$1 - shift - for _word in "$@" - do - [ "$_word" = "$_needle" ] && return 0 - done - return 1 -} - -has_opt() -{ - _opt=$1 - shift - _present=1 - for _o in "$@" - do - case "$_o" in - "$_opt") _present=0 ;; - "!$_opt") _present=1 ;; - esac - done - return "$_present" -} - -md5_file() -{ - openssl dgst -md5 -hex "$1" | sed 's!^[^=]*= !!' -} - -md5_text() -{ - openssl dgst -md5 -hex | sed 's!^[^=]*= !!' + [ -z "${VERBOSE}" ] || echo "$PROGNAME: $(date +"%F %T"): $@" } -sha256_file() +run() { - if command -v sha256sum >/dev/null 2>&1 + debug "$1: $2" + if [ -z "$NOOP" ] then - sha256sum "$1" | awk '{ print $1 }' - else - shasum -a 256 "$1" | awk '{ print $1 }' + echo "$PROGNAME: $1: $2" 1>&3 + set +e ; + eval "$1" 1>&3 2>&3 || { set -e ; return 1; } + set -e ; fi + return 0 } -run() +# Run $1, exiting on failure. +runnolog() { - debug "$1: $2" + debug "$1" if [ -z "$NOOP" ] then - set +e - { echo "$PROGNAME: $1: $2" 1>&3; eval "$1" 1>&3 2>&3; } 2>/dev/null - _rc=$? - if [ $_rc -ne 0 ] - then - eval "$1" >/dev/null 2>&1 - _rc=$? - fi - set -e - [ $_rc -eq 0 ] || return 1 + eval "$1" >/dev/null 2>&1 || exit 1 fi - return 0 } -usage() -{ +args=$(getopt fnrv $*) +if [ $? -ne 0 ] +then echo "usage: $PROGNAME [-fnrv] [repo ...]" 1>&2 exit 1 -} +fi -while getopts fnrv opt +set -- $args + +while [ $# -ne 0 ] do - case "$opt" in - f) FORCE=1 ;; - n) NOOP=1 ;; - r) NOREP=1 ;; - v) VERBOSE=1 ;; - *) usage ;; - esac + case "$1" + in + -n) + NOOP=1 ; shift ;; + -r) + NOREP=1 ; shift ;; + -f) + FORCE=1 ; shift ;; + -v) + VERBOSE=1 ; shift ;; + --) + shift ; break ;; + esac done -shift $((OPTIND - 1)) + +# Start with the local then global configuration. +# Require at least one of them. if [ ! -r "$CONFIG_LOCAL" ] then - [ -r "$CONFIG_GLOBAL" ] || fatal "no config found" + if [ ! -r "$CONFIG_GLOBAL" ] + then + fatal "$PROGNAME: no config found" + fi CONFIG="$CONFIG_GLOBAL" else CONFIG="$CONFIG_LOCAL" fi - debug "using config: $CONFIG" -_v=$(config_value bsdmake); [ -z "$_v" ] || MAKE=$_v -_v=$(config_value apisecret); [ -z "$_v" ] || API_SECRET=$_v -_v=$(config_value apikey); [ -z "$_v" ] || API_KEY=$_v -_v=$(config_value server); [ -z "$_v" ] || SERVER=$_v -_v=$(config_value staging); [ -z "$_v" ] || STAGING=$_v -_v=$(config_value branch); [ -z "$_v" ] || BRANCH=$_v -_v=$(config_value jobfile); [ -z "$_v" ] || JOBFILE=$_v -_v=$(config_value artifact-root); [ -z "$_v" ] || ARTIFACT_ROOT=$_v -_v=$(config_value artifact-url); [ -z "$_v" ] || ARTIFACT_URL=$_v -_v=$(config_value target); [ -z "$_v" ] || TARGETS=$_v - -[ -n "$API_SECRET" ] || fatal "no API secret specified" -[ -n "$API_KEY" ] || fatal "no API key specified" -[ -n "$SERVER" ] || fatal "no server specified" +# Read the API secret from the configuration. + +while read -r ln +do + bsdmake="$(echo "$ln" | sed -n 's!^[ ]*bsdmake[ ]*=[ ]*!!p')" + [ -z "$bsdmake" ] && continue + MAKE="$bsdmake" +done < "$CONFIG" DEP_BINS="$DEP_BINS $MAKE" + +# Read the API secret from the configuration. + +while read -r ln +do + api_secret="$(echo "$ln" | sed -n 's!^[ ]*apisecret[ ]*=[ ]*!!p')" + [ -z "$api_secret" ] && continue + API_SECRET="$api_secret" +done < "$CONFIG" +if [ -z "$API_SECRET" ] +then + fatal "no API secret specified" +fi + +# Read the API key from the configuration. + +while read -r ln +do + api_key="$(echo "$ln" | sed -n 's!^[ ]*apikey[ ]*=[ ]*!!p')" + [ -z "$api_key" ] && continue + API_KEY="$api_key" +done < "$CONFIG" +if [ -z "$API_KEY" ] +then + fatal "no API key specified" +fi + +# Read the server from the configuration. + +while read -r ln +do + server="$(echo "$ln" | sed -n 's!^[ ]*server[ ]*=[ ]*!!p')" + [ -z "$server" ] && continue + SERVER="$server" +done < "$CONFIG" +if [ -z "$SERVER" ] +then + fatal "no server specified" +fi + +debug "using API key: $API_KEY" +debug "using API secret: $API_SECRET" +debug "using server: $SERVER" + for dep in $DEP_BINS do debug "check binary dependency: $dep" - command -v "$dep" >/dev/null 2>&1 || fatal "binary dep not in PATH: $dep" + which "$dep" 2>/dev/null 1>&2 + if [ $? -ne 0 ] + then + fatal "binary dep not in PATH: $dep" + fi done +# Check or create where we'll put our repositories. + if [ ! -d "$STAGING" ] && [ -z "$NOOP" ] then - mkdir -p "$STAGING" || fatal "could not create: $STAGING" + mkdir -p "$STAGING" + if [ $? -ne 0 ] + then + fatal "could not create: $STAGING" + fi + debug "created: $STAGING" fi -native_target() -{ - _uname_s=$(uname -s) - _uname_m=$(uname -m) - case "$_uname_m" in amd64) _arch=x86_64 ;; arm64) _arch=aarch64 ;; *) _arch=$_uname_m ;; esac - case "$_uname_s" in - Darwin) echo "$_arch-apple-darwin" ;; - Linux) echo "$_arch-unknown-linux-gnu" ;; - Windows_NT|MINGW*|MSYS*|CYGWIN*) echo "$_arch-pc-windows-gnu" ;; - *) echo "$_arch-unknown-$(echo "$_uname_s" | tr 'A-Z' 'a-z')" ;; - esac -} +# Auto-update feature. +# FIXME: NOT FOR PERMANENT USE. +# This will eventually be replaced by a real package manager, but for +# now I'm using this because it lets me update hosts without needing to +# do it manually for each one. -expand_targets() -{ - for t in $TARGETS - do - case "$t" in native) native_target ;; *) echo "$t" ;; esac - done -} - -repo_name() -{ - echo "$1" | sed -e 's!.*/!!' -e 's!\.git$!!' -} +if [ -n "$AUTOUP" ] +then + # Same way as we'll use for repositories later on. -want_repo() -{ - _name=$1 - [ $# -eq 1 ] && return 0 - shift - for arg in "$@" - do - [ "$arg" = "$_name" ] && return 0 - done - return 1 -} + debug "checking auto-up status" + set -e + FETCH_HEAD="" + head="" -checkout_repo() -{ - repo=$1 - reponame=$2 - FETCH_HEAD= - head= [ -n "$NOOP" ] || cd "$STAGING" - if [ -d "$reponame" ] + if [ -d "minci" ] then - [ -n "$NOOP" ] || cd "$reponame" - head=$(git rev-parse HEAD 2>/dev/null) - run "git fetch origin" "$reponame" || return 1 + if [ -z "$NOOP" ] + then + cd "minci" + head="$(cut -f1 .git/FETCH_HEAD 2>/dev/null | head -1)" + fi + runnolog "git fetch origin" + runnolog "git reset --hard origin/master" + runnolog "git clean -fdx" + if [ -z "$NOOP" ] + then + FETCH_HEAD="$(cut -f1 .git/FETCH_HEAD | head -1)" + fi else - run "git clone $repo $reponame" "$reponame" || return 1 - [ -n "$NOOP" ] || cd "$reponame" - run "git fetch origin" "$reponame" || return 1 + runnolog "git clone $MINCI_REPO" + if [ -z "$NOOP" ] + then + cd "minci" + fi + # Grabs the newest .git/FETCH_HEAD. + runnolog "git fetch origin" + runnolog "git reset --hard origin/master" + if [ -z "$NOOP" ] + then + FETCH_HEAD="$(cut -f1 .git/FETCH_HEAD | head -1)" + fi fi - if [ -n "$NEWREV" ] + # If up to date, fine. + # If not, install the new script then exit. + # We'll reinvoke later (we're probably being run from cron) with + # the new version. + + if [ -n "$head" ] && [ "$head" = "$FETCH_HEAD" ] then - run "git reset --hard $NEWREV" "$reponame" || return 1 + debug "installation is fresh: minci" else - run "git reset --hard origin/$BRANCH" "$reponame" || return 1 + debug "installation is not fresh: minci" + debug "previous: $head" + debug "current: $FETCH_HEAD" + debug "installing new script and exiting" + if [ -z "$NOOP" ] + then + runnolog "install -m 0755 minci.sh $HOME/bin" + fi + msg "updated binary: now at commit $FETCH_HEAD" + exit 0 fi - run "git clean -fdx" "$reponame" || return 1 - FETCH_HEAD=$(git rev-parse HEAD 2>/dev/null) - [ -n "$REF" ] || REF="refs/heads/$BRANCH" - [ -n "$NEWREV" ] || NEWREV=$FETCH_HEAD - return 0 -} -submit_report() -{ - project_name=$1 - fetchhead=$2 - logfile=$3 - start=$4 - envtime=$5 - depend=$6 - build=$7 - test=$8 - install=$9 - shift 9 - distcheck=$1 - uname_n=$2 - - UNAME_M=$(uname -m | trim) - UNAME_N=$(printf '%s' "$uname_n" | trim) - UNAME_R=$(uname -r | trim) - UNAME_S=$(uname -s | trim) - UNAME_V=$(uname -v | trim) - - hash=$(md5_file "$logfile") - QUERY="project-name=${project_name}" - QUERY="${QUERY}&report-build=${build}" - QUERY="${QUERY}&report-distcheck=${distcheck}" - QUERY="${QUERY}&report-env=${envtime}" - QUERY="${QUERY}&report-fetchhead=${fetchhead}" - QUERY="${QUERY}&report-depend=${depend}" - QUERY="${QUERY}&report-install=${install}" - QUERY="${QUERY}&report-log=$hash" - QUERY="${QUERY}&report-start=${start}" - QUERY="${QUERY}&report-test=${test}" - QUERY="${QUERY}&report-unamem=${UNAME_M}" - QUERY="${QUERY}&report-unamen=${UNAME_N}" - QUERY="${QUERY}&report-unamer=${UNAME_R}" - QUERY="${QUERY}&report-unames=${UNAME_S}" - QUERY="${QUERY}&report-unamev=${UNAME_V}" - QUERY="${QUERY}&user-apisecret=${API_SECRET}" - SIGNATURE=$(printf '%s' "$QUERY" | md5_text) + set +e +fi + +# Process each repository line. - if [ -z "$NOOP" ] && [ -z "$NOREP" ] +NPROC=0 +while read -r ln +do + repo="$(echo "$ln" | sed -n 's!^[ ]*repo[ ]*=[ ]*!!p')" + [ -z "$repo" ] && continue + reponame="$(echo "$repo" | sed -e 's!.*/!!' -e 's!\.git$!!')" + if [ -z "$reponame" ] then - curl -sS \ - -F "report-log=@$logfile" \ - -F "project-name=${project_name}" \ - -F "report-start=${start}" \ - -F "report-env=${envtime}" \ - -F "report-depend=${depend}" \ - -F "report-build=${build}" \ - -F "report-test=${test}" \ - -F "report-install=${install}" \ - -F "report-distcheck=${distcheck}" \ - -F "report-unamem=${UNAME_M}" \ - -F "report-unamen=${UNAME_N}" \ - -F "report-unamer=${UNAME_R}" \ - -F "report-unames=${UNAME_S}" \ - -F "report-unamev=${UNAME_V}" \ - -F "report-fetchhead=${fetchhead}" \ - -F "user-apikey=${API_KEY}" \ - -F "signature=${SIGNATURE}" \ - "${SERVER}" >/dev/null + fatal "malformed repo: $repo" fi -} - -selected_jobs() -{ - [ -n "${triggers:-}" ] || return 0 - printf '%s\n' "$triggers" | while IFS= read -r line - do - case "$line" in ''|'#'*) continue ;; esac - pattern=${line%%:*} - jobs=${line#*:} - pattern=$(printf '%s' "$pattern" | trim) - case "$ref" in - $pattern) - printf '%s\n' $jobs - [ "${trigger_mode:-first}" = all ] || break - ;; - esac - done -} -job_options() -{ - job=$1 - eval "extra=\${options_$job:-}" - printf '%s\n' ${default_options:-report artifacts failfast} $extra -} + # Iterate through the command-line arguments, only if specified, + # to see if we want to run this. -job_key() -{ - job=$1 - { - printf 'repo=%s\nref=%s\nnewrev=%s\ntarget=%s\njob=%s\n' "$repo" "$ref" "$newrev" "$target" "$job" - [ -f "$jobfile" ] && printf 'jobfile=%s\n' "$(sha256_file "$jobfile")" - if command -v "${job}_inputs" >/dev/null 2>&1 - then - (cd "$srcdir" && "${job}_inputs") | while IFS= read -r f - do - [ -f "$srcdir/$f" ] && printf 'input %s %s\n' "$f" "$(sha256_file "$srcdir/$f")" - done - fi - for v in MAKEFLAGS CFLAGS CPPFLAGS LDFLAGS PKG_CONFIG_PATH CC + if [ $# -gt 0 ] + then + for prog in "$@" do - eval val=\${$v:-} - printf '%s=%s\n' "$v" "$val" + if [ "$prog" = "$reponame" ] + then + prog="" + break + fi done - } | if command -v sha256sum >/dev/null 2>&1 - then - sha256sum | awk '{ print $1 }' - else - shasum -a 256 | awk '{ print $1 }' + if [ -n "$prog" ] + then + debug "ignoring: $reponame" + continue + fi fi -} -publish_job() -{ - job=$1 - key=$2 - [ -n "$ARTIFACT_ROOT" ] || return 0 - out=$ARTIFACT_ROOT/${artifact_path:-$reponame}/$target/$newrev/$job/$key - tmp=$out.tmp.$$ - rm -rf "$tmp" - mkdir -p "$tmp" - if command -v "${job}_artifacts" >/dev/null 2>&1 - then - "${job}_artifacts" >"$workdir/artifacts.list" - else - find "$destdir" -type f >"$workdir/artifacts.list" - fi - while IFS= read -r f - do - [ -f "$f" ] || continue - cp "$f" "$tmp/" - done <"$workdir/artifacts.list" - cp "$logfile" "$tmp/build.log" - { - printf 'project=%s\n' "${project:-$reponame}" - printf 'job=%s\nrepo=%s\nref=%s\nnewrev=%s\ntarget=%s\nkey=%s\n' "$job" "$repo" "$ref" "$newrev" "$target" "$key" - [ -n "$ARTIFACT_URL" ] && printf 'artifact_url=%s/%s/%s/%s/%s/%s/\n' "$ARTIFACT_URL" "${artifact_path:-$reponame}" "$target" "$newrev" "$job" "$key" - } >"$tmp/manifest" - mkdir -p "$(dirname "$out")" - rm -rf "$out" - mv "$tmp" "$out" -} + # Get ready for actual processing. + # Now errors without || are fatal. -run_jobfile_job() -{ - job=$1 - target=$2 - key=$(job_key "$job") - workdir=$STAGING/work/$key - pkgdir=$workdir/pkg - destdir=$workdir/artifacts - logfile=$workdir/build.log - artifact_url= - [ -n "$ARTIFACT_URL" ] && artifact_url=$ARTIFACT_URL/${artifact_path:-$reponame}/$target/$newrev/$job/$key/ - export srcdir confdir workdir pkgdir destdir artifact_url target ref oldrev newrev repo repo_url repo_path actor - rm -rf "$workdir" - mkdir -p "$pkgdir" "$destdir" - exec 3>"$logfile" - start=$(date +%s) - envtime=$start - depend=$start - opts=$(job_options "$job") - set +e - "$job" 1>&3 2>&3 - rc=$? set -e - exec 3>&- - if [ $rc -eq 0 ] - then - build=$(date +%s); test=$build; install=$build; distcheck=$build - has_opt artifacts $opts && publish_job "$job" "$key" - has_opt report $opts && submit_report "${project:-$reponame}:$job" "$newrev" "$logfile" "$start" "$envtime" "$depend" "$build" "$test" "$install" "$distcheck" "$target" - return 0 - fi - build=0; test=0; install=0; distcheck=0 - has_opt report $opts && submit_report "${project:-$reponame}:$job" "$newrev" "$logfile" "$start" "$envtime" "$depend" "$build" "$test" "$install" "$distcheck" "$target" - warning "job failed: ${project:-$reponame}:$job" - has_opt allow_failure $opts && return 0 - return 1 -} -run_jobfile() -{ - repo=$1 - reponame=$2 - repo_path=$STAGING/$reponame - repo_url=$repo - actor=$ACTOR - srcdir=$repo_path - ref=$REF - oldrev=$OLDREV - newrev=$FETCH_HEAD - jobfile=$JOBFILE - [ -n "$jobfile" ] || [ ! -f "$srcdir/.config/Jobfile" ] || jobfile=$srcdir/.config/Jobfile - [ -n "$jobfile" ] || [ ! -f "$srcdir/.config/minci/Jobfile" ] || jobfile=$srcdir/.config/minci/Jobfile - [ -n "$jobfile" ] || return 2 - [ -r "$jobfile" ] || fatal "cannot read Jobfile: $jobfile" - confdir=$(cd "$(dirname "$jobfile")" && pwd) - - # shellcheck disable=SC1090 - . "$jobfile" - jobs=$(selected_jobs) - [ -n "$jobs" ] || { debug "no jobs selected for $ref"; return 0; } - command -v prepare >/dev/null 2>&1 && prepare - for target in $(expand_targets) + debug "$repo: $reponame" + + [ -n "$NOOP" ] || exec 3>/tmp/minci.log + [ -n "$NOOP" ] || cd "$STAGING" + + # Set all of our times to zero. + # If a time is non-zero when we send our report, that means that + # we've finished a phase. + + TIME_start=0 + TIME_env=0 + TIME_depend=0 + TIME_build=0 + TIME_test=0 + TIME_install=0 + TIME_distcheck=0 + + # Set our last-commit checksum to be empty as well. + + FETCH_HEAD="" + + # Begin processing. + # This is wrapped in an infinite loop so we can just use `break` + # to come out of error situations and still send the report. + + TIME_start=$(date +%s) + + while : do - done_jobs= - for job in $jobs - do - eval "deps=\${depends_$job:-}" - missing= - for dep in $deps - do - has_word "$dep" $done_jobs || missing="$missing $dep" - done - if [ -n "$missing" ] + head="" + FETCH_HEAD="" + + # If we have a repository already, update and clean it + # out; otherwise, clone it afresh. + # Keep track of the FETCH_HEAD last commit. + + if [ -d "$reponame" ] + then + if [ -z "$NOOP" ] then - warning "skipped $job: missing dependencies:$missing" - continue + cd "$reponame" + head="$(cut -f1 .git/FETCH_HEAD 2>/dev/null | head -1)" fi - if run_jobfile_job "$job" "$target" + run "git fetch origin" "$reponame" || break + run "git reset --hard origin/master" "$reponame" || break + run "git clean -fdx" "$reponame" || break + if [ -z "$NOOP" ] then - done_jobs="$done_jobs $job" - else - opts=$(job_options "$job") - has_opt failfast $opts && return 1 + FETCH_HEAD="$(cut -f1 .git/FETCH_HEAD | head -1)" fi - done - done - command -v cleanup >/dev/null 2>&1 && cleanup - return 0 -} + else + run "git clone $repo" "$reponame" || break + if [ -z "$NOOP" ] + then + cd "$reponame" + fi + # Grabs the newest .git/FETCH_HEAD. + run "git fetch origin" "$reponame" || break + run "git reset --hard origin/master" "$reponame" || break + if [ -z "$NOOP" ] + then + FETCH_HEAD="$(cut -f1 .git/FETCH_HEAD | head -1)" + fi + fi + + # If the FETCH_HEAD commit doesn't change when we freshen the + # repository, then doing re-test it unless -f was passed. + + if [ -z "$FORCE" ] && [ -n "$head" ] && [ "$head" = "$FETCH_HEAD" ] + then + debug "repository is fresh: $reponame" + TIME_start=0 + break + fi + + TIME_env=$(date +%s) + + # Run ./configure, make, make regress, make install, + # make distcheck. If any fail, then break out. -run_legacy() -{ - reponame=$1 - logfile=$STAGING/minci.$reponame.log - exec 3>"$logfile" - start=$(date +%s) - envtime=$(date +%s) - depend=0; build=0; test=0; install=0; distcheck=0 - while : - do run "./configure PREFIX=build" "$reponame" || break - depend=$(date +%s) + TIME_depend=$(date +%s) + run "${MAKE}" "$reponame" || break - build=$(date +%s) + TIME_build=$(date +%s) + run "${MAKE} regress" "$reponame" || break - test=$(date +%s) + TIME_test=$(date +%s) + run "${MAKE} install" "$reponame" || break - install=$(date +%s) + TIME_install=$(date +%s) + run "${MAKE} distcheck" "$reponame" || break - distcheck=$(date +%s) + TIME_distcheck=$(date +%s) + + # Success! break done - exec 3>&- - submit_report "$reponame" "$FETCH_HEAD" "$logfile" "$start" "$envtime" "$depend" "$build" "$test" "$install" "$distcheck" "$(uname -n)" - [ $distcheck -ne 0 ] -} -NPROC=0 -_repos=${TMPDIR:-/tmp}/minci.repos.$$ -config_values repo >"$_repos" -while IFS= read -r repo -do - [ -n "$repo" ] || continue - reponame=$(repo_name "$repo") - [ -n "$reponame" ] || fatal "malformed repo: $repo" - want_repo "$reponame" "$@" || { debug "ignoring: $reponame"; continue; } - set -e - checkout_repo "$repo" "$reponame" || { warning "checkout failed: $reponame"; continue; } - if [ -z "$FORCE" ] && [ -n "$head" ] && [ "$head" = "$FETCH_HEAD" ] + # Stop reporting to fd-3 and remask errors. + # Our house-keeping can now fail without killing us. + + [ -n "$NOOP" ] || exec 3>&- + set +e + + if [ $TIME_start -eq 0 ] then - debug "repository is fresh: $reponame" + [ -n "$NOOP" ] || rm -f /tmp/minci.log continue fi - NPROC=$((NPROC + 1)) - if run_jobfile "$repo" "$reponame" + + NPROC=$(( $NPROC + 1 )) + + if [ $TIME_distcheck -eq 0 ] then + msg "failure: $reponame" + else msg "success: $reponame" + fi + + debug "computing signature" + + UNAME_M=$(uname -m | sed -e 's!^[ ]*!!g' -e 's![ ]*$!!g') + UNAME_N=$(uname -n | sed -e 's!^[ ]*!!g' -e 's![ ]*$!!g') + UNAME_R=$(uname -r | sed -e 's!^[ ]*!!g' -e 's![ ]*$!!g') + UNAME_S=$(uname -s | sed -e 's!^[ ]*!!g' -e 's![ ]*$!!g') + UNAME_V=$(uname -v | sed -e 's!^[ ]*!!g' -e 's![ ]*$!!g') + + # Create the signature for this entry. + # It consists of all the MD5 hash of all arguments in + # alphabetical order (by key), with the report-log (or /dev/null + # if there's no need to report) being replaced by its MD5 hash. + + QUERY="project-name=${reponame}" + QUERY="${QUERY}&report-build=${TIME_build}" + QUERY="${QUERY}&report-distcheck=${TIME_distcheck}" + QUERY="${QUERY}&report-env=${TIME_env}" + QUERY="${QUERY}&report-fetchhead=${FETCH_HEAD}" + QUERY="${QUERY}&report-depend=${TIME_depend}" + QUERY="${QUERY}&report-install=${TIME_install}" + if [ $TIME_distcheck -eq 0 ] + then + hashfile="/tmp/minci.log" else - case $? in - 2) run_legacy "$reponame" && msg "success: $reponame" || msg "failure: $reponame" ;; - *) msg "failure: $reponame" ;; - esac + hashfile="/dev/null" fi -done <"$_repos" -rm -f "$_repos" + hash="$(openssl dgst -md5 -hex $hashfile | sed 's!^[^=]*= !!')" + QUERY="${QUERY}&report-log=$hash" + QUERY="${QUERY}&report-start=${TIME_start}" + QUERY="${QUERY}&report-test=${TIME_test}" + QUERY="${QUERY}&report-unamem=${UNAME_M}" + QUERY="${QUERY}&report-unamen=${UNAME_N}" + QUERY="${QUERY}&report-unamer=${UNAME_R}" + QUERY="${QUERY}&report-unames=${UNAME_S}" + QUERY="${QUERY}&report-unamev=${UNAME_V}" + QUERY="${QUERY}&user-apisecret=${API_SECRET}" + + # Signature is the MD5 of ordered parameters and including our + # API secret. + # The server will perform the same steps. + + SIGNATURE=$(printf "%s" "$QUERY" | openssl dgst -md5 -hex | sed 's!^[^=]*= !!') + + # Now actually send the report. + # It includes the signature and optionally the build log (only + # if we didn't get to the end). + + debug "sending report: $SERVER" + + REPORT_LOG= + if [ $TIME_distcheck -eq 0 ] + then + REPORT_LOG="-F report-log=</tmp/minci.log" + else + REPORT_LOG="-F report-log=" + fi + + if [ -z "$NOOP" -a -z "$NOREP" ] + then + curl -sS ${REPORT_LOG} \ + -F "project-name=${reponame}" \ + -F "report-start=${TIME_start}" \ + -F "report-env=${TIME_env}" \ + -F "report-depend=${TIME_depend}" \ + -F "report-build=${TIME_build}" \ + -F "report-test=${TIME_test}" \ + -F "report-install=${TIME_install}" \ + -F "report-distcheck=${TIME_distcheck}" \ + -F "report-unamem=${UNAME_M}" \ + -F "report-unamen=${UNAME_N}" \ + -F "report-unamer=${UNAME_R}" \ + -F "report-unames=${UNAME_S}" \ + -F "report-unamev=${UNAME_V}" \ + -F "report-fetchhead=${FETCH_HEAD}" \ + -F "user-apikey=${API_KEY}" \ + -F "signature=${SIGNATURE}" \ + "${SERVER}" + fi + if [ -z "$NOOP" ] + then + rm -f /tmp/minci.log + fi +done < "$CONFIG" + +if [ $NPROC -eq 0 ] +then + msg "all repositories up to date" +fi -[ $NPROC -ne 0 ] || msg "all repositories up to date" exit 0
: nply/minci