-
Notifications
You must be signed in to change notification settings - Fork 39
/
release.sh
executable file
·52 lines (45 loc) · 1.3 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
set -e
# if ! [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]; then
# echo "Invalid tag: $TAG, must be in the form of vMAJOR.MINOR.PATCH,example: v1.0.0"
# exit 1
# fi
# 检查当前是否为master分支
if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
echo "You must be on the master branch to release"
exit 1
fi
# 检查是否有未提交的修改
if ! git diff-index --quiet HEAD --; then
# 如果当前环境为github codespace,检测结果有误,跳过
if [ -n "$CODESPACES" ]; then
echo "skip uncommitted changes check in codespace"
else
echo "You have uncommitted changes, please commit or stash them"
exit 1
fi
fi
# 检查本地与远程是否有同步问题
if ! git diff-index --quiet --cached HEAD --; then
echo "Your local repository is out of sync with remote, please sync first"
exit 1
fi
## 获取第一个参数为tag
TAG=$1
if [ -z "$TAG" ]; then
echo "Usage: $0 <tag>"
exit 1
fi
# 判断是否是tag
if ! echo "$TAG" | grep -q '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'; then
echo "Invalid tag: $TAG, must be in the form of vMAJOR.MINOR.PATCH,example: v1.0.0"
exit 1
fi
# 推送到master
git push origin master
# 创建tag
git tag $TAG
# 提交tag
git push origin $TAG
# 显示最新的tag
git describe --tags --abbrev=0