This repository has been archived on 2026-11-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
qqq-orb/src/scripts/node_version_commit.sh
T
james.maes ab841b2ddd fix(node): handle empty CIRCLE_BRANCH in version commit
Aligned node_version_commit.sh with Maven equivalent: added feature
branch skip, empty branch fallback, and non-fatal push handling.
2026-01-30 11:10:57 -06:00

62 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
############################################################################
## node_version_commit.sh
## Node.js Version Commit Management Script
##
## This script handles committing version changes to Git for Node.js projects.
## It checks if the package.json file has been modified and commits the changes if needed.
## It also pushes the changes back to the current branch.
##
## Process:
## 1. Skips for feature branches (ephemeral versions)
## 2. Checks if package.json has been modified
## 3. Extracts the new version from package.json
## 4. Commits the changes with skip ci flag
## 5. Pushes changes to the current branch (non-fatal on failure)
##
## Usage: Called by node_manage_version command
## Output: Commits and pushes version changes if package.json was modified
############################################################################
set -e
################################################################
## Skip version commit for feature branches ##
## Feature versions are ephemeral and don't need to be ##
## persisted back to the repository ##
################################################################
if [[ "$BRANCH_TYPE" == "feature" ]]; then
echo "Skipping version commit for feature branch (ephemeral versions)"
exit 0
fi
################################################################
## Check if package.json was modified and commit if needed ##
################################################################
echo "Checking for package.json version changes"
if [[ -n "$(git status --porcelain package.json)" ]]; then
NEW_VERSION=$(grep '"version"' package.json | sed 's/.*"version": "//;s/".*//')
git add package.json
git commit -m "Bump version to $NEW_VERSION [skip ci]"
# Determine target branch
if [ -n "$CIRCLE_BRANCH" ]; then
TARGET_BRANCH="$CIRCLE_BRANCH"
else
TARGET_BRANCH="main"
fi
# Try to push, but don't fail the build if push fails
# This can happen if another build pushed first (race condition)
if git push origin "HEAD:${TARGET_BRANCH}"; then
echo "Version updated to: $NEW_VERSION and pushed to ${TARGET_BRANCH}"
else
echo "WARNING: Failed to push version commit to ${TARGET_BRANCH}"
echo "This is not fatal - version will be updated on next build"
echo "Common causes: concurrent builds, branch protection rules"
fi
else
echo "No version change needed"
fi