bump_version.sh
1 #!/bin/zsh 2 3 project_root=$PWD 4 5 while getopts 'nc:t:p:' opt; 6 do 7 case "${opt}" in 8 p) 9 # Create pre-release SemVer version. Options: alpha, beta, rc 10 prerelease_type=$OPTARG 11 12 # Get the current version from web package.json to determine base version 13 cd $project_root/src/interface/web 14 current_base_version=$(grep '"version":' package.json | awk -F '"' '{print $4}') 15 16 # Extract base version (remove any existing pre-release suffix) 17 base_version=$(echo $current_base_version | sed 's/-.*$//') 18 19 # If current version is already 2.x.x, increment the pre-release number 20 if [[ $current_base_version == *"-$prerelease_type"* ]]; then 21 # Extract current pre-release number and increment 22 current_num=$(echo $current_base_version | sed "s/.*-$prerelease_type\.//" | sed 's/[^0-9]*$//') 23 next_num=$((current_num + 1)) 24 current_version="$base_version-$prerelease_type.$next_num" 25 else 26 # If base version is 1.x.x, bump to 2.0.0-prerelease.1 27 if [[ $base_version == 1.* ]]; then 28 current_version="2.0.0-$prerelease_type.1" 29 else 30 # Otherwise add pre-release to current base version 31 current_version="$base_version-$prerelease_type.1" 32 fi 33 fi 34 35 # Bump Web app to pre-release version 36 cd $project_root/src/interface/web 37 yarn version --new-version $current_version --no-git-tag-version 38 39 # Bump Desktop app to pre-release version 40 cd $project_root/src/interface/desktop 41 yarn version --new-version $current_version --no-git-tag-version 42 43 # Bump Obsidian plugin to pre-release version 44 cd $project_root/src/interface/obsidian 45 yarn build # verify build before bumping version 46 yarn version --new-version $current_version --no-git-tag-version 47 # append current version, min Obsidian app version from manifest to versions json 48 cp $project_root/versions.json . 49 yarn run version # run Obsidian version script 50 51 # Bump Emacs package to pre-release version 52 cd ../emacs 53 sed -E -i.bak "s/^;; Version: (.*)/;; Version: $current_version/" khoj.el 54 git add khoj.el 55 rm *.bak 56 57 # Copy current obsidian versioned files to project root 58 cd $project_root 59 cp src/interface/obsidian/versions.json . 60 cp src/interface/obsidian/manifest.json . 61 62 # Run pre-commit validation to fix jsons 63 pre-commit run --hook-stage manual --all 64 65 # Commit changes and tag commit for pre-release 66 git add \ 67 $project_root/src/interface/web/package.json \ 68 $project_root/src/interface/desktop/package.json \ 69 $project_root/src/interface/obsidian/package.json \ 70 $project_root/src/interface/obsidian/yarn.lock \ 71 $project_root/src/interface/obsidian/manifest.json \ 72 $project_root/src/interface/obsidian/versions.json \ 73 $project_root/src/interface/emacs/khoj.el \ 74 $project_root/manifest.json \ 75 $project_root/versions.json 76 git commit -m "Release Khoj version $current_version" 77 git tag $current_version 78 ;; 79 t) 80 # Get version type to bump. Options: major, minor, patch 81 version_type=$OPTARG 82 83 # Bump Web app to current version 84 cd $project_root/src/interface/web 85 yarn version --$version_type --no-git-tag-version 86 87 # Bump Desktop app to current version 88 cd $project_root/src/interface/desktop 89 yarn version --$version_type --no-git-tag-version 90 91 # Get bumped project version 92 current_version=$(grep '"version":' package.json | awk -F '"' '{print $4}') 93 94 # Bump Obsidian plugin to current version 95 cd $project_root/src/interface/obsidian 96 yarn build # verify build before bumping version 97 yarn version --$version_type --no-git-tag-version 98 # append current version, min Obsidian app version from manifest to versions json 99 cp $project_root/versions.json . 100 yarn run version # run Obsidian version script 101 102 # Bump Emacs package to current version 103 cd ../emacs 104 sed -E -i.bak "s/^;; Version: (.*)/;; Version: $current_version/" khoj.el 105 git add khoj.el 106 rm *.bak 107 108 # Copy current obsidian versioned files to project root 109 cd $project_root 110 cp src/interface/obsidian/versions.json . 111 cp src/interface/obsidian/manifest.json . 112 113 # Run pre-commit validation to fix jsons 114 pre-commit run --hook-stage manual --all 115 116 # Commit changes and tag commit for release 117 git add \ 118 $project_root/src/interface/web/package.json \ 119 $project_root/src/interface/desktop/package.json \ 120 $project_root/src/interface/obsidian/package.json \ 121 $project_root/src/interface/obsidian/yarn.lock \ 122 $project_root/src/interface/obsidian/manifest.json \ 123 $project_root/src/interface/obsidian/versions.json \ 124 $project_root/src/interface/emacs/khoj.el \ 125 $project_root/manifest.json \ 126 $project_root/versions.json 127 git commit -m "Release Khoj version $current_version" 128 git tag $current_version 129 ;; 130 c) 131 # Get current project version 132 current_version=$OPTARG 133 134 # Bump Web app to current version 135 cd $project_root/src/interface/web 136 yarn version --new-version $current_version --no-git-tag-version 137 138 # Bump Desktop app to current version 139 cd $project_root/src/interface/desktop 140 yarn version --new-version $current_version --no-git-tag-version 141 142 # Bump Obsidian plugin to current version 143 cd $project_root/src/interface/obsidian 144 yarn version --new-version $current_version --no-git-tag-version 145 # append current version, min Obsidian app version from manifest.json to versions.json 146 cp $project_root/versions.json . 147 yarn run version # run Obsidian version script 148 149 # Bump Emacs package to current version 150 cd ../emacs 151 sed -E -i.bak "s/^;; Version: (.*)/;; Version: $current_version/" khoj.el 152 git add khoj.el 153 rm *.bak 154 155 # Copy current obsidian versioned files to project root 156 cd $project_root 157 cp src/interface/obsidian/versions.json . 158 cp src/interface/obsidian/manifest.json . 159 160 # Run pre-commit validation to fix jsons 161 pre-commit run --hook-stage manual --all 162 163 # Commit changes and tag commit for release 164 git add \ 165 $project_root/src/interface/web/package.json \ 166 $project_root/src/interface/desktop/package.json \ 167 $project_root/src/interface/obsidian/package.json \ 168 $project_root/src/interface/obsidian/yarn.lock \ 169 $project_root/src/interface/obsidian/manifest.json \ 170 $project_root/src/interface/obsidian/versions.json \ 171 $project_root/src/interface/emacs/khoj.el \ 172 $project_root/manifest.json \ 173 $project_root/versions.json 174 git commit -m "Release Khoj version $current_version" 175 git tag $current_version 176 ;; 177 n) 178 # Induce hatch to compute next version number 179 # remove .dev[commits-since-tag] version suffix from hatch computed version number 180 next_version=$(touch bump.txt && git add bump.txt && hatch version | sed 's/\.dev.*//g') 181 git rm --cached -- bump.txt && rm bump.txt 182 183 # Bump Web app to next version 184 cd $project_root/src/interface/web 185 yarn version --new-version $next_version --no-git-tag-version 186 187 # Bump Desktop app to next version 188 cd $project_root/src/interface/desktop 189 yarn version --new-version $next_version --no-git-tag-version 190 191 # Bump Obsidian plugins to next version 192 cd $project_root/src/interface/obsidian 193 yarn version --new-version $next_version --no-git-tag-version 194 # append next version, min Obsidian app version from manifest to versions json 195 git rm --cached -- versions.json 196 yarn run version # run Obsidian version script 197 198 # Bump Emacs package to next version 199 cd $project_root/src/interface/emacs 200 sed -E -i.bak "s/^;; Version: (.*)/;; Version: $next_version/" khoj.el 201 rm *.bak 202 203 # Run pre-commit validations to fix jsons 204 pre-commit run --hook-stage manual --all 205 206 # Commit changes 207 git add \ 208 $project_root/src/interface/web/package.json \ 209 $project_root/src/interface/desktop/package.json \ 210 $project_root/src/interface/obsidian/package.json \ 211 $project_root/src/interface/obsidian/yarn.lock \ 212 $project_root/src/interface/obsidian/manifest.json \ 213 $project_root/src/interface/obsidian/versions.json \ 214 $project_root/src/interface/emacs/khoj.el 215 git commit -m "Bump Khoj to pre-release version $next_version" 216 ;; 217 ?) 218 echo -e "Invalid command option.\nUsage: $(basename $0) [-t type] [-c version] [-p prerelease] [-n]" 219 echo -e " -t: Bump version by type (major, minor, patch)" 220 echo -e " -c: Set specific version" 221 echo -e " -p: Create pre-release version (alpha, beta, rc)" 222 echo -e " -n: Compute and set next version using hatch" 223 exit 1 224 ;; 225 esac 226 done 227 228 # Restore State 229 cd $project_root