From c9765e69235f1d465980f3d3bf60476b5575a702 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 28 Jan 2021 22:32:54 +0800 Subject: [PATCH] Merge gem-build & bump tool Drop the yard doc --- tools/bump.sh | 59 ++++++++++++++++++++++++++++++++++++++------------- tools/gem.sh | 22 ------------------- 2 files changed, 44 insertions(+), 37 deletions(-) delete mode 100755 tools/gem.sh diff --git a/tools/bump.sh b/tools/bump.sh index 3c0390d..0a09582 100755 --- a/tools/bump.sh +++ b/tools/bump.sh @@ -1,13 +1,17 @@ #!/usr/bin/env bash # -# Bump latest version to +# 1. Bump latest version number to files: # - _sass/jekyll-theme-chirpy.scss # - assets/js/.copyright.js -# - assets/js/dist/*.js +# - assets/js/dist/*.js (will be built by gulp later) # - jekyll-theme-chirpy.gemspec # - package.json # -# Required: gulp +# 2. Create a git-tag +# +# 3. Build a rubygem package +# +# Requires: gulp, rubygem set -eu @@ -20,7 +24,28 @@ GEM_SPEC="jekyll-theme-chirpy.gemspec" NODE_META="package.json" -bump_assets() { +_check_src() { + if [[ ! -f $1 && ! -d $1 ]]; then + echo -e "Error: missing file \"$1\"!\n" + exit -1 + fi +} + +check() { + if [[ -n $(git status . -s) ]]; then + echo "Warning: commit unstaged files first, and then run this tool againt." + exit -1 + fi + + for i in "${!ASSETS[@]}"; do + _check_src "${ASSETS[$i]}" + done + + _check_src "$NODE_META" + _check_src "$GEM_SPEC" +} + +_bump_assets() { _version="$1" for i in "${!ASSETS[@]}"; do sed -i "s/v[[:digit:]]\.[[:digit:]]\.[[:digit:]]/v$_version/" "${ASSETS[$i]}" @@ -29,20 +54,20 @@ bump_assets() { gulp } -bump_gemspec() { +_bump_gemspec() { sed -i "s/[[:digit:]]\.[[:digit:]]\.[[:digit:]]/$1/" "$GEM_SPEC" } -bump_node() { +_bump_node() { sed -i \ "s,[\"]version[\"]: [\"][[:digit:]]\.[[:digit:]]\.[[:digit:]][\"],\"version\": \"$1\"," \ $NODE_META } bump() { - bump_assets "$1" - bump_gemspec "$1" - bump_node "$1" + _bump_assets "$1" + _bump_gemspec "$1" + _bump_node "$1" if [[ -n $(git status . -s) ]]; then git add . @@ -50,11 +75,12 @@ bump() { fi } +build_gem() { + gem build "$GEM_SPEC" +} + main() { - if [[ -n $(git status . -s) ]]; then - echo "Warning: commit unstaged files first, and then run this tool againt." - exit -1 - fi + check _latest_tag="$(git describe --tags --abbrev=0)" @@ -69,15 +95,18 @@ main() { exit -1 fi - echo "Bump version to $_version" + echo -e "Bump version to $_version\n" bump "$_version" - echo "Create tag v$_version" + echo -e "Create tag v$_version\n" git tag "v$_version" + build_gem + else echo "Error: Illegal version number: '$_version'" + fi } diff --git a/tools/gem.sh b/tools/gem.sh deleted file mode 100755 index 0ef0f38..0000000 --- a/tools/gem.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# -# Create a ruby-gem pakcage with doc -# -# Required: rubygem, yard - -set -eu - -GEM_CONFIG="./jekyll-theme-chirpy.gemspec" - -if [[ ! -f $GEM_CONFIG ]]; then - echo "Error: .gemspec file not found!" - exit -1 -fi - -if [[ -d doc ]]; then - rm -rf doc -fi - -yard doc - -gem build "$GEM_CONFIG"