mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2025-12-18 05:41:31 +00:00
Separate the release steps from the bump tool
This commit is contained in:
62
tools/release.sh
Executable file
62
tools/release.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# According to the GitLab flow release branching model,
|
||||
# cherry-pick the last commit on the main branch to the release branch,
|
||||
# and then create a tag and gem package on the release branch (naming format: 'release/<X.Y>').
|
||||
#
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# It can be run on main branch, and it should be used after just finishing the last feature in the version plan,
|
||||
# or just after merging the hotfix to the main branch.
|
||||
#
|
||||
# Requires: Git, Gulp
|
||||
|
||||
set -eu
|
||||
|
||||
GEM_SPEC="jekyll-theme-chirpy.gemspec"
|
||||
|
||||
check() {
|
||||
if [[ -n $(git status . -s) ]]; then
|
||||
echo "Error: Commit unstaged files first, and then run this tool againt."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ ! -f $GEM_SPEC ]]; then
|
||||
echo -e "Error: Missing file \"$GEM_SPEC\"!\n"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
release() {
|
||||
_default_branch="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
|
||||
_version="$(grep "spec.version" jekyll-theme-chirpy.gemspec | sed 's/.*= "//;s/".*//')" # X.Y.Z
|
||||
_release_branch="release/${_version%.*}"
|
||||
|
||||
if [[ -z $(git branch -v | grep "$_release_branch") ]]; then
|
||||
# create a new release branch
|
||||
git checkout -b "$_release_branch"
|
||||
else
|
||||
# cherry-pick the latest commit from default branch to release branch
|
||||
_last_commit="$(git rev-parse "$_default_branch")"
|
||||
git checkout "$_release_branch"
|
||||
git cherry-pick "$_last_commit" -m 1
|
||||
fi
|
||||
|
||||
# create new tag
|
||||
echo -e "Create tag v$_version\n"
|
||||
git tag "v$_version"
|
||||
|
||||
# build a gem package
|
||||
echo -e "Build the gem pakcage for v$_version\n"
|
||||
rm -f ./*.gem
|
||||
gem build "$GEM_SPEC"
|
||||
|
||||
}
|
||||
|
||||
main() {
|
||||
check
|
||||
release
|
||||
}
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user