2021-01-25 01:20:51 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2021-01-28 17:32:54 +03:00
|
|
|
# 1. Bump latest version number to files:
|
2021-01-25 01:20:51 +03:00
|
|
|
# - _sass/jekyll-theme-chirpy.scss
|
2021-01-27 23:57:11 +03:00
|
|
|
# - assets/js/.copyright.js
|
2021-01-28 17:32:54 +03:00
|
|
|
# - assets/js/dist/*.js (will be built by gulp later)
|
2021-01-25 01:20:51 +03:00
|
|
|
# - jekyll-theme-chirpy.gemspec
|
2021-01-27 23:57:11 +03:00
|
|
|
# - package.json
|
2021-01-25 01:20:51 +03:00
|
|
|
#
|
2021-01-28 17:32:54 +03:00
|
|
|
# 2. Create a git-tag
|
|
|
|
#
|
|
|
|
# 3. Build a rubygem package
|
|
|
|
#
|
|
|
|
# Requires: gulp, rubygem
|
2021-01-25 01:20:51 +03:00
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
ASSETS=(
|
|
|
|
"_sass/jekyll-theme-chirpy.scss"
|
|
|
|
"assets/js/.copyright"
|
|
|
|
)
|
|
|
|
|
|
|
|
GEM_SPEC="jekyll-theme-chirpy.gemspec"
|
|
|
|
|
2021-01-26 22:17:00 +03:00
|
|
|
NODE_META="package.json"
|
|
|
|
|
2021-01-28 17:32:54 +03:00
|
|
|
_check_src() {
|
|
|
|
if [[ ! -f $1 && ! -d $1 ]]; then
|
2021-02-02 16:29:31 +03:00
|
|
|
echo -e "Error: Missing file \"$1\"!\n"
|
2021-01-28 17:32:54 +03:00
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check() {
|
|
|
|
if [[ -n $(git status . -s) ]]; then
|
2021-02-02 16:29:31 +03:00
|
|
|
echo "Error: Commit unstaged files first, and then run this tool againt."
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ensure the current branch is 'master'
|
|
|
|
if [[ "$(git branch --show-current)" != "master" ]]; then
|
|
|
|
echo "Error: This operation must be performed on the 'master' branch!"
|
2021-01-28 17:32:54 +03:00
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in "${!ASSETS[@]}"; do
|
|
|
|
_check_src "${ASSETS[$i]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
_check_src "$NODE_META"
|
|
|
|
_check_src "$GEM_SPEC"
|
|
|
|
}
|
|
|
|
|
|
|
|
_bump_assets() {
|
2021-01-25 01:20:51 +03:00
|
|
|
_version="$1"
|
2021-01-27 15:06:31 +03:00
|
|
|
for i in "${!ASSETS[@]}"; do
|
|
|
|
sed -i "s/v[[:digit:]]\.[[:digit:]]\.[[:digit:]]/v$_version/" "${ASSETS[$i]}"
|
2021-01-25 01:20:51 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
gulp
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:32:54 +03:00
|
|
|
_bump_gemspec() {
|
2021-01-27 15:06:31 +03:00
|
|
|
sed -i "s/[[:digit:]]\.[[:digit:]]\.[[:digit:]]/$1/" "$GEM_SPEC"
|
2021-01-26 22:17:00 +03:00
|
|
|
}
|
|
|
|
|
2021-01-28 17:32:54 +03:00
|
|
|
_bump_node() {
|
2021-01-26 22:17:00 +03:00
|
|
|
sed -i \
|
|
|
|
"s,[\"]version[\"]: [\"][[:digit:]]\.[[:digit:]]\.[[:digit:]][\"],\"version\": \"$1\"," \
|
|
|
|
$NODE_META
|
2021-01-25 01:20:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bump() {
|
2021-01-28 17:32:54 +03:00
|
|
|
_bump_assets "$1"
|
|
|
|
_bump_gemspec "$1"
|
|
|
|
_bump_node "$1"
|
2021-01-25 01:20:51 +03:00
|
|
|
|
|
|
|
if [[ -n $(git status . -s) ]]; then
|
|
|
|
git add .
|
|
|
|
git commit -m "Bump version to $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:32:54 +03:00
|
|
|
build_gem() {
|
2021-02-02 16:29:31 +03:00
|
|
|
rm -f ./*.gem
|
2021-01-28 17:32:54 +03:00
|
|
|
gem build "$GEM_SPEC"
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:29:31 +03:00
|
|
|
release() {
|
|
|
|
_version="$1"
|
|
|
|
_major=""
|
|
|
|
_minor=""
|
|
|
|
|
|
|
|
IFS='.' read -r -a array <<< "$_version"
|
|
|
|
|
|
|
|
for elem in "${array[@]}"; do
|
|
|
|
if [[ -z $_major ]]; then
|
|
|
|
_major="$elem"
|
|
|
|
elif [[ -z $_minor ]]; then
|
|
|
|
_minor="$elem"
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
_release_branch="$_major-$_minor-stable"
|
|
|
|
|
|
|
|
if [[ -z $(git branch -v | grep "$_release_branch") ]]; then
|
|
|
|
git checkout -b "$_release_branch"
|
|
|
|
else
|
|
|
|
git checkout "$_release_branch"
|
|
|
|
# cherry-pick the latest 2 commit from master to release branch
|
|
|
|
git cherry-pick "$(git rev-parse master~1)" "$(git rev-parse master)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "Create tag v$_version\n"
|
|
|
|
git tag "v$_version"
|
|
|
|
|
|
|
|
build_gem
|
|
|
|
|
|
|
|
# head back to master branch
|
|
|
|
git checkout master
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-25 01:20:51 +03:00
|
|
|
main() {
|
2021-01-28 17:32:54 +03:00
|
|
|
check
|
2021-01-25 01:20:51 +03:00
|
|
|
|
2021-02-02 16:29:31 +03:00
|
|
|
_latest_tag="$(git describe --tags $(git rev-list --tags --max-count=1))"
|
2021-01-25 01:20:51 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-01-28 17:32:54 +03:00
|
|
|
echo -e "Bump version to $_version\n"
|
2021-01-25 01:20:51 +03:00
|
|
|
bump "$_version"
|
|
|
|
|
2021-02-02 16:29:31 +03:00
|
|
|
echo -e "Release to v$_version\n"
|
|
|
|
release "$_version"
|
2021-01-28 17:32:54 +03:00
|
|
|
|
2021-01-25 01:20:51 +03:00
|
|
|
else
|
|
|
|
echo "Error: Illegal version number: '$_version'"
|
|
|
|
fi
|
2021-02-02 16:29:31 +03:00
|
|
|
|
2021-01-25 01:20:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main
|