Skip to content

Commit ecebb6f

Browse files
[CI][CD] Update template to 2.0.0
1 parent 3b3666c commit ecebb6f

7 files changed

Lines changed: 76 additions & 28 deletions

File tree

.github/workflows/appRelease.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# MIT License
22
#
3-
# Copyright (c) 2021 Vilius Sutkus <ViliusSutkus89@gmail.com>
3+
# Copyright (c) 2021, 2022 Vilius Sutkus '89 <ViliusSutkus89@gmail.com>
44
#
55
# https://github.com/ViliusSutkus89/Sample_Android_Library-MavenCentral-Instrumented_Tests
6-
# .github/workflows/appRelease.yml - v1.3.0
6+
# .github/workflows/appRelease.yml - v2.0.0
77
#
88
# Permission is hereby granted, free of charge, to any person obtaining a copy
99
# of this software and associated documentation files (the "Software"), to deal
@@ -108,6 +108,16 @@ jobs:
108108
name: "[AppRelease] ${{ github.event.repository.name }} v${{ steps.version.outputs.appVersion }}"
109109
artifacts: "artifacts/APKs/**/*.apk,artifacts/application-lint-report.html/application-lint-report.html"
110110

111+
incrementAppVersion:
112+
needs: releaseApp
113+
permissions:
114+
contents: write
115+
runs-on: ubuntu-20.04
116+
steps:
117+
- uses: actions/checkout@v2
118+
with:
119+
ref: ${{ github.event.ref }}
120+
111121
- run: ./ci-scripts/incrementVersion --application
112122
id: postReleaseVersionIncrement
113123

.github/workflows/fullRelease.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# MIT License
22
#
3-
# Copyright (c) 2021 Vilius Sutkus <ViliusSutkus89@gmail.com>
3+
# Copyright (c) 2021, 2022 Vilius Sutkus '89 <ViliusSutkus89@gmail.com>
44
#
55
# https://github.com/ViliusSutkus89/Sample_Android_Library-MavenCentral-Instrumented_Tests
6-
# .github/workflows/fullRelease.yml - v1.3.0
6+
# .github/workflows/fullRelease.yml - v2.0.0
77
#
88
# Permission is hereby granted, free of charge, to any person obtaining a copy
99
# of this software and associated documentation files (the "Software"), to deal
@@ -148,3 +148,21 @@ jobs:
148148
omitBodyDuringUpdate: true
149149
allowUpdates: true
150150
artifacts: "application/app/build/outputs/apk/**/*.apk,application-lint-report.html"
151+
152+
incrementAppVersion:
153+
needs: buildApplication
154+
permissions:
155+
contents: write
156+
runs-on: ubuntu-20.04
157+
steps:
158+
- uses: actions/checkout@v2
159+
with:
160+
ref: ${{ github.event.ref }}
161+
162+
- run: ./ci-scripts/incrementVersion --application
163+
id: postReleaseVersionIncrement
164+
165+
- uses: stefanzweifel/git-auto-commit-action@v4
166+
with:
167+
commit_message: "Post release app version increment to ${{ steps.postReleaseVersionIncrement.outputs.newAppVersion }} (from ${{ steps.postReleaseVersionIncrement.outputs.oldAppVersion }})"
168+
file_pattern: ${{ steps.postReleaseVersionIncrement.outputs.files }}

.github/workflows/privilegedBuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2021 Vilius Sutkus <ViliusSutkus89@gmail.com>
44
#
55
# https://github.com/ViliusSutkus89/Sample_Android_Library-MavenCentral-Instrumented_Tests
6-
# .github/workflows/privilegedBuild.yml - v1.4.0
6+
# .github/workflows/privilegedBuild.yml - v2.0.0
77
#
88
# Permission is hereby granted, free of charge, to any person obtaining a copy
99
# of this software and associated documentation files (the "Software"), to deal

.github/workflows/unprivilegedBuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2021 Vilius Sutkus <ViliusSutkus89@gmail.com>
44
#
55
# https://github.com/ViliusSutkus89/Sample_Android_Library-MavenCentral-Instrumented_Tests
6-
# .github/workflows/unprivilegedBuild.yml - v1.4.0
6+
# .github/workflows/unprivilegedBuild.yml - v2.0.0
77
#
88
# Permission is hereby granted, free of charge, to any person obtaining a copy
99
# of this software and associated documentation files (the "Software"), to deal

ci-scripts/getVersion

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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/getVersion - v1.4.0
7+
# ci-scripts/getVersion - 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
@@ -32,9 +32,9 @@ use strict;
3232
use warnings;
3333

3434
use base 'Exporter';
35-
our $VERSION = '1.4.0';
35+
our $VERSION = '2.0.0';
3636
our @EXPORT = qw(getVersion);
37-
our @EXPORT_OK = qw(getVersionCode getAppVersion getAppVersionCode);
37+
our @EXPORT_OK = qw(getVersionCode getAppVersionCode getAppVersion getAppReleaseNumber);
3838

3939
use File::Basename 'dirname';
4040
use Getopt::Long;
@@ -69,11 +69,24 @@ sub getVersionCode {
6969
}
7070

7171
sub getAppVersion {
72-
my ($version) = fileParser::grepSingleLine(
72+
my ($appVersion) = fileParser::grepSingleLine(
7373
pathResolver::getAbsolutePath($rootDir . '/application/app/build.gradle'),
74-
qr/versionName\s+["']((\d+\.\d+\.\d+?)(.\d+?)*)["']$/
74+
qr/versionName\s+["'](\d+\.\d+\.\d+(?:\.\d+)?)["']$/
7575
);
76-
return $version;
76+
return $appVersion;
77+
}
78+
79+
sub getAppReleaseNumber {
80+
my ($appReleaseNumber) = fileParser::grepSingleLine(
81+
pathResolver::getAbsolutePath($rootDir . '/application/app/build.gradle'),
82+
qr/versionName\s+["']\d+\.\d+\.\d+(?:\.(\d+))?["']$/
83+
);
84+
# App Release Number may or may not be available
85+
# Default to 0 if not available (migrating from old format)
86+
if (!defined $appReleaseNumber) {
87+
$appReleaseNumber = 0;
88+
}
89+
return $appReleaseNumber;
7790
}
7891

7992
sub getAppVersionCode {

ci-scripts/incrementVersion

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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;
4040
use lib File::Basename::dirname(__FILE__) . '/lib';
4141
use fileUpdater;
4242
use getVersion;
43+
use List::Util qw(max);
4344

4445
sub 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();

ci-scripts/updateDownstreamVersion

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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/updateDownstreamVersions - v1.1.5
7+
# ci-scripts/updateDownstreamVersions - 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
@@ -45,6 +45,7 @@ die(File::Basename::basename(__FILE__) . " takes no arguments!\n") if (@ARGV);
4545

4646
my $version = getVersion::getVersion();
4747
my $versionCode = getVersion::getVersionCode();
48+
my $appReleaseNumber = getVersion::getAppReleaseNumber();
4849

4950
print "::set-output name=version::$version\n";
5051
print "::set-output name=versionCode::$versionCode\n";
@@ -58,16 +59,18 @@ $versionUpdater->update('README.md', sub {
5859
return $_;
5960
});
6061

62+
# Application is versioned as "LIBRARY_MAJOR.LIBRARY_MINOR.LIBRARY_PATCH.APPLICATION_RELEASE_NUMBER"
6163
$versionUpdater->update('application/app/build.gradle', sub {
6264
$_ = shift;
6365
# Update the version of library, which this sample application depends on.
6466
s/^(\s+implementation\s+['"]com\.viliussutkus89\:pdf2htmlex-android\:)[\d\.]+(['"])$/${1}${version}${2}/;
6567

66-
# Update versionName of sample application to be the same as the library, but with ".0" at the end.
67-
s/^(\s+versionName\s+['"])[\d\.]+(['"])$/${1}${version}.0${2}/;
68+
# Update versionName of sample application to reflect library version.
69+
s/^(\s+versionName\s+['"])[\d\.]+(['"])$/${1}${version}.${appReleaseNumber}${2}/;
6870

6971
# Update versionCode of sample application to be the same as the library.
7072
s/^(\s+versionCode\s+)\d+$/${1}${versionCode}/;
73+
7174
return $_;
7275
});
7376

0 commit comments

Comments
 (0)