Skip to content

feat: add version check and self-update capability - #4

Merged
tcoretech merged 2 commits into
mainfrom
claude/add-version-check-update-5Chpr
Jan 5, 2026
Merged

tcoretech merged 2 commits into
mainfrom
claude/add-version-check-update-5Chpr

Conversation

@tjcork

@tjcork tjcork commented Dec 31, 2025

Copy link
Copy Markdown
Collaborator

Add the ability to detect when a newer version of n8n-git is available
and provide a self-update mechanism.

Changes:

  • Add lib/utils/version.sh with version check and update functions
  • Add 'update' command to download and install latest release
  • Add 'version' command to display version info and check for updates
  • Add --version/-V flag for quick version display
  • Add update notification at startup (cached, non-blocking)
  • Add 'make update' target to Makefile
  • Update help text with new commands and examples

The update check uses GitHub API with 24-hour caching to avoid
rate limiting. For development installations, it suggests using
git pull instead of the update command.

Add the ability to detect when a newer version of n8n-git is available
and provide a self-update mechanism.

Changes:
- Add lib/utils/version.sh with version check and update functions
- Add 'update' command to download and install latest release
- Add 'version' command to display version info and check for updates
- Add --version/-V flag for quick version display
- Add update notification at startup (cached, non-blocking)
- Add 'make update' target to Makefile
- Update help text with new commands and examples

The update check uses GitHub API with 24-hour caching to avoid
rate limiting. For development installations, it suggests using
git pull instead of the update command.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds version checking and self-update capabilities to n8n-git, allowing users to detect when newer versions are available and upgrade their installation directly from the command line. The implementation includes GitHub API integration with intelligent caching to avoid rate limiting, and supports multiple installation types (system, user, and development).

Key changes:

  • New version management utility with update checking, version comparison, and self-update functionality
  • New update and version commands with corresponding CLI flags
  • Startup notification system that alerts users of available updates using cached checks

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 14 comments.

File Description
n8n-git.sh Added version.sh sourcing, new command handlers for update and version, version flag support, and startup update notifications
lib/utils/version.sh New utility providing version checking, comparison logic, installation detection, and self-update mechanism with GitHub API integration
lib/utils/interactive.sh Updated help text to document new update and version commands and --version flag
Makefile Added make update target for convenient updates and documented in help text

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/utils/version.sh Resolved
Comment thread lib/utils/version.sh Resolved
Comment thread lib/utils/version.sh
# Cache file for version check (avoid spamming GitHub API)
_get_version_cache_file() {
local cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/n8n-git"
mkdir -p "$cache_dir" 2>/dev/null || true

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache file creation uses 'mkdir -p' with output redirected to /dev/null and '|| true' to ignore failures. However, if the cache directory cannot be created (e.g., due to permissions), the function will silently continue and later fail when trying to write to the cache file. Consider adding explicit validation that the cache directory was created successfully, or at minimum log a warning when cache operations fail.

Suggested change
mkdir -p "$cache_dir" 2>/dev/null || true
# Best-effort cache directory creation; warn if unusable
if ! mkdir -p "$cache_dir" 2>/dev/null; then
if [ ! -d "$cache_dir" ] || [ ! -w "$cache_dir" ]; then
printf 'Warning: Failed to create or access cache directory "%s"; cache may not be writable.\n' "$cache_dir" >&2
fi
fi

Copilot uses AI. Check for mistakes.
Comment thread lib/utils/version.sh Resolved
Comment thread n8n-git.sh Outdated
for arg in "$@"; do
case "$arg" in
--dry-run) update_dry_run=true ;;
v*|[0-9]*) target_version="$arg" ;;

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument parsing for the update command uses a simplistic pattern match 'v*|[0-9]' which will match any argument starting with 'v' or a digit. This could incorrectly capture unrelated arguments as version numbers (e.g., '--verbose' would match the 'v' pattern). Consider using a more specific pattern like 'v[0-9].[0-9].[0-9]*' or validating the version format after capture.

Suggested change
v*|[0-9]*) target_version="$arg" ;;
v[0-9]*.[0-9]*.[0-9]*|[0-9]*.[0-9]*.[0-9]*) target_version="$arg" ;;

Copilot uses AI. Check for mistakes.
Comment thread lib/utils/version.sh
Comment on lines +150 to +178
show_update_notification() {
# Skip update check if explicitly disabled
if [[ "${N8N_GIT_DISABLE_UPDATE_CHECK:-}" == "true" ]]; then
return 0
fi

# Skip update check in non-interactive/CI environments
if [[ -n "${CI:-}" ]] || [[ -n "${GITHUB_ACTIONS:-}" ]]; then
return 0
fi

# Run check in background to avoid slowing down startup
# But if we already have cached data, show it immediately
local cache_file
cache_file="$(_get_version_cache_file)"

if [[ -f "$cache_file" ]]; then
check_for_updates
if [[ "$UPDATE_AVAILABLE" == "true" && -n "$LATEST_VERSION" ]]; then
echo ""
log INFO "${YELLOW}Update available:${NC} v${VERSION} -> v${LATEST_VERSION}"
log INFO "Run '${BOLD}n8n-git update${NC}' to install the latest version."
echo ""
fi
else
# Trigger background check for next time (don't block)
(check_for_updates &) 2>/dev/null || true
fi
}

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function relies on global variables UPDATE_AVAILABLE and LATEST_VERSION being set, but these are not initialized before use. If check_for_updates has never been called, these variables will be unset, potentially causing issues with string comparisons. Consider initializing these variables at the top of the script or within the function to ensure they always have a defined state.

Copilot uses AI. Check for mistakes.
Comment thread lib/utils/version.sh
Comment on lines +282 to +294
if ! check_for_updates; then
log ERROR "Failed to check for updates. Check your network connection."
return 1
fi

if [[ "$UPDATE_AVAILABLE" != "true" ]]; then
log SUCCESS "You are already running the latest version (v${VERSION})."
return 0
fi

source_ref="v${LATEST_VERSION}"
log INFO "Updating from v${VERSION} to v${LATEST_VERSION}..."
fi

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The perform_update function relies on global variables UPDATE_AVAILABLE and LATEST_VERSION being set by check_for_updates, but these are not initialized. If the network call fails or check_for_updates encounters an error, these variables may be unset when accessed on line 287, potentially causing incorrect behavior in the version comparison. Consider ensuring these variables are always initialized or add explicit checks for their existence.

Copilot uses AI. Check for mistakes.
Comment thread lib/utils/version.sh Outdated
fi
else
# Trigger background check for next time (don't block)
(check_for_updates &) 2>/dev/null || true

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The background process spawned with '(check_for_updates &)' may continue running even if the main process exits or encounters errors. While the function is designed to be non-blocking, there's no cleanup mechanism for this background job. Consider using 'disown' after backgrounding to properly detach the process, or ensure the background check completes quickly to avoid orphaned processes.

Suggested change
(check_for_updates &) 2>/dev/null || true
{ check_for_updates & disown; } 2>/dev/null || true

Copilot uses AI. Check for mistakes.
Comment thread lib/utils/version.sh
Comment on lines +277 to +321
if [[ -n "$target_version" ]]; then
source_ref="v${target_version#v}"
log INFO "Installing specific version: $source_ref"
else
# Get latest release version
if ! check_for_updates; then
log ERROR "Failed to check for updates. Check your network connection."
return 1
fi

if [[ "$UPDATE_AVAILABLE" != "true" ]]; then
log SUCCESS "You are already running the latest version (v${VERSION})."
return 0
fi

source_ref="v${LATEST_VERSION}"
log INFO "Updating from v${VERSION} to v${LATEST_VERSION}..."
fi

# Check write permissions
local needs_sudo=false
if [[ "$INSTALL_TYPE" == "system" ]]; then
if [[ ! -w "$INSTALL_BINDIR" ]] || [[ ! -w "$(dirname "$INSTALL_SHAREDIR")" ]]; then
needs_sudo=true
fi
fi

if [[ "$dry_run" == "true" ]]; then
log WARN "DRY RUN - Would perform the following:"
log INFO " Download: https://github.com/${N8N_GIT_REPO}/archive/refs/tags/${source_ref}.tar.gz"
log INFO " Install binary to: $INSTALL_BINDIR/n8n-git"
log INFO " Install libraries to: $INSTALL_SHAREDIR/lib"
if [[ "$needs_sudo" == "true" ]]; then
log INFO " (Would require sudo for system installation)"
fi
return 0
fi

# Create temporary directory
local workdir
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT

# Download the release
local archive_url="https://github.com/${N8N_GIT_REPO}/archive/refs/tags/${source_ref}.tar.gz"

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download URL is constructed using user-controllable input (target_version parameter) without proper validation. A malicious version string could potentially be crafted to manipulate the download URL. While the current pattern does strip the 'v' prefix, consider adding explicit validation that the version string matches expected semantic versioning format before constructing the URL to prevent potential security issues.

Copilot uses AI. Check for mistakes.
Comment thread lib/utils/version.sh
}

# Detect the installation type and paths
# Sets: INSTALL_TYPE (system|user|dev), INSTALL_BINDIR, INSTALL_SHAREDIR

Copilot AI Dec 31, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function sets global variables INSTALL_TYPE, INSTALL_BINDIR, and INSTALL_SHAREDIR but this is not documented in the function's comment header. The comment should explicitly state what global variables are set by this function and what values they can take.

Suggested change
# Sets: INSTALL_TYPE (system|user|dev), INSTALL_BINDIR, INSTALL_SHAREDIR
# Sets: INSTALL_TYPE (system|user|dev|unknown), INSTALL_BINDIR, INSTALL_SHAREDIR
# - INSTALL_TYPE: installation scope; "unknown" when detection fails
# - INSTALL_BINDIR: directory containing the n8n-git executable (may be empty with INSTALL_TYPE=unknown)
# - INSTALL_SHAREDIR: directory containing n8n-git shared data (may be empty with INSTALL_TYPE=unknown)

Copilot uses AI. Check for mistakes.
- Fix overly broad version pattern matching that could match --verbose
  Now uses stricter semver pattern: v[0-9]*.[0-9]*|[0-9]*.[0-9]*
- Initialize global variables UPDATE_AVAILABLE and LATEST_VERSION to
  prevent unset variable issues
- Add is_valid_version() function to validate version strings before
  URL construction (security improvement)
- Add disown for background process cleanup in update check
- Move update/version command handling before main argument parsing
  to properly handle update-specific arguments
- Add dedicated --help for update command with usage examples
@tcoretech
tcoretech merged commit 6a0e1ca into main Jan 5, 2026
5 checks passed
@tcoretech
tcoretech deleted the claude/add-version-check-update-5Chpr branch January 5, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants