[Dev] Check pipeline argument before starting process

This commit is contained in:
samuel 2023-04-30 23:32:12 +02:00
parent 48ab309698
commit aa90bedd37
1 changed files with 33 additions and 21 deletions

View File

@ -130,7 +130,39 @@ main() (
usage
fail "Missing positionnal argument PIPELINE."
fi
# Check pipeline validity.
pipeline="$1"
case "${pipeline}" in
newcommit)
if [ -z "${repo_name}" ]; then
usage
fail "missing option -n|--name for pipeline '${pipeline}'."
fi
if [ -z "${repo_hash}" ]; then
usage
fail "missing option -h|--hash for pipeline '${pipeline}'."
fi
;;
newtag)
if [ -z "${repo_name}" ]; then
usage
fail "Missing option -n|--name for pipeline '${pipeline}'."
fi
if [ -z "${repo_hash}" ]; then
usage
fail "Missing option -H|--hash for pipeline '${pipeline}'."
fi
if [ -z "${repo_tag}" ]; then
usage
fail "Missing option -T|--tag for pipeline '${pipeline}'."
fi
;;
*)
usage
fail "Unexpected value for PIPELINE: '${pipeline}'."
;;
esac
# Load config file.
if [ ! -r "${config_file}" ]; then
@ -189,17 +221,9 @@ main() (
rd_pipeline_sock_dir="${pipeline_sock_dir}/${pipeline}-${tsp}-${random}"
rd_pipeline_sock="${rd_pipeline_sock_dir}/pipeline.sock"
# Check pipeline with options.
# Build runner request.
case "${pipeline}" in
newcommit)
if [ -z "${repo_name}" ]; then
usage
fail "Missing option -n|--name for pipeline '${pipeline}'."
fi
if [ -z "${repo_hash}" ]; then
usage
fail "Missing option -H|--hash for pipeline '${pipeline}'."
fi
runner_request="$(jq --null-input --compact-output \
--arg s "${rd_pipeline_sock}" \
--arg n "${repo_name}" \
@ -207,18 +231,6 @@ main() (
'{"response_sock":$s,"repo_name":$n,"repo_hash":$h}')"
;;
newtag)
if [ -z "${repo_name}" ]; then
usage
fail "Missing option -n|--name for pipeline '${pipeline}'."
fi
if [ -z "${repo_hash}" ]; then
usage
fail "Missing option -H|--hash for pipeline '${pipeline}'."
fi
if [ -z "${repo_tag}" ]; then
usage
fail "Missing option -T|--tag for pipeline '${pipeline}'."
fi
runner_request="$(jq --null-input --compact-output \
--arg s "${rd_pipeline_sock}" \
--arg n "${repo_name}" \