11# !/usr/bin/env perl
22# MIT License
33#
4- # Copyright (c) 2021 Vilius Sutkus <ViliusSutkus89@gmail.com>
4+ # Copyright (c) 2021, 2022 Vilius Sutkus '89 <ViliusSutkus89@gmail.com>
55#
66# https://github.com/ViliusSutkus89/Sample_Android_Library-MavenCentral-Instrumented_Tests
7- # ci-scripts/incrementVersion - v1.3 .0
7+ # ci-scripts/incrementVersion - v2.0 .0
88#
99# Permission is hereby granted, free of charge, to any person obtaining a copy
1010# of this software and associated documentation files (the "Software"), to deal
@@ -40,6 +40,7 @@ use Getopt::Long;
4040use lib File::Basename::dirname(__FILE__ ) . ' /lib' ;
4141use fileUpdater;
4242use getVersion;
43+ use List::Util qw( max) ;
4344
4445sub usage {
4546 my $bn = File::Basename::basename(__FILE__ );
@@ -81,17 +82,17 @@ if (defined $application) {
8182 usage if (@ARGV );
8283
8384 # oldAppVersion could be either new format:
84- # "LIBRARY_MAJOR.LIBRARY_MINOR.LIBRARY_PATCH.APPLICATION_BUILD_NUMBER "
85+ # "LIBRARY_MAJOR.LIBRARY_MINOR.LIBRARY_PATCH.APPLICATION_RELEASE_NUMBER "
8586 # or old format:
8687 # "LIBRARY_MAJOR.LIBRARY_MINOR.LIBRARY_PATCH"
87- my ($major , $minor , $patch_ , $buildNumber ) = $oldAppVersion =~ / (\d +)\. (\d +)\. (\d +)\. ?(\d +)?/ ;
88- if (!defined $buildNumber ) {
88+ my ($major , $minor , $patch_ , $appReleaseNumber ) = $oldAppVersion =~ / (\d +)\. (\d +)\. (\d +)\. ?(\d +)?/ ;
89+ if (!defined $appReleaseNumber ) {
8990 # Converting from old to new app version format
90- $buildNumber = 0;
91+ $appReleaseNumber = 0;
9192 }
92- $buildNumber = $buildNumber + 1;
93+ $appReleaseNumber = $appReleaseNumber + 1;
9394
94- $newAppVersion = " ${major} .${minor} .${patch_} .${buildNumber } " ;
95+ $newAppVersion = " ${major} .${minor} .${patch_} .${appReleaseNumber } " ;
9596 $newAppVersionCode = $oldAppVersionCode + 1;
9697
9798 $versionIncrementer -> update(' application/app/build.gradle' , sub {
@@ -107,21 +108,24 @@ if (defined $application) {
107108 print " ::set-output name=newAppVersionCode::$newAppVersionCode \n " ;
108109 print " ::set-output name=files::application/app/build.gradle\n " ;
109110} else {
111+ # Both app and library versionCode need to be incremental
112+ my $vCode = max($oldVersionCode , $oldAppVersionCode );
113+
110114 my ($major , $minor , $patch_ ) = $oldVersion =~ / (\d +)\. (\d +)\. (\d +)/ ;
111115 if (defined $upMajor ) {
112116 $major = $major + 1;
113117 $newVersion = " ${major} .0.0" ;
114- $newVersionCode = $oldVersionCode + 10000;
118+ $newVersionCode = $vCode + 10000;
115119 }
116120 elsif (defined $upMinor ) {
117121 $minor = $minor + 1;
118122 $newVersion = " ${major} .${minor} .0" ;
119- $newVersionCode = $oldVersionCode + 1000;
123+ $newVersionCode = $vCode + 1000;
120124 }
121125 elsif (defined $upPatch ) {
122126 $patch_ = $patch_ + 1;
123127 $newVersion = " ${major} .${minor} .${patch_} " ;
124- $newVersionCode = $oldVersionCode + 100;
128+ $newVersionCode = $vCode + 100;
125129 }
126130 else {
127131 $newVersion = shift or usage();
0 commit comments