Improve the bump version tool

This commit is contained in:
Cotes Chung 2020-11-27 01:51:15 +08:00
parent 4ea320b250
commit 83bfd32807
2 changed files with 36 additions and 11 deletions

View file

@ -9,7 +9,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme" content="{{ site.data.meta.name }} {{ site.data.meta.version }}"> <meta name="theme" content="{{ site.data.meta.name }} v{{ site.data.meta.version }}">
{% seo title=false %} {% seo title=false %}

View file

@ -11,18 +11,43 @@ set -eu
META_FILE="_data/meta.yml" META_FILE="_data/meta.yml"
_latest_tag="$(git describe --abbrev=0)" bump() {
_version_field="version: $1"
_version_field="version: $_latest_tag"
if [[ ! -f $META_FILE ]]; then if [[ ! -f $META_FILE ]]; then
echo "name: Chirpy" > $META_FILE echo "name: Chirpy" > $META_FILE
echo "$_version_field" >> $META_FILE echo "$_version_field" >> $META_FILE
echo "homepage: https://github.com/cotes2020/jekyll-theme-chirpy/" >> $META_FILE
else else
sed -i "s/^version:.*/$_version_field/g" $META_FILE sed -i "s/^version:.*/$_version_field/g" $META_FILE
fi fi
if [[ -n $(git status $META_FILE -s) ]]; then if [[ -n $(git status $META_FILE -s) ]]; then
git add $META_FILE git add $META_FILE
git commit -m "Bump version to $_latest_tag" git commit -m "Bump version to $1"
fi
}
_latest_tag="$(git describe --tags --abbrev=0)"
echo "Input a version number (hint: latest version is ${_latest_tag:1})"
read version
if [[ $version =~ ^[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?$ ]]; then
if git tag --list | egrep -q "^v$version$"; then
echo "Error: version '$version' already exists"
exit -1
fi
echo "Bump version to $version"
bump "$version"
echo "Create tag v$version"
git tag "v$version"
else
echo "Error: Illegal version number: '$version'"
fi fi