From 83bfd32807156f7f0b82ac411d305ed278724e81 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Fri, 27 Nov 2020 01:51:15 +0800 Subject: [PATCH] Improve the bump version tool --- _includes/head.html | 2 +- tools/bump-version.sh | 45 +++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index 439f0aa..96c9454 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -9,7 +9,7 @@
- + {% seo title=false %} diff --git a/tools/bump-version.sh b/tools/bump-version.sh index e797f9b..93e86d1 100755 --- a/tools/bump-version.sh +++ b/tools/bump-version.sh @@ -11,18 +11,43 @@ set -eu 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 + echo "name: Chirpy" > $META_FILE + echo "$_version_field" >> $META_FILE + echo "homepage: https://github.com/cotes2020/jekyll-theme-chirpy/" >> $META_FILE + else + sed -i "s/^version:.*/$_version_field/g" $META_FILE + fi + + if [[ -n $(git status $META_FILE -s) ]]; then + git add $META_FILE + 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" -if [[ ! -f $META_FILE ]]; then - echo "name: Chirpy" > $META_FILE - echo "$_version_field" >> $META_FILE else - sed -i "s/^version:.*/$_version_field/g" $META_FILE -fi -if [[ -n $(git status $META_FILE -s) ]]; then - git add $META_FILE - git commit -m "Bump version to $_latest_tag" + echo "Error: Illegal version number: '$version'" fi