From f4786ad43f601bac8fe813f96a170e429b8cf8ea Mon Sep 17 00:00:00 2001 From: minottic Date: Wed, 17 Aug 2022 15:28:52 +0200 Subject: [PATCH] Fix script for workflow run --- deploy_dev.sh | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) mode change 100644 => 100755 deploy_dev.sh diff --git a/deploy_dev.sh b/deploy_dev.sh old mode 100644 new mode 100755 index b1f4f8b..dd6c060 --- a/deploy_dev.sh +++ b/deploy_dev.sh @@ -5,21 +5,21 @@ function display_help() { echo " -w CI Workflow. To be specified when environment=development" echo " -s submodule name. Default to scilog" echo " -c CI repo local path. Default to ." - echo " -b CI Branch name. Default to the branch name of the submodule or the commit sha when the submodule branch is main" - echo " -r CI remote alias. Default to origin" + echo " -b CI Branch name. Default to the current branch name of the submodule" + echo " -o CI origin alias. Default to origin" echo " -m CI Main branch name. Default to main" echo " -t Github token" exit 1 } -while getopts m:b:h: flag; do +while getopts e:w:s:c:b:o:m:t: flag; do case "${flag}" in e) input_env=${OPTARG};; w) input_worfklow=${OPTARG};; s) input_submodule=${OPTARG};; c) input_cipath=${OPTARG};; b) input_branch=${OPTARG};; - r) input_remote=${OPTARG};; + o) input_origin=${OPTARG};; m) input_main=${OPTARG};; t) github_token=${OPTARG};; h) display_help; shift ;; @@ -28,9 +28,9 @@ while getopts m:b:h: flag; do done function pull() { - git fetch "$remote" + git fetch "$origin" git checkout "$main" || return $? - git pull "$remote"/"$main" || return $? + git pull "$origin"/"$main" || return $? } function commit_and_push() { @@ -39,8 +39,8 @@ function commit_and_push() { echo "Failed to checkout to main or pull. Check your local changes" exit 1 fi - git commit "$submodule" -m "Deploy $branch: $short_commit" - push=$(git push $remote $main 2>&1) + git commit "$submodule" -m "Deploy $branch: ${commit:0:7}" + push=$(git push $origin $main 2>&1) } function prepare_env_and_run() { @@ -52,13 +52,14 @@ function prepare_env_and_run() { } function workflow_dispatch() { - repo=$(echo ${a%%.git} | awk -F : '{print $2}') + remote=$(git ls-remote --get-url $origin) + repo=$(echo ${remote%%.git} | awk -F : '{print $2}') curl \ -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token $github_token" \ https://api.github.com/repos/"$repo"/actions/workflows/"$input_worfklow"/dispatches \ - -d '{"ref":"$main","inputs:{"submodule_commit":"$short_commit"}}' + -d '{"ref":"'$main'","inputs":{"submodule_commit":"'$commit'"}}' } function main() { @@ -67,17 +68,20 @@ function main() { cipath="${input_cipath:-.}" branch_parse=$(git --git-dir=$submodule/.git rev-parse --abbrev-ref HEAD) branch="${input_branch:-$branch_parse}" - remote="${input_remote:-origin}" - short_commit=$(git --git-dir=$submodule/.git rev-parse --short HEAD)y + origin="${input_origin:-origin}" + commit=$(git --git-dir=$submodule/.git rev-parse HEAD) main="${input_main:-main}" - cd "$cipath" - if [ "$environment" == "development"] + if [[ "$environment" == "development" ]]; then + echo "deploying on development" workflow_dispatch - elif [ "$environment" == "qa"] + elif [[ "$environment" == "qa" ]]; then + echo "deploying on qa" prepare_env_and_run - else + else echo "Please use either developmemt or qa" fi } +cd "$cipath" main +cd - > /dev/null