Skip to content

Commit

Permalink
feat: ✨ add for loop through cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Augustin <dev@andreas-augustin.org>
  • Loading branch information
AndreasAugustin committed Apr 22, 2024
1 parent d0d70e1 commit d1a4b11
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,50 @@ function arr_push_prepare_pr_create_pr() {
echo "::endgroup::"
}

declare -A arr

arr["prechecks"]=arr_prechecks
arr["pull"]=arr_checkout_branch_and_pull
arr["commit"]=arr_commit
arr["push"]=arr_push
arr["pr"]=arr_push_prepare_pr_create_pr

${arr["prechecks"]}
${arr["pull"]}
${arr["commit"]}
${arr["push"]}
${arr["pr"]}
declare -A cmd_arr

cmd_arr["prechecks"]=arr_prechecks
cmd_arr["pull"]=arr_checkout_branch_and_pull
cmd_arr["commit"]=arr_commit
cmd_arr["push"]=arr_push
cmd_arr["pr"]=arr_push_prepare_pr_create_pr

if [[ -z "${STEPS}" ]]; then
info "no steps provided. Default is to execute all."
for key in "${!cmd_arr[@]}";
do
debug "execute cmd ${key}"
${cmd_arr[${key}]}
done
else
info "steps provided."
readarray -t steps < <(awk -F',' '{ for( i=1; i<=NF; i++ ) print $i }' <<<"${STEPS}")
# check if steps are supported
not_supported_steps=""
for step in "${steps[@]}";
do
matched=false
for key in "${!cmd_arr[@]}";
do
debug "execute cmd ${key}"
if [[ "${step}" == "${key}" ]]; then
matched=true;
fi
done
if [[ "$matched" == 'false' ]]; then
not_supported_steps="${not_supported_steps} $step"
fi
done
if [[ -z "${not_supported_steps}" ]]; then
for step in "${steps[@]}";
do
debug "execute cmd ${step}"
${cmd_arr[${step}]}
done
else
err "follwoing steps are not supported ${not_supported_steps}"
exit 1
fi
fi

set_github_action_outputs "${PR_BRANCH}" "${TEMPLATE_GIT_HASH}"

0 comments on commit d1a4b11

Please sign in to comment.