[Dev] Display live messages in pipeline
This commit is contained in:
parent
f9a5808607
commit
14ed4ab071
|
@ -259,21 +259,25 @@ main() (
|
|||
echo "${runner_request}" | ncat --unixsock "${runner_sock}"
|
||||
) &
|
||||
|
||||
# Wait for runner response.
|
||||
# Start CI runner.
|
||||
echo -e "Starting CI runner..."
|
||||
cd "${rd_pipeline_sock_dir}"
|
||||
ncat_cmd="ncat --listen --unixsock --keep-open pipeline.sock"
|
||||
if [ "${runner_timeout}" -gt 0 ]; then
|
||||
response="$(timeout "${runner_timeout}" ncat --listen \
|
||||
--unixsock pipeline.sock)"
|
||||
else
|
||||
response="$(ncat --listen --unixsock pipeline.sock)"
|
||||
ncat_cmd="timeout ${runner_timeout} ${ncat_cmd}"
|
||||
fi
|
||||
while read -r response; do
|
||||
echo -e "$(echo "${response}" | jq --raw-output .msg)"
|
||||
code="$(echo "${response}" | jq .code)"
|
||||
[ "${code}" = "null" ] || break
|
||||
done < <($ncat_cmd)
|
||||
pkill --full --exact --parent "$$" "${ncat_cmd}" || true
|
||||
|
||||
# Remove random directory.
|
||||
rm --recursive "${rd_pipeline_sock_dir}"
|
||||
|
||||
# Display response.
|
||||
echo -e "Response from RUNNER:\n$(echo "${response}" | jq --raw-output .msg)"
|
||||
exit "$(echo "${response}" | jq .code)"
|
||||
exit "${code}"
|
||||
)
|
||||
|
||||
main "$@"
|
||||
|
|
116
src/runner.sh
116
src/runner.sh
|
@ -95,21 +95,29 @@ Positional argument ACTION
|
|||
)
|
||||
|
||||
reply() (
|
||||
code="$1"
|
||||
msg="$2"
|
||||
msg="$1"
|
||||
code="$2"
|
||||
|
||||
if [ "${code}" -gt 0 ]; then
|
||||
log_error "${msg}"
|
||||
else
|
||||
if [ -z "${code}" ]; then
|
||||
log_info "${msg}"
|
||||
json="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg m "${msg}" \
|
||||
'{"msg":$m}')"
|
||||
else
|
||||
if [ "${code}" -eq 0 ]; then
|
||||
log_info "${msg}"
|
||||
else
|
||||
log_error "${msg}"
|
||||
fi
|
||||
json="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg m "${msg}" \
|
||||
--arg c "${code}" \
|
||||
'{"msg":$m,"code":$c|tonumber}')"
|
||||
fi
|
||||
|
||||
if ! output="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg c "${code}" \
|
||||
--arg m "${msg}" \
|
||||
'{"code":$c|tonumber,"msg":$m}' |
|
||||
ncat --unixsock "${response_sock}" 2>&1)"; then
|
||||
if ! output="$(echo "${json}" | ncat --unixsock "${response_sock}" 2>&1)"; then
|
||||
log_error "Cannot write to sock '${response_sock}': ${output}."
|
||||
fi
|
||||
)
|
||||
|
@ -149,17 +157,18 @@ process_request() (
|
|||
log_debug "Get repo_name from json."
|
||||
if ! repo_name="$(echo "${request}" |
|
||||
jq --raw-output ".repo_name" 2>&1)"; then
|
||||
reply "${err_json_bad_format}" \
|
||||
"Cannot parse json '${request}': ${repo_name}."
|
||||
reply "Cannot parse json '${request}': ${repo_name}." \
|
||||
"${err_json_bad_format}"
|
||||
return
|
||||
fi
|
||||
if [ "${repo_name}" = "null" ]; then
|
||||
reply "${err_repo_name_missing}" "Missing key repo_name in '${request}'."
|
||||
reply "Missing key repo_name in '${request}'." \
|
||||
"${err_repo_name_missing}"
|
||||
return
|
||||
fi
|
||||
if [ -z "${repo_name}" ]; then
|
||||
reply "${err_repo_name_empty}" \
|
||||
"Empty value for key repo_name in '${request}'."
|
||||
reply "Empty value for key repo_name in '${request}'." \
|
||||
"${err_repo_name_empty}"
|
||||
return
|
||||
fi
|
||||
log_debug "Got pkg name: '${repo_name}'."
|
||||
|
@ -167,7 +176,8 @@ process_request() (
|
|||
# Get repository folder.
|
||||
repo_dir="${repos_dir}/${repo_name}.git"
|
||||
if [ ! -d "${repo_dir}" ]; then
|
||||
reply "${err_repo_dir_not_exist}" "Repository '${repo_dir}' does not exist."
|
||||
reply "Repository '${repo_dir}' does not exist." \
|
||||
"${err_repo_dir_not_exist}"
|
||||
return
|
||||
fi
|
||||
log_debug "Repository is present at '${repo_dir}'."
|
||||
|
@ -175,30 +185,31 @@ process_request() (
|
|||
# Get repo_hash from json.
|
||||
log_debug "Get repo_hash from json."
|
||||
if ! repo_hash=$(echo "${request}" | jq --raw-output ".repo_hash" 2>&1); then
|
||||
reply "${err_json_bad_format}" \
|
||||
"Cannot parse json '${request}': ${repo_hash}."
|
||||
reply "Cannot parse json '${request}': ${repo_hash}." \
|
||||
"${err_json_bad_format}"
|
||||
return
|
||||
fi
|
||||
if [ "${repo_hash}" = "null" ]; then
|
||||
reply "${err_repo_hash_missing}" "Missing key repo_hash in '${request}'."
|
||||
reply "Missing key repo_hash in '${request}'." \
|
||||
"${err_repo_hash_missing}"
|
||||
return
|
||||
fi
|
||||
if [ -z "${repo_hash}" ]; then
|
||||
reply "${err_repo_hash_empty}" \
|
||||
"Empty value for key repo_hash in '${request}'." 1>&2
|
||||
reply "Empty value for key repo_hash in '${request}'." \
|
||||
"${err_repo_hash_empty}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Get repo_tag from json.
|
||||
log_debug "Get repo_tag from json."
|
||||
if ! repo_tag=$(echo "${request}" | jq --raw-output ".repo_tag"); then
|
||||
reply "${err_json_bad_format}" \
|
||||
"Cannot parse json '${request}': ${repo_tag}."
|
||||
reply "Cannot parse json '${request}': ${repo_tag}." \
|
||||
"${err_json_bad_format}"
|
||||
return
|
||||
fi
|
||||
if [ -z "${repo_tag}" ]; then
|
||||
reply "${err_repo_tag_empty}" \
|
||||
"Empty value for key repo_tag in '${request}'."
|
||||
reply "Empty value for key repo_tag in '${request}'." \
|
||||
"${err_repo_tag_empty}"
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -207,66 +218,81 @@ process_request() (
|
|||
[ "${repo_tag}" != "null" ] && repo_id="${repo_tag}"
|
||||
rand="$(echo "${RANDOM}" | md5sum | head --bytes 7)"
|
||||
repo_clone="${runner_cloning_dir}/${repo_name}-${repo_id}-${rand}"
|
||||
log_info "Clone '$repo_name'."
|
||||
if ! output="$(git clone "$repo_dir" "$repo_clone" 2>&1)"; then
|
||||
reply "${err_clone_repo}" "Cannot clone repo '${repo_name}': ${output}."
|
||||
log_info "Clone '${repo_name}'."
|
||||
reply "Cloning repo '${repo_name}'..."
|
||||
if ! output="$(git clone "${repo_dir}" "${repo_clone}" 2>&1)"; then
|
||||
reply "Cannot clone repo '${repo_name}': ${output}." \
|
||||
"${err_clone_repo}"
|
||||
return
|
||||
fi
|
||||
cd "$repo_clone"
|
||||
|
||||
# Checkout git hash.
|
||||
log_info "Checkout hash $repo_hash."
|
||||
log_info "Checkout hash ${repo_hash}."
|
||||
reply "Checkouting hash '${repo_hash}..."
|
||||
if ! output="$(git checkout "$repo_hash" 2>&1)"; then
|
||||
reply "${err_checkout_hash}" \
|
||||
"Cannot checkout hash '${repo_hash}': ${output}."
|
||||
reply "Cannot checkout hash '${repo_hash}': ${output}." \
|
||||
"${err_checkout_hash}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Check code validity.
|
||||
log_info "Check code validity."
|
||||
log_info "Check code format."
|
||||
reply "Checking code format..."
|
||||
if ! output="$(make check_format 2>&1)"; then
|
||||
reply "${err_check_format}" "Check format error: ${output}."
|
||||
reply "Check format error: ${output}." "${err_check_format}"
|
||||
return
|
||||
fi
|
||||
log_info "Check code linting."
|
||||
reply "Checking code linting..."
|
||||
if ! output="$(make check_linting 2>&1)"; then
|
||||
reply "${err_check_linting}" "Check linting error: ${output}."
|
||||
reply "Check linting error: ${output}." "${err_check_linting}"
|
||||
return
|
||||
fi
|
||||
log_info "Run unit tests."
|
||||
reply "Running unit tests..."
|
||||
if ! output="$(make unit_test 2>&1)"; then
|
||||
reply "${err_unit_test}" "Unit test error: ${output}."
|
||||
reply "Unit test error: ${output}." "${err_unit_test}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Stop now if no tag specified.
|
||||
if [ "$repo_tag" = "null" ]; then
|
||||
reply 0 "Hash '${repo_hash}' OK for repo '${repo_name}'."
|
||||
reply "Hash '${repo_hash}' OK for repo '${repo_name}'." 0
|
||||
return
|
||||
fi
|
||||
|
||||
# Build rpm package.
|
||||
echo "Build RPM package."
|
||||
log_info "Add git tag '${repo_tag}'."
|
||||
reply "Adding tag '${repo_tag}'..."
|
||||
if ! output="$(git tag --message="$repo_tag" "$repo_tag" 2>&1)"; then
|
||||
reply "${err_add_tag}" "Cannot add git tag '${repo_tag}': ${output}."
|
||||
reply "Cannot add git tag '${repo_tag}': ${output}." "${err_add_tag}"
|
||||
return
|
||||
fi
|
||||
log_info "Make source tarball."
|
||||
reply "Making source tarball..."
|
||||
if ! output="$(make tarball 2>&1)"; then
|
||||
reply "${err_make_tarball}" \
|
||||
"Cannot make tarball for tag '${repo_tag}': ${output}."
|
||||
reply "Cannot make tarball for tag '${repo_tag}': ${output}." \
|
||||
"${err_make_tarball}"
|
||||
return
|
||||
fi
|
||||
repo_version="$(make version)"
|
||||
log_info "Build RPM package '${repo_name}' v${repo_version}."
|
||||
reply "Building RPM package '${repo_name}' v${repo_version}..."
|
||||
if ! output="$(rpmbuild -bb "$repo_name.spec" 2>&1)"; then
|
||||
reply "${err_rpm_build}" \
|
||||
"Cannot build rpm for tag '${repo_tag}': ${output}."
|
||||
reply "Cannot build rpm for tag '${repo_tag}': ${output}." \
|
||||
"${err_rpm_build}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Deploy rpm package.
|
||||
log_info "Deploy RPM package."
|
||||
log_info "Deploy RPM package '${repo_name}' v${repo_version}."
|
||||
reply "Deploying RPM package '${repo_name}' v${repo_version}..."
|
||||
deployer_request="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg s "${repo_clone}/runner.sock" \
|
||||
--arg n "${repo_name}" \
|
||||
--arg v "$(make version)" \
|
||||
--arg v "${repo_version}" \
|
||||
'{"response_sock":$s,"pkg_name":$n,"pkg_version":$v}')"
|
||||
(
|
||||
inotifywait --timeout 1 --quiet --quiet \
|
||||
|
|
Loading…
Reference in New Issue