build.sh 988 Bytes
#!/bin/bash

set -e

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $current_branch != "test" ]]; then
  echo "当前不在 test 分支,脚本终止"
  exit 3
fi

output=$(git pull --rebase)
if echo "$output" | grep -q "Updating" && echo "$output" | grep -q "Fast-forward"; then
  echo "准备开始执行打包"
else
  if [[ $1 != "true" ]]; then
    echo "无文件变动"
    exit 4
  fi
  echo "准备开始执行打包[强制]"
fi

mkdir -p target

rm -rf target/*
rm -rf dist

echo "yes" | pnpm install --frozen-lockfile

pnpm build:local

mv dist/* target/

git add .

status=$(git status --porcelain)
if [[ -n $status ]]; then
  echo "准备提交打包后的文件"
else
  echo "本地没有文件变化"
  exit 4
fi

timestamp=$(date +"%Y-%m-%d %H:%M:%S")
commit_message="📦 build(*): build [${timestamp}] "
git commit -m "${commit_message}" -n

git pull --rebase

git push

sleep 3
curl https://testjenkins.feewee.cn/job/front.admin.feewee.cn/build?token=oKyioWCW