Add androidTargetSdkVersion as an option to update the Android SDK (#298)
* Add androidTargetSdkVersion as an option to update the Android SDK API level * Fix build script * Update default value * Add JAVA_HOME * Use Unity_path * Update src/model/android-versioning.test.ts Co-authored-by: Webber Takken <webber@takken.io> * Correct JAVA_HOME * Use unity_path * Update JAVA_HOME to use path found from 2020.3 * Dynamically determine JAVA_HOME * Update path determination Co-authored-by: Webber Takken <webber@takken.io>
This commit is contained in:
@@ -28,4 +28,14 @@ describe('Android Versioning', () => {
|
||||
expect(AndroidVersioning.determineVersionCode('1.2.3', 2)).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('determineSdkManagerParameters', () => {
|
||||
it('defaults to blank', () => {
|
||||
expect(AndroidVersioning.determineSdkManagerParameters('AndroidApiLevelAuto')).toBe('');
|
||||
});
|
||||
|
||||
it('uses the specified api level', () => {
|
||||
expect(AndroidVersioning.determineSdkManagerParameters('AndroidApiLevel30')).toBe('platforms;android-30');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,4 +34,9 @@ export default class AndroidVersioning {
|
||||
core.info(`Using android versionCode ${versionCode}`);
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
static determineSdkManagerParameters(targetSdkVersion) {
|
||||
const parsedVersion = Number.parseInt(targetSdkVersion.slice(-2), 10);
|
||||
return Number.isNaN(parsedVersion) ? '' : `platforms;android-${parsedVersion}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Versioning from './versioning';
|
||||
import UnityVersioning from './unity-versioning';
|
||||
import AndroidVersioning from './android-versioning';
|
||||
import BuildParameters from './build-parameters';
|
||||
import Input from './input';
|
||||
import Platform from './platform';
|
||||
@@ -10,6 +11,10 @@ const determineUnityVersion = jest
|
||||
.spyOn(UnityVersioning, 'determineUnityVersion')
|
||||
.mockImplementation(() => '2019.2.11f1');
|
||||
|
||||
const determineSdkManagerParameters = jest
|
||||
.spyOn(AndroidVersioning, 'determineSdkManagerParameters')
|
||||
.mockImplementation(() => 'platforms;android-30');
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
@@ -44,6 +49,11 @@ describe('BuildParameters', () => {
|
||||
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ androidVersionCode: 1003037 }));
|
||||
});
|
||||
|
||||
it('determines the android sdk manager parameters only once', async () => {
|
||||
await BuildParameters.create();
|
||||
expect(determineSdkManagerParameters).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('returns the platform', async () => {
|
||||
const mockValue = 'somePlatform';
|
||||
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockValue);
|
||||
@@ -154,6 +164,14 @@ describe('BuildParameters', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the android target sdk version', async () => {
|
||||
const mockValue = 'AndroidApiLevelAuto';
|
||||
jest.spyOn(Input, 'androidTargetSdkVersion', 'get').mockReturnValue(mockValue);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(
|
||||
expect.objectContaining({ androidTargetSdkVersion: mockValue }),
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the custom parameters', async () => {
|
||||
const mockValue = '-profile SomeProfile -someBoolean -someValue exampleValue';
|
||||
jest.spyOn(Input, 'customParameters', 'get').mockReturnValue(mockValue);
|
||||
|
||||
@@ -21,6 +21,8 @@ class BuildParameters {
|
||||
public androidKeystorePass!: string;
|
||||
public androidKeyaliasName!: string;
|
||||
public androidKeyaliasPass!: string;
|
||||
public androidTargetSdkVersion!: string;
|
||||
public androidSdkManagerParameters!: string;
|
||||
public customParameters!: string;
|
||||
public sshAgent!: string;
|
||||
public gitPrivateToken!: string;
|
||||
@@ -43,6 +45,8 @@ class BuildParameters {
|
||||
|
||||
const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode);
|
||||
|
||||
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion);
|
||||
|
||||
return {
|
||||
version: unityVersion,
|
||||
customImage: Input.customImage,
|
||||
@@ -61,6 +65,8 @@ class BuildParameters {
|
||||
androidKeystorePass: Input.androidKeystorePass,
|
||||
androidKeyaliasName: Input.androidKeyaliasName,
|
||||
androidKeyaliasPass: Input.androidKeyaliasPass,
|
||||
androidTargetSdkVersion: Input.androidTargetSdkVersion,
|
||||
androidSdkManagerParameters,
|
||||
customParameters: Input.customParameters,
|
||||
sshAgent: Input.sshAgent,
|
||||
gitPrivateToken: Input.gitPrivateToken,
|
||||
|
||||
@@ -35,6 +35,8 @@ class Docker {
|
||||
androidKeystorePass,
|
||||
androidKeyaliasName,
|
||||
androidKeyaliasPass,
|
||||
androidTargetSdkVersion,
|
||||
androidSdkManagerParameters,
|
||||
customParameters,
|
||||
sshAgent,
|
||||
gitPrivateToken,
|
||||
@@ -64,6 +66,8 @@ class Docker {
|
||||
--env ANDROID_KEYSTORE_PASS="${androidKeystorePass}" \
|
||||
--env ANDROID_KEYALIAS_NAME="${androidKeyaliasName}" \
|
||||
--env ANDROID_KEYALIAS_PASS="${androidKeyaliasPass}" \
|
||||
--env ANDROID_TARGET_SDK_VERSION="${androidTargetSdkVersion}" \
|
||||
--env ANDROID_SDK_MANAGER_PARAMETERS="${androidSdkManagerParameters}" \
|
||||
--env CUSTOM_PARAMETERS="${customParameters}" \
|
||||
--env CHOWN_FILES_TO="${chownFilesTo}" \
|
||||
--env GITHUB_REF \
|
||||
|
||||
@@ -226,6 +226,19 @@ describe('Input', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('androidTargetSdkVersion', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.androidTargetSdkVersion).toStrictEqual('');
|
||||
});
|
||||
|
||||
it('takes input from the users workflow', () => {
|
||||
const mockValue = 'secret';
|
||||
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
|
||||
expect(Input.androidTargetSdkVersion).toStrictEqual(mockValue);
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('allowDirtyBuild', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.allowDirtyBuild).toStrictEqual(false);
|
||||
|
||||
@@ -75,6 +75,10 @@ class Input {
|
||||
return core.getInput('androidKeyaliasPass') || '';
|
||||
}
|
||||
|
||||
static get androidTargetSdkVersion() {
|
||||
return core.getInput('androidTargetSdkVersion') || '';
|
||||
}
|
||||
|
||||
static get allowDirtyBuild() {
|
||||
const input = core.getInput('allowDirtyBuild') || false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user