Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve androidVersionCode parsing and application #297

Merged
merged 1 commit into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -15,7 +15,12 @@ public static void SetVersion(string version)
}

public static void SetAndroidVersionCode(string androidVersionCode) {
PlayerSettings.Android.bundleVersionCode = Int32.Parse(androidVersionCode);
int bundleVersionCode = Int32.Parse(androidVersionCode);
if (bundleVersionCode <= 0) {
return;
}

PlayerSettings.Android.bundleVersionCode = bundleVersionCode;
}

static void Apply(string version)
6 changes: 5 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/model/android-versioning.test.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@ import AndroidVersioning from './android-versioning';

describe('Android Versioning', () => {
describe('versionToVersionCode', () => {
it('defaults to 0 when versioning strategy is none', () => {
expect(AndroidVersioning.versionToVersionCode('none')).toBe(0);
});

it('defaults to 1 when version is not a valid semver', () => {
expect(AndroidVersioning.versionToVersionCode('abcd')).toBe(1);
});
@@ -11,7 +15,7 @@ describe('Android Versioning', () => {
});

it('throw when generated version code is too large', () => {
expect(() => AndroidVersioning.versionToVersionCode('1234.0.0')).toThrow();
expect(() => AndroidVersioning.versionToVersionCode('2050.0.0')).toThrow();
});
});

7 changes: 6 additions & 1 deletion src/model/android-versioning.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,11 @@ export default class AndroidVersioning {
}

static versionToVersionCode(version) {
if (version === 'none') {
core.info(`Versioning strategy is set to ${version}, so android version code should not be applied.`);
return 0;
}

const parsedVersion = semver.parse(version);

if (!parsedVersion) {
@@ -21,7 +26,7 @@ export default class AndroidVersioning {
// Allow for 3 patch digits, 3 minor digits and 3 major digits.
const versionCode = parsedVersion.major * 1000000 + parsedVersion.minor * 1000 + parsedVersion.patch;

if (versionCode >= 1000000000) {
if (versionCode >= 2050000000) {
throw new Error(
`Generated versionCode ${versionCode} is dangerously close to the maximum allowed number 2100000000. Consider a different versioning scheme to be able to continue updating your application.`,
);