Commit 2c316168 by Yvon

deploiement : add option to target specific branch instead of {coop}_prod and…

deploiement : add option to target specific branch instead of {coop}_prod and option not to send any email so that others are not spammed during tests
parent f8dd4cc9
Pipeline #3181 failed with stage
in 1 minute 10 seconds
#!/bin/bash
# $1 : project name
# $2 : instance (prod not supported for now)
ci_dir="/home/django/third-party/scripts/src"
ci_data_dir="/home/django/third-party/scripts/data"
if ! python3 "${ci_dir}/supported_coops.py" "${1}" "${2}"; then
echo "arguments : ${1} ${2} not supported"
python3 "${ci_dir}/send_error_mail.py" "arguments : ${1} ${2} not supported"
coop=$1
instance=$2 #(prod not supported for now)
#move to the third argument
shift
shift
target_branch=""
send_mails=true
#https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while [[ "$#" -gt 0 ]]; do
case $1 in
-b|--branch) target_branch="$2"; shift ;;
-n|--nomail) send_mails=false ;;
*) echo "arguments : ${coop} ${instance} $1 not supported (Unknown parameter passed: $1)"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "arguments : ${coop} ${instance} $1 not supported (Unknown parameter passed: $1)"
fi
exit 1 ;;
esac
shift
done
if ! python3 "${ci_dir}/supported_coops.py" "${coop}" "${instance}"; then
echo "arguments : ${coop} ${instance} not supported"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "arguments : ${coop} ${instance} not supported"
fi
exit 1
fi
if [[ -z "${target_branch}" ]]; then
target_branch="${coop}_prod"
fi
now=$( date +%Y%m%d_%H%M%S )
source "${ci_dir}/update_code.sh"
repo="third-party"
echo "START PROCESS" "${1}" "${2}" "${repo}" "${now}"
update_code "${1}" "${2}" "${repo}" "${now}" || exit 1
echo "START PROCESS" "${coop}" "${instance}" "${repo}" "${now}" "${target_branch}"
update_code "${coop}" "${instance}" "${repo}" "${now}" "${target_branch}" "${send_mails}" || exit 1
echo "DONE"
repo="Odoo"
echo "START PROCESS" "${1}" "${2}" "${repo}" "${now}"
update_code "${1}" "${2}" "${repo}" "${now}" || exit 1
echo "START PROCESS" "${coop}" "${instance}" "${repo}" "${now}" "${target_branch}"
update_code "${coop}" "${instance}" "${repo}" "${now}" "${target_branch}" "${send_mails}" || exit 1
echo "DONE"
if [[ "${2}" == "preprod" ]]; then
python3 "${ci_dir}/send_mail.py" "${ci_data_dir}/ci_diff_third-party_${now}.txt" "${ci_data_dir}/ci_diff_Odoo_${now}.txt" "${1}"
if [[ "${instance}" == "preprod" ]] -a ${send_mails}; then
python3 "${ci_dir}/send_mail.py" "${ci_data_dir}/ci_diff_third-party_${now}.txt" "${ci_data_dir}/ci_diff_Odoo_${now}.txt" "${coop}"
fi
......@@ -4,6 +4,8 @@ update_code() {
instance=$2
repo=$3
now=$4
target_branch=$5
send_mails=$6
ci_dir="/home/django/third-party/scripts/src"
ci_data_dir="/home/django/third-party/scripts/data"
......@@ -19,31 +21,35 @@ update_code() {
service="odoo"
else
echo "Incorrect repo name : ${repo}"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : incorrect repo name"
fi
exit 1
fi
cd /home/${user}/${repo}
su ${user} -c "git fetch --all"
branch_found_str=$( su ${user} -c "git ls-remote origin ${coop}_prod" ) #seems that git ls-remote is not "failing" so we need to check output
branch_found_str=$( su ${user} -c "git ls-remote origin ${target_branch}" ) #seems that git ls-remote is not "failing" so we need to check output
if [ -z "${branch_found_str}" ]; then
#branch prod does not exist, cannot go on
echo "${coop} ${instance} ${repo}: branch ${coop}_prod does not exist"
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : branch ${coop}_prod does not exist"
echo "${coop} ${instance} ${repo}: branch ${target_branch} does not exist"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : branch ${target_branch} does not exist"
fi
exit 1
fi
###COMPARE BRANCHES AND DECIDE IF WE NEED TO CREATE A FILE CONTAINING NEW COMMITS###
#new_commits="$( git log origin/${coop}_prod...origin/dev_cooperatic --no-merges --oneline )" (old version)
#new_commits="$( git log origin/${target_branch}...origin/dev_cooperatic --no-merges --oneline )" (old version)
#Let's break down the new big line below :
#origin/${coop}_prod...origin/dev_cooperatic : we look for difference between develop branch and prod branch
#origin/${target_branch}...origin/dev_cooperatic : we look for difference between develop branch and prod branch
#--pretty=format:'%s' : get rid of commit id
#the big grep+sed group : discard lines not maching pattern "merge [0-9]\+-... into dev_cooperatic" and only keep the [0-9]\+-.... part with a link to redmine
new_commits="$( git log origin/${coop}_prod...origin/dev_cooperatic --merges --oneline --pretty=format:'%s' | grep "into 'dev_cooperatic'" | sed "s/Merge branch '//g" | sed "s/' into 'dev_cooperatic'//g" | grep "^[0-9]\+" | sed -E 's/(^[0-9]+)/\<a href=\"https\:\/\/redmine.coopdev.fr\/issues\/\1\"\>\1\<\/a\>/g' )"
new_commits="$( git log origin/${target_branch}...origin/dev_cooperatic --merges --oneline --pretty=format:'%s' | grep "into 'dev_cooperatic'" | sed "s/Merge branch '//g" | sed "s/' into 'dev_cooperatic'//g" | grep "^[0-9]\+" | sed -E 's/(^[0-9]+)/\<a href=\"https\:\/\/redmine.coopdev.fr\/issues\/\1\"\>\1\<\/a\>/g' )"
if [ -z "${new_commits}" ]; then
echo "${coop} ${instance} ${repo} : no new commits"
#As there are no new commits in prod, we don't want to send email for this repo.
......@@ -76,7 +82,9 @@ update_code() {
if [[ ${repo} == "third-party" ]]; then
if ! test -f "coops_configurations/config_${coop}.py"; then
echo "${coop} ${instance} ${repo}: coops_configurations/config_${coop}.py does not exists"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : coops_configurations/config_${coop}.py does not exists"
fi
exit 1
fi
fi
......@@ -92,7 +100,9 @@ update_code() {
#We can not continue but we have stopped service already, let's restart it before exiting
/etc/init.d/${service} start
echo "${coop} ${instance} ${repo}: could not git checkout dev_cooperatic"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not checkout dev_cooperatic"
fi
exit 1
fi
......@@ -107,7 +117,9 @@ update_code() {
#We can not continue but we have stopped service already, let's restart it before exiting
/etc/init.d/${service} start
echo "${coop} ${instance} ${repo}: could not git pull"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not git pull"
fi
exit 1
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment