prod-build.sh 988 Bytes
#!/bin/bash

set -e

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $current_branch != "master" ]]; then
  echo "当前不在 master 分支,脚本终止"
  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
rm -rf fw-cms.tar.gz

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

pnpm install && pnpm build:prod_local

tar -zcvf fw-cms.tar.gz ./dist &>/dev/null

node post.js

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(*): prod build [${timestamp}] "
git commit -m "${commit_message}" -n

git pull --rebase

git push