forked from chkfung/android-version-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (71 loc) · 3.76 KB
/
index.js
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
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
// versionCode — A positive integer [...] -> https://developer.android.com/studio/publish/versioning
const versionCodeRegexPattern = /(versionCode(?:\s|=)*)(.*)/;
// versionName — A string used as the version number shown to users [...] -> https://developer.android.com/studio/publish/versioning
const versionNameRegexPattern = /(versionName(?:\s|=)*)(.*)/;
const applicationIdRegexPattern = /(applicationId(?:\s|=)*)(.*)/;
const keystoreAliasRegexPattern = /(keyAlias(?:\s|=)*)(.*)/;
const keystorePasswordRegexPattern = /(storePassword(?:\s|=)*)(.*)/;
const keystoreAliasPasswordRegexPattern = /(keyPassword(?:\s|=)*)(.*)/;
try {
const gradlePath = core.getInput('gradlePath');
let versionCode = core.getInput('versionCode');
let versionName = core.getInput('versionName');
const applicationId = core.getInput('applicationId');
const keystoreAlias = core.getInput('keystoreAlias');
const keystorePassword = core.getInput('keystorePassword');
const keystoreAliasPassword = core.getInput('keystoreAliasPassword');
console.log(`Gradle Path : ${gradlePath}`);
console.log(`Version Code : ${versionCode}`);
console.log(`Version Name : ${versionName}`);
console.log(`Application Id : ${applicationId}`);
console.log(`Keystore Alias : ${keystoreAlias}`);
console.log(`Keystore Password : ${keystorePassword}`);
console.log(`Keystore Alias Password : ${keystoreAliasPassword}`);
fs.readFile(gradlePath, 'utf8', function (err, data) {
newGradle = data;
if (versionCode.length > 0)
newGradle = newGradle.replace(versionCodeRegexPattern, `$1${versionCode}`);
else
{
const found = newGradle.match(versionCodeRegexPattern);
versionCode = found[2];
}
if (versionName.length > 0)
newGradle = newGradle.replace(versionNameRegexPattern, `$1\"${versionName}\"`);
else
{
const found = newGradle.match(versionNameRegexPattern);
versionName = found[2].replaceAll("\"", "");
}
if (applicationId.length > 0)
newGradle = newGradle.replace(applicationIdRegexPattern, `$1\"${applicationId}\"`);
if (keystoreAlias.length > 0)
newGradle = newGradle.replace(keystoreAliasRegexPattern, `$1\"${keystoreAlias}\"`);
if (keystorePassword.length > 0)
newGradle = newGradle.replace(keystorePasswordRegexPattern, `$1\"${keystorePassword}\"`);
if (keystoreAliasPassword.length > 0)
newGradle = newGradle.replace(keystoreAliasPasswordRegexPattern, `$1\"${keystoreAliasPassword}\"`);
fs.writeFile(gradlePath, newGradle, function (err) {
if (err) throw err;
if (versionCode.length > 0)
console.log(`Successfully override version code ${versionCode}`)
if (versionName.length > 0)
console.log(`Successfully override version name ${versionName}`)
if (applicationId.length > 0)
console.log(`Successfully override application id ${applicationId}`)
if (keystoreAlias.length > 0)
console.log(`Successfully override keystore alias ${keystoreAlias}`)
if (keystorePassword.length > 0)
console.log(`Successfully override keystore password ${keystorePassword}`)
if (keystoreAliasPassword.length > 0)
console.log(`Successfully override keystore alias password ${keystoreAliasPassword}`)
core.setOutput("result", `Done`);
core.exportVariable("FULL_VERSION_NAME", `v${versionName}(${versionCode})`);
});
});
} catch (error) {
core.setFailed(error.message);
}