Skip to content

Commit c797e8d

Browse files
committed
fix(hooks): Update pre-push hook to commit version bumps and request re-push
1 parent 76d20a2 commit c797e8d

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

.github/hooks/pre-push

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,42 @@ fi
156156
# Auto-update version if enabled
157157
if [[ "$AUTO_UPDATE" == "true" ]]; then
158158
if [[ -f "$VERSION_FILE" && -f "$BUMP_SCRIPT" ]]; then
159-
log_info "Auto-updating VERSION to $BUMP_TYPE bump..."
160159

161-
# Run bump-version with detected bump type
162-
if "$BUMP_SCRIPT" "$BUMP_TYPE" > /dev/null 2>&1; then
163-
log_success "Updated VERSION and CHANGELOG.md"
164-
165-
# Stage the updated files
166-
git add "$VERSION_FILE" "$CHANGELOG_FILE" package.json 2>/dev/null || true
167-
log_info "Staged version updates for push"
160+
# Check if we've already bumped the version in the latest commit to avoid infinite loop
161+
# If the last commit message starts with "chore: release", we assume it's our auto-bump
162+
last_msg=$(git log -1 --pretty=%B)
163+
if [[ "$last_msg" == chore:\ release\ v* ]]; then
164+
log_info "Version bump already committed. Proceeding with push."
168165
else
169-
log_error "Failed to update VERSION"
170-
exit 1
166+
log_info "Auto-updating VERSION to $BUMP_TYPE bump..."
167+
168+
# Run bump-version with detected bump type
169+
# Capture output to get the new version number
170+
BUMP_OUTPUT=$("$BUMP_SCRIPT" "$BUMP_TYPE")
171+
EXIT_CODE=$?
172+
173+
if [[ $EXIT_CODE -eq 0 ]]; then
174+
# Extract new version (simple grep from the output or read file)
175+
NEW_VERSION=$(head -n 1 "$VERSION_FILE")
176+
177+
log_success "Updated VERSION to v${NEW_VERSION}"
178+
179+
# Commit the version bump
180+
git add "$VERSION_FILE" "$CHANGELOG_FILE" package.json 2>/dev/null || true
181+
git commit -m "chore: release v${NEW_VERSION} [skip ci]" --no-verify >/dev/null 2>&1
182+
183+
log_warn "---------------------------------------------------------"
184+
log_warn "🚀 Version bumped and committed: v${NEW_VERSION}"
185+
log_warn "---------------------------------------------------------"
186+
log_info "The push was intercepted to include the version update."
187+
log_info "Please run 'git push' again used to publish this release."
188+
log_warn "---------------------------------------------------------"
189+
190+
exit 1 # Intentionally fail push to let user re-push with new commit
191+
else
192+
log_error "Failed to update VERSION"
193+
exit 1
194+
fi
171195
fi
172196
fi
173197
fi

0 commit comments

Comments
 (0)