Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Back port --self-update --major (#92)
Browse files Browse the repository at this point in the history
[Feature]
- Restrict major version updates with --self-update unless --major is specified

To prepare for the upcoming major update, I have modified the --self-update behavior. Now, updating to a new major HeavyScript version requires the explicit use of the --major flag.

The new CLI is under development and can be found on the "args" branch. It will remain there until it's fully developed and tested.
  • Loading branch information
Heavybullets8 authored Mar 31, 2023
1 parent 264b64b commit 7f60f93
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
37 changes: 29 additions & 8 deletions functions/self_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
args=("$@")


is_major_update() {
local current_version="${1#v}"
local latest_version="${2#v}"

local current_major_version="${current_version%%.*}"
local latest_major_version="${latest_version%%.*}"

if [[ "$latest_major_version" -gt "$current_major_version" ]]; then
return 0
else
return 1
fi
}


choose_branch() {
clear -x
echo "Pulling git information.."
Expand Down Expand Up @@ -86,14 +101,20 @@ update_func(){
else
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
if [[ "$hs_version" != "$latest_tag" ]] ; then
echo "Found a new version of HeavyScript, updating myself..."
git checkout --force "$latest_tag" &>/dev/null
echo "Updating from: $hs_version"
echo "Updating To: $latest_tag"
echo "Changelog:"
curl --silent "https://api.github.com/repos/HeavyBullets8/heavy_script/releases/latest" | jq -r .body
echo
return 111
if [[ "$include_major" == "true" ]] || ! is_major_update "${hs_version}" "${latest_tag}"; then
echo "Found a new version of HeavyScript, updating myself..."
git checkout --force "$latest_tag" &>/dev/null
echo "Updating from: $hs_version"
echo "Updating To: $latest_tag"
echo "Changelog:"
curl --silent "https://api.github.com/repos/HeavyBullets8/heavy_script/releases/latest" | jq -r .body
echo
return 111
else
echo "A major update is available: $latest_tag"
echo "Skipping the update due to major version change."
echo "To update to the latest version, run: heavyscript --self-update --major"
fi
else
echo "HeavyScript is already the latest version:"
echo -e "$hs_version\n\n"
Expand Down
3 changes: 3 additions & 0 deletions heavy_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ do
restart-app)
restart_app=true
;;
major)
include_major=true
;;
*)
echo -e "Invalid Option \"--$OPTARG\"\n"
help
Expand Down

0 comments on commit 7f60f93

Please sign in to comment.