mirror of
https://github.com/ivuorinen/actions.git
synced 2026-02-07 10:44:49 +00:00
feat: extended release make target, fixes (#329)
* feat: extended release make target, fixes * fix: cr comments
This commit is contained in:
150
_tools/shared.sh
150
_tools/shared.sh
@@ -14,12 +14,12 @@ YELLOW='\033[1;33m'
|
||||
# shellcheck disable=SC2034
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Validate CalVer version format: vYYYY.MM.DD
|
||||
# Validate CalVer version format: vYYYY.MM.DD (zero-padded)
|
||||
validate_version() {
|
||||
version="$1"
|
||||
|
||||
# Check format: vYYYY.MM.DD using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}\.[0-9]{1,2}\.[0-9]{1,2}$'; then
|
||||
# Check format: vYYYY.MM.DD (require zero-padding) using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}\.[0-9]{2}\.[0-9]{2}$'; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -34,12 +34,12 @@ validate_version() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate month (1-12)
|
||||
# Validate month (01-12)
|
||||
if [ "$month" -lt 1 ] || [ "$month" -gt 12 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate day (1-31)
|
||||
# Validate day (01-31)
|
||||
if [ "$day" -lt 1 ] || [ "$day" -gt 31 ]; then
|
||||
return 1
|
||||
fi
|
||||
@@ -67,12 +67,12 @@ validate_major_version() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# Validate minor version format: vYYYY.MM
|
||||
# Validate minor version format: vYYYY.MM (zero-padded)
|
||||
validate_minor_version() {
|
||||
version="$1"
|
||||
|
||||
# Check format: vYYYY.MM using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}\.[0-9]{1,2}$'; then
|
||||
# Check format: vYYYY.MM (require zero-padding) using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}\.[0-9]{2}$'; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -86,7 +86,7 @@ validate_minor_version() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate month (1-12)
|
||||
# Validate month (01-12)
|
||||
if [ "$month" -lt 1 ] || [ "$month" -gt 12 ]; then
|
||||
return 1
|
||||
fi
|
||||
@@ -94,6 +94,134 @@ validate_minor_version() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if working directory is clean (no uncommitted changes)
|
||||
check_git_clean() {
|
||||
if ! has_git; then
|
||||
return 1
|
||||
fi
|
||||
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if currently on specified branch (default: main)
|
||||
check_on_branch() {
|
||||
target_branch="${1:-main}"
|
||||
|
||||
if ! has_git; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || return 1
|
||||
|
||||
if [ "$current_branch" != "$target_branch" ]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if a git tag exists
|
||||
check_tag_exists() {
|
||||
tag="$1"
|
||||
|
||||
if ! has_git; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if git rev-parse "$tag" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Prompt user for yes/no confirmation
|
||||
# Usage: if prompt_confirmation "Continue?"; then ...; fi
|
||||
prompt_confirmation() {
|
||||
prompt_text="${1:-Continue?}"
|
||||
timeout_seconds="${2:-30}"
|
||||
|
||||
# Check if stdin is a TTY (interactive terminal)
|
||||
if [ ! -t 0 ]; then
|
||||
msg_error "Non-interactive session detected - cannot prompt for confirmation"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if timeout command is available for optional timeout support
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
printf '%s [y/N] (timeout in %ss) ' "$prompt_text" "$timeout_seconds"
|
||||
|
||||
# Use timeout command to limit read duration
|
||||
# shellcheck disable=SC2016
|
||||
if response=$(timeout "$timeout_seconds" sh -c 'read -r r && echo "$r"' 2>/dev/null); then
|
||||
: # read succeeded within timeout
|
||||
else
|
||||
printf '\n'
|
||||
msg_warn "Confirmation timeout - defaulting to No"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
# No timeout available - plain read
|
||||
printf '%s [y/N] ' "$prompt_text"
|
||||
read -r response || return 1
|
||||
fi
|
||||
|
||||
case "$response" in
|
||||
[yY]|[yY][eE][sS])
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Message output functions for consistent, colored output
|
||||
# These functions provide a clean API for printing status messages
|
||||
|
||||
# msg_error "message" - Print error message in red with ✗ symbol to stderr
|
||||
msg_error() {
|
||||
printf '%s✗ %s%s\n' "$RED" "$1" "$NC" >&2
|
||||
}
|
||||
|
||||
# msg_success "message" - Print success message in green with ✓ symbol
|
||||
msg_success() {
|
||||
printf '%s✓ %s%s\n' "$GREEN" "$1" "$NC"
|
||||
}
|
||||
|
||||
# msg_done "message" - Print completion message in green with ✅ symbol
|
||||
msg_done() {
|
||||
printf '%s✅ %s%s\n' "$GREEN" "$1" "$NC"
|
||||
}
|
||||
|
||||
# msg_info "message" - Print info/status message in blue (no symbol)
|
||||
msg_info() {
|
||||
printf '%s%s%s\n' "$BLUE" "$1" "$NC"
|
||||
}
|
||||
|
||||
# msg_warn "message" - Print warning message in yellow (no symbol)
|
||||
msg_warn() {
|
||||
printf '%s%s%s\n' "$YELLOW" "$1" "$NC"
|
||||
}
|
||||
|
||||
# msg_item "message" - Print indented item with ✓ in green
|
||||
msg_item() {
|
||||
printf ' %s✓%s %s\n' "$GREEN" "$NC" "$1"
|
||||
}
|
||||
|
||||
# msg_notice "message" - Print indented notice with ℹ in blue
|
||||
msg_notice() {
|
||||
printf ' %sℹ%s %s\n' "$BLUE" "$NC" "$1"
|
||||
}
|
||||
|
||||
# msg_plain "color" "message" - Print plain colored message (no symbol)
|
||||
# Usage: msg_plain "$YELLOW" "=== BANNER ==="
|
||||
msg_plain() {
|
||||
color="$1"
|
||||
message="$2"
|
||||
printf '%s%s%s\n' "$color" "$message" "$NC"
|
||||
}
|
||||
|
||||
# Get the directory where the calling script is located
|
||||
get_script_dir() {
|
||||
cd "$(dirname -- "$1")" && pwd
|
||||
@@ -107,7 +235,7 @@ has_git() {
|
||||
# Require git to be available, exit with error if not
|
||||
require_git() {
|
||||
if ! has_git; then
|
||||
printf '%b' "${RED}Error: git is not installed or not in PATH${NC}\n" >&2
|
||||
msg_error "git is not installed or not in PATH"
|
||||
printf 'Please install git to use this script.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -117,7 +245,7 @@ require_git() {
|
||||
safe_mktemp() {
|
||||
_temp_file=""
|
||||
if ! _temp_file=$(mktemp); then
|
||||
printf '%b' "${RED}Error: Failed to create temp file${NC}\n" >&2
|
||||
msg_error "Failed to create temp file"
|
||||
exit 1
|
||||
fi
|
||||
printf '%s' "$_temp_file"
|
||||
|
||||
Reference in New Issue
Block a user