Devel-Cover

 view release on metacpan or  search on metacpan

utils/dc  view on Meta::CPAN

  docker_name "${args[@]:-}"
}

cpancover_controller_command() {
  local name="${1:?No name specified}"
  shift
  local cmd=("$@")
  mkdir -p "$results_dir"
  local sock=/var/run/docker.sock
  local tty_flag=""
  [[ -t 0 ]] && tty_flag="-t"
  local env_flags=()
  while IFS='=' read -r var value; do
    env_flags+=(--env "$var=$value")
  done < <(env | grep -E '^(CPANCOVER_|DEVEL_COVER_)' || true)
  "$docker" run -i ${tty_flag:+"$tty_flag"} \
    --mount "type=bind,source=$sock,target=$sock" \
    --mount "type=bind,source=$results_dir,target=/remote_staging" \
    ${env_flags[@]:+"${env_flags[@]}"} \
    --rm=false --memory=1g --name="$(docker_name "$name")" \
    "$docker_image" "${cmd[@]}"
}

recipe_cpancover-controller-shell() {
  cpancover_controller_command controller_bash "/bin/bash"
}

recipe_cpancover-docker-shell() {
  local staging="${1:-$results_dir}"
  mkdir -p "$staging"
  $docker run -it \
    --mount type=bind,source="$staging",target=/remote_staging \
    --rm=false --memory=1g --name="$(docker_name docker)" \
    "$docker_image" /bin/bash
}

# Called from Collection.pm
recipe_cpancover-docker-module() {
  local module="${1:?No module specified}"
  local name="${2:?No name specified}"
  local staging="${3:-$results_dir}"
  local module_timeout="${CPANCOVER_TIMEOUT:-1800}" # half an hour

  local log_name="$name"
  name=$(docker_name "$name")
  mkdir -p "$staging"
  ((verbose)) && pi "module: $module"
  local v=
  ((verbose)) && v=--verbose
  container=$($docker run -d \
    --rm=false --memory=1g --name="$name" \
    "$docker_image" \
    dc $v cpancover-build-module "$module")
  ((verbose)) && pi "container is $container"
  if timeout "$module_timeout" "$docker" wait "$name" >/dev/null 2>&1; then
    $docker logs "$name" | tee "$staging/$log_name.out"
    local_staging="$staging/$name"
    mkdir -p "$local_staging"
    $docker cp "$name:/root/cover/staging" "$local_staging"
    if [[ -d $local_staging ]]; then
      chmod -R 755 "$local_staging"
      find "$local_staging" -type f -exec chmod 644 {} \;
      chown -R "$(id -un):$(id -gn)" "$local_staging"
      cd "$local_staging"/* || exit
      for f in *; do
        if [[ -d $f && ! -d "$staging/$f" ]]; then
          echo "$log_name.out.gz" >"$f/.log_ref"
          mv "$f" "$staging"
        fi
      done
      rm -r "$local_staging"
    fi
  else
    pi "module timed out after ${module_timeout}s, killing container: $module"
    $docker logs "$name" | tee "$staging/$log_name.out" 2>/dev/null || true
    $docker kill "$name" >/dev/null 2>&1 || true
  fi
  $docker rm "$name" >/dev/null 2>&1 || true
}

cpancover_compress_dir() {
  local dir="$1" do_sidecars="${2:-}" prefix="${3:-}"
  shift 3 2>/dev/null || shift $#
  local exclude=("$@")

  rm -rf "$dir/runs" "$dir/structure"
  rm -f "$dir"/digests "$dir"/digests.gz "$dir"/cover.[0-9]* \
    "$dir"/cover.[0-9]*.gz "$dir"/*.lock "$dir"/*.lock.gz

  local find_args=("$dir" -maxdepth 1
    -type f -not -name '*.gz' -not -name '*.xz' -not -name '*.json'
    -not -name 'virtual_unzipped' -not -name '.log_ref')
  local name
  for name in "${exclude[@]}"; do
    find_args+=(-not -name "$name")
  done
  if find "${find_args[@]}" -print -quit | read -r; then
    pi "${prefix}compressing"
    find "${find_args[@]}" -print0 | xargs -0 pigz -f9
  fi

  [[ -n "$do_sidecars" ]] || return 0

  local marker="$dir/virtual_unzipped" created=false gzfile basefile
  for gzfile in "$dir"/*.gz; do
    [[ -f "$gzfile" ]] || continue
    [[ -f "$marker" ]] || touch "$marker"
    basefile="${gzfile%.gz}"
    if [[ ! -e "$basefile" ]]; then
      ln "$marker" "$basefile"
      created=true
    fi
  done
  if [[ "$created" == true ]]; then
    pi "${prefix}created sidecars"
  fi
}

cpancover_compress_dirs() {
  local only_new="$1"
  local max_jobs="${CPANCOVER_COMPRESS_JOBS:-$(nice_cpus)}"
  local jobs=0 dir name prefix



( run in 0.626 second using v1.01-cache-2.11-cpan-5b529ec07f3 )