File indexing completed on 2024-04-28 15:08:12

0001 #!/bin/sh
0002 # Bump the version in multiple files such as CMakeLists.txt
0003 # If option "-r <date>" is set, it will also update the publiccode.yml, org.kde.gcompris.appdata.xml and docs/docbook/index.docbook files.
0004 # There is no check at all if the release already exists or if the values are correct.
0005 #
0006 # SPDX-FileCopyrightText: 2023 Johnny Jazeix <jazeix@gmail.com>
0007 #
0008 #   SPDX-License-Identifier: GPL-3.0-or-later
0009 
0010 function usage() {
0011     echo "Usage: ./tools/bump_version.sh -v <version> [-r <date>] [-h]"
0012     echo "  -v, --version <version>   contains the new version <major>.<minor>"
0013     echo "  -r, --release <date>      contains the date of the release YYYY-MM-DD (optional)"
0014     echo "  -h, --help                displays this help"
0015 }
0016 
0017 if [ ! -f org.kde.gcompris.appdata.xml ]
0018 then
0019     echo "ERROR: Run me from the top level GCompris source dir"
0020     exit 1
0021 fi
0022 
0023 while [[ $# -gt 0 ]]; do
0024   case $1 in
0025     -v|--version)
0026       VERSION="$2"
0027       shift # past argument
0028       shift # past value
0029       ;;
0030     -r|--release)
0031       DATE="$2"
0032       shift # past argument
0033       shift # past value
0034       ;;
0035     -h|--help)
0036         usage;
0037         exit 0
0038       ;;
0039     -*|--*)
0040       echo "Unknown option $1"
0041       exit 1
0042       ;;
0043     *)
0044       POSITIONAL_ARGS+=("$1") # save positional arg
0045       shift # past argument
0046       ;;
0047   esac
0048 done
0049 
0050 if [[ ! "${VERSION}" ]]
0051 then
0052     echo "Mission version"
0053     usage
0054     exit 1
0055 fi
0056 
0057 major=`echo $VERSION | cut -d. -f1`
0058 minor=`echo $VERSION | cut -d. -f2`
0059 
0060 echo "Version  = ${major}.${minor}"
0061 echo "Date     = ${DATE}"
0062 
0063 # Update CMakeLists GCOMPRIS_MAJOR_VERSION and GCOMPRIS_MINOR_VERSION variables
0064 sed -i "s/set(GCOMPRIS_MAJOR_VERSION [0-9]\+)$/set\(GCOMPRIS_MAJOR_VERSION $major\)/" CMakeLists.txt
0065 sed -i "s/set(GCOMPRIS_MINOR_VERSION [0-9]\+)$/set\(GCOMPRIS_MINOR_VERSION $minor\)/" CMakeLists.txt
0066 
0067 git add CMakeLists.txt && git commit -m "core, bump version to ${major}.${minor}"
0068 
0069 if [[ "${DATE}" ]]
0070 then
0071     # Update publiccode.yml with the new date and release
0072     sed -i "s/releaseDate: '[0-9\-]\+'/releaseDate: '$DATE'/" publiccode.yml
0073     sed -i "s/softwareVersion: '[0-9\.]\+'/softwareVersion: '${major}.${minor}'/" publiccode.yml
0074     git add publiccode.yml && git commit -m "publiccode, add ${major}.${minor} release"
0075     # Add a new release in org.kde.gcompris.appdata.xml with the new date and release
0076     sed -i -e "/<releases>/a\ \ \ \ <release version=\"${major}.${minor}\" date=\"$DATE\"/>" org.kde.gcompris.appdata.xml
0077     git add org.kde.gcompris.appdata.xml && git commit -m "appdata, add ${major}.${minor} release"
0078 
0079     # Update docs/docbook/index.docbook
0080     sed -i "s=<date>[0-9\-]\+</date>=<date>$DATE</date>=" docs/docbook/index.docbook
0081     sed -i "s=<releaseinfo>[0-9\.]\+</releaseinfo>=<releaseinfo>${major}.${minor}</releaseinfo>=" docs/docbook/index.docbook
0082     git add docs/docbook/index.docbook && git commit -m "docs, bump version to ${major}.${minor}"
0083 fi