Simplify, improve bump version development script

- Just use in-built `npm version' command to update desktop, obsidian version
- Upgrade by major, minor or patch version using new -t flag in script
  E.g bump_version -t minor
This commit is contained in:
Debanjum Singh Solanky 2024-06-22 18:15:37 +05:30
parent abd6f58aee
commit 59edb99f04

View file

@ -2,26 +2,64 @@
project_root=$PWD project_root=$PWD
while getopts 'nc:' opt; while getopts 'nc:t:' opt;
do do
case "${opt}" in case "${opt}" in
t)
# Get version type to bump. Options: major, minor, patch
version_type=$OPTARG
# Bump Desktop app to current version
cd $project_root/src/interface/desktop
npm version $version_type
# Get bumped project version
current_version=$(grep '"version":' package.json | awk -F '"' '{print $4}')
# Bump Obsidian plugin to current version
cd $project_root/src/interface/obsidian
cp $project_root/versions.json .
npm version $version_type
# Bump Emacs package to current version
cd ../emacs
sed -E -i.bak "s/^;; Version: (.*)/;; Version: $current_version/" khoj.el
git add khoj.el
rm *.bak
# Copy current obsidian versioned files to project root
cd $project_root
cp src/interface/obsidian/versions.json .
cp src/interface/obsidian/manifest.json .
# Run pre-commit validation to fix jsons
pre-commit run --hook-stage manual --all
# Commit changes and tag commit for release
git add \
$project_root/src/interface/desktop/package.json \
$project_root/src/interface/obsidian/package.json \
$project_root/src/interface/obsidian/package-lock.json \
$project_root/src/interface/obsidian/manifest.json \
$project_root/src/interface/obsidian/versions.json \
$project_root/src/interface/emacs/khoj.el \
$project_root/manifest.json \
$project_root/versions.json
git commit -m "Release Khoj version $current_version"
git tag $current_version master
;;
c) c)
# Get current project version # Get current project version
current_version=$OPTARG current_version=$OPTARG
# Bump Desktop app to current version # Bump Desktop app to current version
cd $project_root/src/interface/desktop cd $project_root/src/interface/desktop
sed -E -i.bak "s/version\": \"(.*)\",/version\": \"$current_version\",/" package.json npm version $current_version
rm *.bak
# Bump Obsidian plugin to current version # Bump Obsidian plugin to current version
cd $project_root/src/interface/obsidian cd $project_root/src/interface/obsidian
sed -E -i.bak "s/version\": \"(.*)\",/version\": \"$current_version\",/" package.json
sed -E -i.bak "s/version\": \"(.*)\",/version\": \"$current_version\",/" package-lock.json
sed -E -i.bak "s/version\": \"(.*)\"/version\": \"$current_version\"/" manifest.json
cp $project_root/versions.json . cp $project_root/versions.json .
npm run version # append current version npm version $current_version
rm *.bak
# Bump Emacs package to current version # Bump Emacs package to current version
cd ../emacs cd ../emacs
@ -58,16 +96,11 @@ do
# Bump Desktop app to next version # Bump Desktop app to next version
cd $project_root/src/interface/desktop cd $project_root/src/interface/desktop
sed -E -i.bak "s/version\": \"(.*)\",/version\": \"$current_version\",/" package.json npm version $next_version
rm *.bak
# Bump Obsidian plugins to next version # Bump Obsidian plugins to next version
cd $project_root/src/interface/obsidian cd $project_root/src/interface/obsidian
sed -E -i.bak "s/version\": \"(.*)\",/version\": \"$next_version\",/" package.json npm version $next_version
sed -E -i.bak "s/version\": \"(.*)\",/version\": \"$next_version\",/" package-lock.json
sed -E -i.bak "s/version\": \"(.*)\"/version\": \"$next_version\"/" manifest.json
npm run version # updates versions.json
rm *.bak
# Bump Emacs package to next version # Bump Emacs package to next version
cd $project_root/src/interface/emacs cd $project_root/src/interface/emacs
@ -88,7 +121,7 @@ do
git commit -m "Bump Khoj to pre-release version $next_version" git commit -m "Bump Khoj to pre-release version $next_version"
;; ;;
?) ?)
echo -e "Invalid command option.\nUsage: $(basename $0) [-c] [-n]" echo -e "Invalid command option.\nUsage: $(basename $0) [-t] [-c] [-n]"
exit 1 exit 1
;; ;;
esac esac