Debian Codegraph @

tools/bump_version.sh

raw symbols SCIP
1 #!/bin/sh
2 # Bump the version in multiple files such as CMakeLists.txt, AndroidManifest.xml
3 # If option "-c" is set, it will also regenerate the fastlane changelogs from the NEWS file.
4 # There is no check at all if the release already exists or if the values are correct.
5 #
6 # SPDX-FileCopyrightText: 2023 Johnny Jazeix <[email protected]>
7 #
8 # SPDX-License-Identifier: GPL-3.0-or-later
9
10 function usage() {
11 echo "Usage: ./tools/bump_version.sh -v <version> [-h]"
12 echo " -v, --version <version> contains the new version <major>.<minor>.<patch>"
13 echo " -c, --changelog generate fastlane changelog from NEWS (optional)"
14 echo " -h, --help displays this help"
15 }
16
17 if [ ! -f io.github.petitlapin.Li-ri.appdata.xml ]
18 then
19 echo "ERROR: Run me from the top level source dir"
20 exit 1
21 fi
22
23 while [[ $# -gt 0 ]]; do
24 case $1 in
25 -v|--version)
26 VERSION="$2"
27 shift # past argument
28 shift # past value
29 ;;
30 -c|--changelog)
31 CHANGELOG="1"
32 shift # past argument
33 ;;
34 -h|--help)
35 usage;
36 exit 0
37 ;;
38 -*|--*)
39 echo "Unknown option $1"
40 exit 1
41 ;;
42 *)
43 POSITIONAL_ARGS+=("$1") # save positional arg
44 shift # past argument
45 ;;
46 esac
47 done
48
49 if [[ ! "${VERSION}" ]]
50 then
51 echo "Mission version"
52 usage
53 exit 1
54 fi
55
56 major=`echo $VERSION | cut -d. -f1`
57 minor=`echo $VERSION | cut -d. -f2`
58 patch=`echo $VERSION | cut -d. -f3`
59
60 version=${major}.${minor}.${patch}
61 echo "Version = $version"
62
63 # Update CMakeLists LIRI_VERSION_MAJOR and LIRI_VERSION_MINOR variables
64 sed -i "s/set(LIRI_VERSION_MAJOR [0-9]\+)$/set\(LIRI_VERSION_MAJOR $major\)/" CMakeLists.txt
65 sed -i "s/set(LIRI_VERSION_MINOR [0-9]\+)$/set\(LIRI_VERSION_MINOR $minor\)/" CMakeLists.txt
66 sed -i "s/set(LIRI_VERSION_PATCH [0-9]\+)$/set\(LIRI_VERSION_PATCH $patch\)/" CMakeLists.txt
67
68 # Update AndroidManifest.xml
69 versioncode=$((${major}*10000 + ${minor}*100 + ${patch}))
70 sed -i "s/android:versionCode=\"[0-9]\+\"$/android:versionCode=\"$versioncode\"/" android/app/src/main/AndroidManifest.xml
71 sed -i "s/android:versionName=\"[0-9.]\+\"$/android:versionName=\"$version\"/" android/app/src/main/AndroidManifest.xml
72
73 sed -i "s/Li-ri V[0-9.]\+/Li-ri V$version/" src/main.cc
74
75 git add CMakeLists.txt android/app/src/main/AndroidManifest.xml src/main.cc && git commit -m "bump version to ${major}.${minor}.${patch}"
76
77 if [[ "${CHANGELOG}" ]]
78 then
79 appstreamcli news-to-metainfo ./NEWS.yaml ./io.github.petitlapin.Li-ri.appdata.xml
80 python tools/fdroid_create_fastlane_changelogs.py
81
82 git add fastlane/metadata/android/en-US/changelogs/ io.github.petitlapin.Li-ri.appdata.xml && git commit -m "update changelog for ${major}.${minor}.${patch}"
83 fi