1#!/bin/bash
2
3set -eu
4set -o pipefail
5
6function set_cmake_version {
7    sed -i "s/\(set(PROJECT_VERSION \"\).*\")/\1${1}\")/g" CMakeLists.txt
8}
9
10# We always start the beta branching from master.
11git checkout master
12
13# Something like: kdisplay@5.XX.0-beta.0
14LAST_TAG=$(git describe --abbrev=0)
15LAST_BETA_VERSION=$(echo $LAST_TAG | sed -e 's,kdisplay@\(\),\1,g')
16
17echo "Last beta version was: $LAST_BETA_VERSION"
18
19# This updates version number from beta to its release
20NEXT_VERSION=$(semver -i minor $LAST_BETA_VERSION)
21# Needs to be done a second time to get the next minor version.
22NEXT_VERSION=$(semver -i minor $NEXT_VERSION)
23
24# The next tag is suffixed according to SemVer.
25BETA_VERSION="${NEXT_VERSION}-beta.0"
26
27# The CMake project version needs the *90 hack since CMake does not support SemVer.
28CMAKE_VERSION=$(semver -i patch $LAST_BETA_VERSION)
29CMAKE_VERSION=$(echo $CMAKE_VERSION | sed -e 's,\w$,90,g')
30
31echo "Next beta version: '${BETA_VERSION}' Corresponding CMake project version: '${CMAKE_VERSION}'"
32
33# This creates the changelog.
34standard-version -t kdisplay\@ --skip.commit true --skip.tag true --preMajor --release-as $BETA_VERSION
35
36# Set CMake version.
37set_cmake_version $CMAKE_VERSION
38
39# Now we have all changes ready.
40git add CMakeLists.txt CHANGELOG.md
41
42# Commit and tag it.
43git commit -m "build: create beta release ${BETA_VERSION}" -m "Update changelog and raise CMake project version to ${CMAKE_VERSION}."
44git tag -a "kdisplay@${BETA_VERSION}" -m "Create beta release ${BETA_VERSION}."
45
46# Now checkout the next stable branch.
47BRANCH_NAME="Plasma/$(echo $NEXT_VERSION | sed -e 's,^\(\w*\.\w*\)\..*,\1,g')"
48echo "New stable branch name: $BRANCH_NAME"
49git checkout -b $BRANCH_NAME
50
51# Go back to master branch and update version to next release.
52git checkout master
53MASTER_CMAKE_VERSION=$(semver -i minor $CMAKE_VERSION)
54MASTER_CMAKE_VERSION=$(echo $MASTER_CMAKE_VERSION | sed -e 's,\w$,80,g')
55
56
57# Set CMake version
58set_cmake_version $MASTER_CMAKE_VERSION
59
60# And commit the updated version.
61git add CMakeLists.txt
62git commit -m "build: raise CMake project version to ${MASTER_CMAKE_VERSION}" -m "For development on master branch."
63
64echo "Changes applied. Check integrity of master and $BRANCH_NAME branches. Then issue 'git push --follow-tags' on both."
65