-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathincrementVersion
More file actions
executable file
·153 lines (138 loc) · 6.52 KB
/
incrementVersion
File metadata and controls
executable file
·153 lines (138 loc) · 6.52 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env perl
# MIT License
#
# Copyright (c) 2021, 2022 Vilius Sutkus '89 <[email protected]>
#
# https://github.com/ViliusSutkus89/Sample_Android_Library-MavenCentral-Instrumented_Tests
# ci-scripts/incrementVersion - v2.0.0
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
###########################################################################################
### The Purpose ### The Purpose ### The Purpose ### The Purpose ### The Purpose ### The ###
###########################################################################################
# The purpose of this script is to increment project version in library files.
###########################################################################################
### ~The Purpose~ # ~The Purpose~ # ~The Purpose~ # ~The Purpose~ # ~The Purpose~ # ~The~ #
###########################################################################################
use warnings;
use strict;
use File::Basename;
use Getopt::Long;
use lib File::Basename::dirname(__FILE__) . '/lib';
use fileUpdater;
use getVersion;
use List::Util qw(max);
sub usage {
my $bn = File::Basename::basename(__FILE__);
print STDERR "./$bn --major | --minor | --patch\n";
print STDERR "\t--major to increment major number, set minor and patch numbers to zero and increment versionCode by 100.\n";
print STDERR "\t--minor to increment minor number, set patch to zero and increment versionCode by 10.\n";
print STDERR "\t--patch to increment patch number and increment versionCode by 1.\n";
print STDERR "\n";
print STDERR "./$bn requestedVersion requestedVersionCode\n";
print STDERR "\t to set a specific version and versionCode, for example \"./$bn 0.4.2 55\".\n";
print STDERR "\n";
print STDERR "./$bn --application";
print STDERR "\t to increment application's version (build number).\n";
exit 1;
}
# $oldVersion, $oldVersionCode - pre increment, possibly released
# $newVersion, $newVersionCode - post increment, to be used for upcoming dev builds
my $oldVersion = getVersion::getVersion();
my $oldVersionCode = getVersion::getVersionCode();
my $oldAppVersion = getVersion::getAppVersion();
my $oldAppVersionCode = getVersion::getAppVersionCode();
my ($newVersion, $newVersionCode, $newAppVersion, $newAppVersionCode);
my ($upMajor, $upMinor, $upPatch, $application, $help);
Getopt::Long::GetOptions(major => \$upMajor, minor => \$upMinor, patch => \$upPatch, application => \$application, 'help' => \$help) or usage;
if (defined $help) {
usage();
}
my $rootDirectory = File::Basename::dirname(pathResolver::getAbsolutePath(File::Basename::dirname(__FILE__)));
my $versionIncrementer = fileUpdater->new({ rootDirectory => $rootDirectory });
if (defined $application) {
if (defined $upMajor || defined $upMinor || defined $upPatch) {
print STDERR "--application cannot be used with --major, --minor or --patch arguments!\n";
exit 1
}
usage if (@ARGV);
# oldAppVersion could be either new format:
# "LIBRARY_MAJOR.LIBRARY_MINOR.LIBRARY_PATCH.APPLICATION_RELEASE_NUMBER"
# or old format:
# "LIBRARY_MAJOR.LIBRARY_MINOR.LIBRARY_PATCH"
my ($major, $minor, $patch_, $appReleaseNumber) = $oldAppVersion =~ /(\d+)\.(\d+)\.(\d+)\.?(\d+)?/;
if (!defined $appReleaseNumber) {
# Converting from old to new app version format
$appReleaseNumber = 0;
}
$appReleaseNumber = $appReleaseNumber + 1;
$newAppVersion = "${major}.${minor}.${patch_}.${appReleaseNumber}";
$newAppVersionCode = $oldAppVersionCode + 1;
$versionIncrementer->update('sampleapp/app/build.gradle', sub {
$_ = shift;
s/^(\s+versionName\s+["'])${oldAppVersion}(["'])/${1}${newAppVersion}${2}/;
s/^(\s+versionCode\s+)${oldAppVersionCode}$/${1}${newAppVersionCode}/;
return $_;
});
print "::set-output name=oldAppVersion::$oldAppVersion\n";
print "::set-output name=oldAppVersionCode::$oldAppVersionCode\n";
print "::set-output name=newAppVersion::$newAppVersion\n";
print "::set-output name=newAppVersionCode::$newAppVersionCode\n";
print "::set-output name=files::sampleapp/app/build.gradle\n";
} else {
# Both app and library versionCode need to be incremental
my $vCode = max($oldVersionCode, $oldAppVersionCode);
my ($major, $minor, $patch_) = $oldVersion =~ /(\d+)\.(\d+)\.(\d+)/;
if (defined $upMajor) {
$major = $major + 1;
$newVersion = "${major}.0.0";
$newVersionCode = $vCode + 10000;
}
elsif (defined $upMinor) {
$minor = $minor + 1;
$newVersion = "${major}.${minor}.0";
$newVersionCode = $vCode + 1000;
}
elsif (defined $upPatch) {
$patch_ = $patch_ + 1;
$newVersion = "${major}.${minor}.${patch_}";
$newVersionCode = $vCode + 100;
}
else {
$newVersion = shift or usage();
$newVersionCode = shift or usage();
}
usage if (@ARGV);
$versionIncrementer->update('build.gradle', sub {
$_ = shift;
s/^(version\s*=\s*['"])${oldVersion}(['"])$/${1}${newVersion}$2/;
return $_;
});
$versionIncrementer->update('lib/build.gradle', sub {
$_ = shift;
s/^(\s+versionCode\s+)${oldVersionCode}$/${1}${newVersionCode}/;
return $_;
});
print "::set-output name=oldVersion::$oldVersion\n";
print "::set-output name=oldVersionCode::$oldVersionCode\n";
print "::set-output name=newVersion::$newVersion\n";
print "::set-output name=newVersionCode::$newVersionCode\n";
print "::set-output name=files::build.gradle lib/build.gradle\n";
}