mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
159 lines
4.4 KiB
Bash
Executable File
159 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
_warn() {
|
|
echo -e -n "\033[1;33mWarning:\033[0m "
|
|
echo "${1}"
|
|
shift
|
|
for arg in "$@"; do
|
|
echo " ${arg}"
|
|
done
|
|
}
|
|
|
|
bump_version() {
|
|
echo "Which version part would you like to bump? ([M]ajor/[m]inor/[p]atch)"
|
|
read -r version_part
|
|
|
|
# Get current version
|
|
current_version=$(node -p "require('./package.json').version")
|
|
IFS='.' read -r major minor patch <<<"$current_version"
|
|
|
|
# Calculate new version
|
|
if [[ "$version_part" =~ ^M$ ]]; then
|
|
new_version="$((major + 1)).0.0"
|
|
elif [[ "$version_part" =~ ^m$ ]]; then
|
|
new_version="$major.$((minor + 1)).0"
|
|
elif [[ "$version_part" =~ ^p$ ]]; then
|
|
new_version="$major.$minor.$((patch + 1))"
|
|
else
|
|
echo "Invalid version part. Please use M, m, or p"
|
|
return 1
|
|
fi
|
|
|
|
# Update package.json with new version
|
|
sed -i "s/\"version\": \"$current_version\"/\"version\": \"$new_version\"/" package.json
|
|
echo "Version bumped from $current_version to $new_version"
|
|
}
|
|
|
|
commit() {
|
|
# First check if versions match between package.json and CHANGELOG.md
|
|
if ! check_versions; then
|
|
_warn "Version mismatch between package.json and CHANGELOG.md" "Please update the changelog or package.json before committing"
|
|
return 1
|
|
fi
|
|
|
|
# Check if package.json version has changed in staged changes
|
|
if git diff --cached package.json | grep -q '"version":'; then
|
|
# Get the new version from package.json
|
|
new_version=$(node -p "require('./package.json').version")
|
|
|
|
echo "Version has been changed. Would you like to tag this release as v$new_version? (y/n)"
|
|
read -r response
|
|
|
|
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
git commit
|
|
git tag -a "v$new_version" -m "Release version $new_version"
|
|
echo "Created tag v$new_version"
|
|
elif [[ "$response" =~ ^[Nn]$ ]]; then
|
|
git commit
|
|
else
|
|
_warn "Unrecognized reply: $response"
|
|
return 1
|
|
fi
|
|
else
|
|
git commit
|
|
fi
|
|
}
|
|
|
|
check_versions() {
|
|
# Get version from package.json
|
|
pkg_version=$(node -p "require('./package.json').version")
|
|
|
|
# Get latest version from CHANGELOG.md (first version entry)
|
|
changelog_version=$(grep -m 1 "^## Version" CHANGELOG.md | sed 's/^## Version //')
|
|
|
|
# Compare versions
|
|
if [ "$pkg_version" = "$changelog_version" ]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
docker_push() {
|
|
local version=$(node -p "require('./package.json').version")
|
|
# check if version already exist on dockerhub, if so, don't tag and push versioned image
|
|
if docker pull "dohsimpson/habittrove:v$version" &>/dev/null; then
|
|
echo "Docker image with tag v$version already exists on DockerHub. Skipping versioned image push"
|
|
docker tag habittrove dohsimpson/habittrove:latest
|
|
docker push dohsimpson/habittrove:latest
|
|
echo "Pushed Docker images with tags: latest"
|
|
else
|
|
docker tag habittrove "dohsimpson/habittrove:v$version"
|
|
docker push "dohsimpson/habittrove:v$version"
|
|
echo "Pushed Docker images with tags: v$version"
|
|
fi
|
|
}
|
|
|
|
run() {
|
|
npm run dev
|
|
}
|
|
|
|
build() {
|
|
npm run build
|
|
}
|
|
|
|
add_changelog() {
|
|
# Get current version from package.json
|
|
current_version=$(node -p "require('./package.json').version")
|
|
|
|
# Ask if this is for a new version
|
|
echo "Is this for a new version? (y/n)"
|
|
read -r is_new_version
|
|
|
|
if [[ "$is_new_version" =~ ^[Yy]$ ]]; then
|
|
new_version=$(node -p "require('./package.json').version")
|
|
|
|
# Add new version header
|
|
sed -i "/^# Changelog/a \\\n## Version $new_version" CHANGELOG.md
|
|
fi
|
|
|
|
while true; do
|
|
# Get change type
|
|
echo "What type of change is this? ([A]dded/[C]hanged/[F]ixed/[R]emoved)"
|
|
read -r change_type
|
|
|
|
case $change_type in
|
|
A | a) change_type="Added" ;;
|
|
C | c) change_type="Changed" ;;
|
|
F | f) change_type="Fixed" ;;
|
|
R | r) change_type="Removed" ;;
|
|
*)
|
|
echo "Invalid change type"
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
# Get change description
|
|
echo "Enter description of the change:"
|
|
read -r change_desc
|
|
|
|
# Add the change to CHANGELOG.md
|
|
if grep -q "^### $change_type" CHANGELOG.md; then
|
|
# If type exists, append to it
|
|
sed -i "/^### $change_type$/a - $change_desc" CHANGELOG.md
|
|
else
|
|
# If type doesn't exist, create new section
|
|
sed -i "/^## Version/ {N; s/\n/\n\n### $change_type\n- $change_desc\n/}" CHANGELOG.md
|
|
fi
|
|
|
|
echo "Change added successfully!"
|
|
|
|
# Ask if user wants to add another change
|
|
echo "Add another change? (y/n)"
|
|
read -r add_another
|
|
[[ "$add_another" =~ ^[Yy]$ ]] || break
|
|
done
|
|
|
|
echo "Changelog update complete!"
|
|
}
|