-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pre-commit
More file actions
36 lines (27 loc) · 976 Bytes
/
.pre-commit
File metadata and controls
36 lines (27 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Path to composer.json
COMPOSER_FILE="composer.json"
# Check if composer.json exists
if [ ! -f "$COMPOSER_FILE" ]; then
echo "$COMPOSER_FILE not found!"
exit 1
fi
# Use jq to bump the patch version
if command -v jq &> /dev/null; then
# Read the current version
CURRENT_VERSION=$(jq -r '.version' "$COMPOSER_FILE")
# Split the version into an array
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Increment the patch version
NEW_PATCH=$((PATCH + 1))
# Create the new version string
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
# Update the composer.json file
jq --arg new_version "$NEW_VERSION" '.version = $new_version' "$COMPOSER_FILE" > tmp.$.json && mv tmp.$.json "$COMPOSER_FILE"
echo "Bumped version from $CURRENT_VERSION to $NEW_VERSION"
# Stage the changes to package.json
git add composer.json
else
echo "jq is not installed. Please install jq to use this hook."
exit 1
fi