-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupgrade-major-versions.sh
executable file
·68 lines (56 loc) · 2.3 KB
/
upgrade-major-versions.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# This script upgrades the versions of the IDEs in the build file, if the latest
# major version is larger than the one in build.gradle
# Returns the latest released version for the given JetBrains product code.
latestRelease() {
typeCode=$1
releaseType=$2
url="https://data.services.jetbrains.com/products?fields=code,releases.build,releases.type&code=${typeCode}"
curl -s "${url}" | jq "[.[0]|.releases|.[]|select(.type==\"${releaseType}\")|.build][0]" | tr -d '"'
}
# Returns the latest go plugin version from https://plugins.jetbrains.com/api/plugins/9568.
findLatestGoPluginVersion() {
majorVersion=$1
url="https://plugins.jetbrains.com/api/plugins/9568/updates?channel=&size=8"
curl -s "${url}" | jq "[.[]|select(.since|startswith(\"${majorVersion}\"))][0].version" | tr -d '"'
}
# Returns the latest IDE version used to build the plugin for the given IDE
currentVersion() {
typeCode=$1
releaseType=$2
grep "${typeCode}.${releaseType}.version" gradle.properties | sed "s/^.*=\(.*\)/\1/"
}
# Returns the major version for the given full version string
majorVersion() {
version=$1
echo "${version}" | sed "s/^\([^.]*\).*/\1/"
}
# Sets the version for the given product type in the build file
setVersion() {
typeCode=$1
version=$2
releaseType=$3
sed -i.bak "s/^${typeCode}\.${releaseType}\.version=.*$/${typeCode}.${releaseType}.version=${version}/g" gradle.properties
}
# Updates the version for given product type in the build file if the major version
# of the latest release differs
updateIfNeeded() {
typeCode=$1
releaseType=$2
latest=$(latestRelease "${typeCode}" "${releaseType}")
current=$(currentVersion "${typeCode}" "${releaseType}")
latestMajor=$(majorVersion "${latest}")
currentMajor=$(majorVersion "${current}")
if [ "$latestMajor" != "$currentMajor" ]; then
echo "Upgrading ${typeCode} (${releaseType}) to ${latest}"
setVersion "$typeCode" "$latest" "$releaseType"
goPluginVersion=$(findLatestGoPluginVersion "${latestMajor}")
sed -i.bak "s/^${typeCode}\.${releaseType}\.go_plugin\.version=.*$/${typeCode}.${releaseType}.go_plugin.version=${goPluginVersion}/g" gradle.properties
else
echo "No upgrade needed for ${typeCode} ${releaseType}"
fi
}
updateIfNeeded IIC release
updateIfNeeded IIC eap
updateIfNeeded GO release
updateIfNeeded GO eap