221 lines
4.9 KiB
Bash
Executable File
221 lines
4.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# ---------------- Settings
|
|
declare -A git_repo_arr
|
|
|
|
git_repo_arr[cvttpy]=git@cloud21.cvtt.vpn:/opt/store/git/cvtt2/cvttpy.git
|
|
git_repo_arr[ops]=git@cloud21.cvtt.vpn:/opt/store/git/cvtt2/ops.git
|
|
git_repo_arr[research]=git@cloud21.cvtt.vpn:/opt/store/git/cvtt2/research.git
|
|
git_repo_arr[cvtt-rust]=git@cloud21.cvtt.vpn:/opt/store/git/cvtt2/cvtt-rust.git
|
|
git_repo_arr[docker_dev]=git@cloud21.cvtt.vpn:/opt/store/git/cvtt2/docker_dev.git
|
|
|
|
dist_root=/home/cvttdist/software/cvtt2
|
|
dist_user=cvttdist
|
|
dist_host="cloud21.cvtt.vpn"
|
|
dist_ssh_port="22"
|
|
|
|
dist_locations="cloud21.cvtt.vpn:22 homestore.cvtt.vpn:22"
|
|
# ---------------- Settings
|
|
|
|
# ---------------- cmdline
|
|
prj=
|
|
brnch=master
|
|
interactive=N
|
|
|
|
usage() {
|
|
echo "Usage: $0 -p <project> [-b <branch (master)> -i (interactive)"
|
|
exit 1
|
|
}
|
|
|
|
while getopts ":p:b:i" opt; do
|
|
case ${opt} in
|
|
p )
|
|
prj=$OPTARG
|
|
;;
|
|
b )
|
|
brnch=$OPTARG
|
|
;;
|
|
i )
|
|
interactive=Y
|
|
;;
|
|
\? )
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
usage
|
|
;;
|
|
: )
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
usage
|
|
;;
|
|
esac
|
|
done
|
|
# ---------------- cmdline
|
|
|
|
confirm() {
|
|
if [ "${interactive}" == "Y" ]; then
|
|
echo "--------------------------------"
|
|
echo -n "Press <Enter> to continue" && read
|
|
fi
|
|
}
|
|
|
|
rust_binaries() {
|
|
res=()
|
|
for binname in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].targets[] | select(.kind | index("bin")) | .name'); do
|
|
res+=("${binname}")
|
|
done
|
|
echo "${res[@]}"
|
|
}
|
|
|
|
rust_libraries() {
|
|
res=()
|
|
for libname in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].targets[] | select(.kind | index("lib")) | .name'); do
|
|
res+=("lib${libname}.rlib")
|
|
done
|
|
echo "${res[@]}"
|
|
}
|
|
|
|
if [ "${interactive}" == "Y" ]; then
|
|
echo -n "Enter project [${prj}]: "
|
|
read project
|
|
if [ "${project}" == "" ]
|
|
then
|
|
project=${prj}
|
|
fi
|
|
else
|
|
project=${prj}
|
|
fi
|
|
|
|
repo=${git_repo_arr[${project}]}
|
|
if [ -z ${repo} ]; then
|
|
echo "ERROR: Project repository for ${project} not found"
|
|
exit -1
|
|
fi
|
|
echo "Project repo: ${repo}"
|
|
|
|
if [ "${interactive}" == "Y" ]; then
|
|
echo -n "Enter branch to build release from [${brnch}]: "
|
|
read branch
|
|
if [ "${branch}" == "" ]
|
|
then
|
|
branch=${brnch}
|
|
fi
|
|
else
|
|
branch=${brnch}
|
|
fi
|
|
|
|
tmp_dir=$(mktemp -d)
|
|
function cleanup {
|
|
cd ${HOME}
|
|
rm -rf ${tmp_dir}
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
|
|
prj_dir="${tmp_dir}/${prj}"
|
|
|
|
cmd_arr=()
|
|
Cmd="git clone ${repo} ${prj_dir}"
|
|
cmd_arr+=("${Cmd}")
|
|
|
|
Cmd="cd ${prj_dir}"
|
|
cmd_arr+=("${Cmd}")
|
|
|
|
if [ "${interactive}" == "Y" ]; then
|
|
echo "------------------------------------"
|
|
echo "The following commands will execute:"
|
|
echo "------------------------------------"
|
|
for cmd in "${cmd_arr[@]}"
|
|
do
|
|
echo ${cmd}
|
|
done
|
|
fi
|
|
|
|
confirm
|
|
|
|
for cmd in "${cmd_arr[@]}"
|
|
do
|
|
echo ${cmd} && eval ${cmd}
|
|
done
|
|
|
|
Cmd="git checkout ${branch}"
|
|
echo ${Cmd} && eval ${Cmd}
|
|
if [ "${?}" != "0" ]; then
|
|
echo "ERROR: Branch ${branch} is not found"
|
|
cd ${HOME} && rm -rf ${tmp_dir}
|
|
exit -1
|
|
fi
|
|
|
|
|
|
release_version=$(cat release_version.txt | awk -F',' '{print $1}')
|
|
whats_new=$(cat release_version.txt | awk -F',' '{print $2}')
|
|
|
|
|
|
echo "--------------------------------"
|
|
echo "Release version: ${release_version}"
|
|
|
|
confirm
|
|
|
|
version_tag="v${release_version}"
|
|
version_comment="'${version_tag} ${project} ${branch} $(date +%Y-%m-%d)\n${whats_new}'"
|
|
|
|
cmd_arr=()
|
|
Cmd="git tag -a ${version_tag} -m ${version_comment}"
|
|
cmd_arr+=("${Cmd}")
|
|
|
|
Cmd="git push origin --tags"
|
|
cmd_arr+=("${Cmd}")
|
|
|
|
Cmd="rm -rf .git"
|
|
cmd_arr+=("${Cmd}")
|
|
|
|
SourceLoc=../${project}
|
|
if [ "${project}" == "cvtt-rust" ]; then
|
|
|
|
cmd_arr+=("cd ${prj_dir}")
|
|
|
|
release_dir=${prj_dir}/dist/${project}
|
|
|
|
cmd_arr+=("mkdir -p ${release_dir}")
|
|
cmd_arr+=("cp release_version.txt ${release_dir}")
|
|
|
|
jq_cmd="jq '.packages[] | select(.targets[].kind[] == \"bin\") | .name'"
|
|
apps=$(cargo metadata --no-deps --format-version 1 --manifest-path=${prj_dir}/Cargo.toml | eval $jq_cmd | uniq)
|
|
for app in ${apps[@]}; do
|
|
app=${app//\"/} # remove quotes
|
|
cmd_arr+=("cargo install --root ${release_dir} --path ${prj_dir}/apps/${app}")
|
|
done
|
|
|
|
SourceLoc=${release_dir}
|
|
fi
|
|
|
|
dist_path="${dist_root}/${project}/${release_version}"
|
|
|
|
for dist_loc in ${dist_locations}; do
|
|
dhp=(${dist_loc//:/ })
|
|
dist_host=${dhp[0]}
|
|
dist_port=${dhp[1]}
|
|
Cmd="rsync -avzh"
|
|
Cmd="${Cmd} --rsync-path=\"mkdir -p ${dist_path}"
|
|
Cmd="${Cmd} && rsync\" -e \"ssh -p ${dist_ssh_port}\""
|
|
Cmd="${Cmd} $SourceLoc ${dist_user}@${dist_host}:${dist_path}/"
|
|
cmd_arr+=("${Cmd}")
|
|
done
|
|
|
|
if [ "${interactive}" == "Y" ]; then
|
|
echo "------------------------------------"
|
|
echo "The following commands will execute:"
|
|
echo "------------------------------------"
|
|
for cmd in "${cmd_arr[@]}"
|
|
do
|
|
echo ${cmd}
|
|
done
|
|
fi
|
|
|
|
confirm
|
|
|
|
for cmd in "${cmd_arr[@]}"
|
|
do
|
|
pwd && echo ${cmd} && eval ${cmd}
|
|
done
|
|
|
|
echo "$0 Done ${project} ${release_version}"
|