跳转到内容

❧ 内网测试服部署脚本

#!/bin/bash
# 启用错误自动退出
set -e
#检查当前分支是否是test分支
deploy_branch="test"
current_branch=$(git branch --show-current)
if [ "$current_branch" != "$deploy_branch" ]; then
echo -e "\033[31m 请切换至$deploy_branch分支后再执行! \033[0m"
exit 1
fi
# 更新代码
echo -e "\033[34m 正在拉取最新代码... \033[0m"
git pull
# 执行打包
echo -e "\033[34m 正在执行打包... \033[0m"
npm run build
# 请求webhook
function requestWebook()
{
echo -e "\033[34m 正在请求webhook... \033[0m"
curl -X GET http://192.168.160.121:4000/webhook?dir=mc-official-website
if [ $? -ne 0 ]; then
echo -e "\033[31m webhook请求失败! \033[0m"
exit 1
fi
echo -e "\033[32m webhook请求成功! \033[0m"
}
while true
do
read -r -p "确认继续提交代码吗? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
# 提交
echo -e "\033[34m 正在提交代码... \033[0m"
git add dist
git commit -m 'chore: dist'
git push
# 内网更新
requestWebook
echo -e "\033[32m 执行完成! \033[0m"
exit 1
;;
[nN][oO]|[nN])
echo -e "\033[33m 执行中断! \033[0m"
exit 1
;;
*)
echo -e "\033[31m 输入错误,请重新输入>_< \033[0m"
;;
esac
done