|
4 | 4 | ## Usage: next
|
5 | 5 | ## Example: "ddev next, ddev next patch, ddev next minor, ddev next major"
|
6 | 6 |
|
7 |
| -INCREASE_PATCH="patch" |
8 |
| -INCREASE_MINOR="minor" |
9 |
| -INCREASE_MAJOR="major" |
| 7 | +DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) |
10 | 8 |
|
11 |
| -versionType=${1:-$INCREASE_PATCH} |
| 9 | +# Ensure DEFAULT_BRANCH is set |
| 10 | +if [ -z "$DEFAULT_BRANCH" ]; then |
| 11 | + echo "Error: DEFAULT_BRANCH could not be determined." |
| 12 | + exit 1 |
| 13 | +fi |
12 | 14 |
|
13 |
| -IFS='.' read -ra lastTagParts <<< "$(git tag -l --sort=v:refname | tail -1)" |
| 15 | +# Check if on '${DEFAULT_BRANCH}' branch |
| 16 | +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 17 | +if [ "$CURRENT_BRANCH" != "$DEFAULT_BRANCH" ]; then |
| 18 | + echo "You are on branch '$CURRENT_BRANCH'. Before tagging please switch to the '$DEFAULT_BRANCH' branch and make sure it's up to date by running 'git pull'. Then run 'ddev next' command again." |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +# Fetch the latest state of the remote branch |
| 23 | +if ! git fetch -q origin $DEFAULT_BRANCH; then |
| 24 | + echo "Error: Failed to fetch from origin. Please check your network connection and remote repository configuration." |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +# Check if the local branch is behind the remote branch |
| 29 | +LOCAL=$(git rev-parse @) |
| 30 | +REMOTE=$(git rev-parse @{u}) |
| 31 | +BASE=$(git merge-base @ @{u}) |
| 32 | + |
| 33 | +if [ "$LOCAL" != "$REMOTE" ]; then |
| 34 | + if [ "$LOCAL" == "$BASE" ]; then |
| 35 | + echo "Your local '$DEFAULT_BRANCH' branch is behind the remote. Please update it with 'git pull' and run 'ddev next' command again." |
| 36 | + exit 1 |
| 37 | + elif [ "$REMOTE" == "$BASE" ]; then |
| 38 | + echo "Your local '$DEFAULT_BRANCH' branch has commits that are not pushed to the remote. Please push your changes with 'git push' and run 'ddev next' command again." |
| 39 | + exit 1 |
| 40 | + else |
| 41 | + echo "Your local '$DEFAULT_BRANCH' branch has diverged from the remote. Please resolve the divergence before proceeding." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +fi |
| 45 | + |
| 46 | + |
| 47 | +versionType=${1:-patch} |
| 48 | +if [ ! -z "$versionType" ]; then |
| 49 | + if [ "$versionType" != "patch" ] && [ "$versionType" != "minor" ] && [ "$versionType" != "major" ]; then |
| 50 | + echo "Error: Invalid argument. Please use 'patch', 'minor', or 'major'." |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +fi |
| 54 | + |
| 55 | +# Validate and increment version |
| 56 | +lastTag=$(git tag -l --sort=v:refname | tail -1) |
| 57 | +if ! [[ $lastTag =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 58 | + echo "Error: Last tag '$lastTag' does not follow semantic versioning." |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +IFS='.' read -ra lastTagParts <<< "$lastTag" |
14 | 63 | major=${lastTagParts[0]}
|
15 | 64 | minor=${lastTagParts[1]}
|
16 | 65 | patch=${lastTagParts[2]}
|
17 | 66 |
|
18 | 67 | case $versionType in
|
19 |
| - $INCREASE_MINOR) |
| 68 | + major) |
| 69 | + ((major++)) |
| 70 | + minor=0 |
20 | 71 | patch=0
|
21 |
| - minor=$((minor+1)) |
22 | 72 | ;;
|
23 |
| - $INCREASE_MAJOR) |
| 73 | + minor) |
| 74 | + ((minor++)) |
24 | 75 | patch=0
|
25 |
| - minor=0 |
26 |
| - major=$((major+1)) |
27 | 76 | ;;
|
28 |
| - $INCREASE_PATCH) |
29 |
| - patch=$((patch+1)) |
| 77 | + patch) |
| 78 | + ((patch++)) |
30 | 79 | ;;
|
31 | 80 | esac
|
32 | 81 |
|
33 |
| -nextTag="$major.$minor.$patch" |
| 82 | +NEXT_TAG="$major.$minor.$patch" |
34 | 83 |
|
35 |
| -sed -i "s/'version' => '[0-9]\+\.[0-9]\+\.[0-9]\+'/'version' => '$nextTag'/g" ./ext_emconf.php |
| 84 | +if git rev-parse "$NEXT_TAG" >/dev/null 2>&1; then |
| 85 | + echo "Error: Tag '$NEXT_TAG' already exists. Please check the current version." |
| 86 | + exit 1 |
| 87 | +fi |
36 | 88 |
|
37 |
| -sed -i "s/release=\"[0-9]\+\.[0-9]\+\.[0-9]\+\"/release=\"$nextTag\"/g" ./Documentation/guides.xml |
38 |
| -sed -i'' -E "s/(<project[^>]* version=\")[^\"]+(\")/\1$nextTag\2/" ./Documentation/guides.xml |
| 89 | +# Update files with the new version |
| 90 | +sed -i "s/'version' => '[0-9]\+\.[0-9]\+\.[0-9]\+'/'version' => '$NEXT_TAG'/g" ./ext_emconf.php |
| 91 | +sed -i "s/release=\"[0-9]\+\.[0-9]\+\.[0-9]\+\"/release=\"$NEXT_TAG\"/g" ./Documentation/guides.xml |
| 92 | +sed -i'' -E "s/(<project[^>]* version=\")[^\"]+(\")/\1$NEXT_TAG\2/" ./Documentation/guides.xml |
39 | 93 |
|
40 |
| -default_branch=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) |
41 |
| -echo "git add Documentation/guides.xml ext_emconf.php && git commit -m 'Tag new version' && git tag -a '$nextTag' -m '$nextTag' -s && git push origin $default_branch --tags" |
| 94 | +# Prepare command to tag the new version |
| 95 | +echo "Copy the command below and run it to tag the new version:" |
| 96 | +echo "git add Documentation/guides.xml ext_emconf.php && git commit -m 'Tag version $NEXT_TAG' && git tag -a '$NEXT_TAG' -m 'Version $NEXT_TAG' -s && git push origin $DEFAULT_BRANCH --tags" |
0 commit comments