Add android symbol type parameter. Change windows scripts to use $LastExitCode and not $?. Update tests.

pull/505/head
Andrew Kahr 2023-02-11 21:45:49 -08:00
parent 899cb85628
commit 25e471bdd5
13 changed files with 124 additions and 42 deletions

View File

@ -53,7 +53,6 @@ inputs:
description: '[Deprecated] Use androidExportType instead. Whether to build .aab instead of .apk' description: '[Deprecated] Use androidExportType instead. Whether to build .aab instead of .apk'
androidExportType: androidExportType:
required: false required: false
default: 'androidPackage'
description: description:
'The android export type. Should be androidPackage for apk, androidAppBundle for aab, or androidStudioProject for 'The android export type. Should be androidPackage for apk, androidAppBundle for aab, or androidStudioProject for
an android studio project.' an android studio project.'
@ -81,6 +80,10 @@ inputs:
required: false required: false
default: '' default: ''
description: 'The android target API level.' description: 'The android target API level.'
androidSymbolType:
required: false
default: 'none'
description: 'The android symbol type to export. Should be "none", "public" or "debugging".'
sshAgent: sshAgent:
required: false required: false
default: '' default: ''

View File

@ -54,6 +54,22 @@ namespace UnityBuilderAction.Input
break; break;
} }
} }
if (options.TryGetValue("androidSymbolType", out string symbolType) && !string.IsNullOrEmpty(symbolType))
{
switch(symbolType)
{
case "public":
EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Public;
break;
case "debugging":
EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Debugging;
break;
case "none":
EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Disabled;
break;
}
}
} }
} }
} }

23
dist/index.js vendored
View File

@ -231,6 +231,17 @@ class BuildParameters {
const buildVersion = yield versioning_1.default.determineBuildVersion(input_1.default.versioningStrategy, input_1.default.specifiedVersion); const buildVersion = yield versioning_1.default.determineBuildVersion(input_1.default.versioningStrategy, input_1.default.specifiedVersion);
const androidVersionCode = android_versioning_1.default.determineVersionCode(buildVersion, input_1.default.androidVersionCode); const androidVersionCode = android_versioning_1.default.determineVersionCode(buildVersion, input_1.default.androidVersionCode);
const androidSdkManagerParameters = android_versioning_1.default.determineSdkManagerParameters(input_1.default.androidTargetSdkVersion); const androidSdkManagerParameters = android_versioning_1.default.determineSdkManagerParameters(input_1.default.androidTargetSdkVersion);
const androidSymbolExportType = input_1.default.androidSymbolType;
if (platform_1.default.isAndroid(input_1.default.targetPlatform)) {
switch (androidSymbolExportType) {
case 'none':
case 'public':
case 'debugging':
break;
default:
throw new Error(`Invalid androidSymbolType: ${input_1.default.androidSymbolType}. Must be one of: none, public, debugging`);
}
}
// Todo - Don't use process.env directly, that's what the input model class is for. // Todo - Don't use process.env directly, that's what the input model class is for.
// --- // ---
let unitySerial = ''; let unitySerial = '';
@ -271,6 +282,7 @@ class BuildParameters {
androidTargetSdkVersion: input_1.default.androidTargetSdkVersion, androidTargetSdkVersion: input_1.default.androidTargetSdkVersion,
androidSdkManagerParameters, androidSdkManagerParameters,
androidExportType: input_1.default.androidExportType, androidExportType: input_1.default.androidExportType,
androidSymbolType: androidSymbolExportType,
customParameters: input_1.default.customParameters, customParameters: input_1.default.customParameters,
sshAgent: input_1.default.sshAgent, sshAgent: input_1.default.sshAgent,
gitPrivateToken: input_1.default.gitPrivateToken || (yield github_cli_1.GithubCliReader.GetGitHubAuthToken()), gitPrivateToken: input_1.default.gitPrivateToken || (yield github_cli_1.GithubCliReader.GetGitHubAuthToken()),
@ -325,6 +337,8 @@ class BuildParameters {
return `${filename}.aab`; return `${filename}.aab`;
case `androidStudioProject`: case `androidStudioProject`:
return filename; return filename;
default:
throw new Error(`Unknown Android Export Type: ${androidExportType}. Must be one of androidPackage for apk, androidAppBundle for aab, androidStudioProject for android project`);
} }
} }
return filename; return filename;
@ -6644,6 +6658,7 @@ class ImageEnvironmentFactory {
{ name: 'ANDROID_TARGET_SDK_VERSION', value: parameters.androidTargetSdkVersion }, { name: 'ANDROID_TARGET_SDK_VERSION', value: parameters.androidTargetSdkVersion },
{ name: 'ANDROID_SDK_MANAGER_PARAMETERS', value: parameters.androidSdkManagerParameters }, { name: 'ANDROID_SDK_MANAGER_PARAMETERS', value: parameters.androidSdkManagerParameters },
{ name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType }, { name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType },
{ name: 'ANDROID_SYMBOL_TYPE', value: parameters.androidSymbolType },
{ name: 'CUSTOM_PARAMETERS', value: parameters.customParameters }, { name: 'CUSTOM_PARAMETERS', value: parameters.customParameters },
{ name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo }, { name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo },
{ name: 'GITHUB_REF', value: process.env.GITHUB_REF }, { name: 'GITHUB_REF', value: process.env.GITHUB_REF },
@ -7210,7 +7225,7 @@ class Input {
return Input.getInput('androidVersionCode'); return Input.getInput('androidVersionCode');
} }
static get androidAppBundle() { static get androidAppBundle() {
core.warning('androidAppBundle is deprecated, please use androidExportType instead in the Unity-Build-Action'); core.warning('androidAppBundle is deprecated, please use androidExportType instead');
const input = Input.getInput('androidAppBundle') || false; const input = Input.getInput('androidAppBundle') || false;
return input === 'true'; return input === 'true';
} }
@ -7243,6 +7258,9 @@ class Input {
static get androidTargetSdkVersion() { static get androidTargetSdkVersion() {
return Input.getInput('androidTargetSdkVersion') || ''; return Input.getInput('androidTargetSdkVersion') || '';
} }
static get androidSymbolType() {
return Input.getInput('androidSymbolType') || 'none';
}
static get sshAgent() { static get sshAgent() {
return Input.getInput('sshAgent') || ''; return Input.getInput('sshAgent') || '';
} }
@ -7632,6 +7650,7 @@ class SetupMac {
process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion; process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion;
process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters; process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters;
process.env.ANDROID_EXPORT_TYPE = buildParameters.androidExportType; process.env.ANDROID_EXPORT_TYPE = buildParameters.androidExportType;
process.env.ANDROID_SYMBOL_TYPE = buildParameters.androidSymbolType;
process.env.CUSTOM_PARAMETERS = buildParameters.customParameters; process.env.CUSTOM_PARAMETERS = buildParameters.customParameters;
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo; process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
}); });
@ -8100,7 +8119,7 @@ class Versioning {
* The commit SHA that triggered the workflow run. * The commit SHA that triggered the workflow run.
*/ */
static get sha() { static get sha() {
return process.env.GITHUB_SHA; return 'HEAD';
} }
/** /**
* Maximum number of lines to print when logging the git diff * Maximum number of lines to print when logging the git diff

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -148,6 +148,7 @@ echo ""
-androidKeyaliasPass "$ANDROID_KEYALIAS_PASS" \ -androidKeyaliasPass "$ANDROID_KEYALIAS_PASS" \
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \ -androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
-androidExportType "$ANDROID_EXPORT_TYPE" \ -androidExportType "$ANDROID_EXPORT_TYPE" \
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
$CUSTOM_PARAMETERS $CUSTOM_PARAMETERS
# Catch exit code # Catch exit code

View File

@ -134,6 +134,7 @@ unity-editor \
-androidKeyaliasPass "$ANDROID_KEYALIAS_PASS" \ -androidKeyaliasPass "$ANDROID_KEYALIAS_PASS" \
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \ -androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
-androidExportType "$ANDROID_EXPORT_TYPE" \ -androidExportType "$ANDROID_EXPORT_TYPE" \
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
$CUSTOM_PARAMETERS $CUSTOM_PARAMETERS
# Catch exit code # Catch exit code

View File

@ -127,11 +127,12 @@ $_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUST
-androidKeyaliasPass $Env:ANDROID_KEYALIAS_PASS ` -androidKeyaliasPass $Env:ANDROID_KEYALIAS_PASS `
-androidTargetSdkVersion $Env:ANDROID_TARGET_SDK_VERSION ` -androidTargetSdkVersion $Env:ANDROID_TARGET_SDK_VERSION `
-androidExportType $Env:ANDROID_EXPORT_TYPE ` -androidExportType $Env:ANDROID_EXPORT_TYPE `
-androidSymbolType $Env:ANDROID_SYMBOL_TYPE `
$customParametersArray ` $customParametersArray `
-logfile | Out-Host -logfile | Out-Host
# Catch exit code # Catch exit code
$Env:BUILD_EXIT_CODE=$? $Env:BUILD_EXIT_CODE=$LastExitCode
# Display results # Display results
if ($Env:BUILD_EXIT_CODE -eq 0) if ($Env:BUILD_EXIT_CODE -eq 0)

View File

@ -95,43 +95,41 @@ describe('BuildParameters', () => {
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildFile: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildFile: mockValue }));
}); });
test.each([Platform.types.StandaloneWindows, Platform.types.StandaloneWindows64])( test.each`
'appends exe for %s', targetPlatform | expectedExtension | androidExportType
async (targetPlatform) => { ${Platform.types.Android} | ${'.apk'} | ${'androidPackage'}
${Platform.types.Android} | ${'.aab'} | ${'androidAppBundle'}
${Platform.types.Android} | ${''} | ${'androidStudioProject'}
${Platform.types.StandaloneWindows} | ${'.exe'} | ${'n/a'}
${Platform.types.StandaloneWindows64} | ${'.exe'} | ${'n/a'}
`(
'appends $expectedExtension for $targetPlatform with androidExportType $androidExportType',
async ({ targetPlatform, expectedExtension, androidExportType }) => {
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform); jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform); jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'androidExportType', 'get').mockReturnValue(androidExportType);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildFile: `${targetPlatform}.exe` }), expect.objectContaining({ buildFile: `${targetPlatform}${expectedExtension}` }),
); );
}, },
); );
test.each([Platform.types.Android])('appends apk for %s', async (targetPlatform) => { test.each`
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform); targetPlatform | androidSymbolType
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform); ${Platform.types.Android} | ${'none'}
jest.spyOn(Input, 'androidExportType', 'get').mockReturnValue('androidPackage'); ${Platform.types.Android} | ${'public'}
await expect(BuildParameters.create()).resolves.toEqual( ${Platform.types.Android} | ${'debugging'}
expect.objectContaining({ buildFile: `${targetPlatform}.apk` }), ${Platform.types.StandaloneWindows} | ${'none'}
); ${Platform.types.StandaloneWindows64} | ${'none'}
}); `(
'androidSymbolType is set to $androidSymbolType when targetPlatform is $targetPlatform and input targetSymbolType is $androidSymbolType',
test.each([Platform.types.Android])('appends apk for %s', async (targetPlatform) => { async ({ targetPlatform, androidSymbolType }) => {
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform); jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform); jest.spyOn(Input, 'androidSymbolType', 'get').mockReturnValue(androidSymbolType);
jest.spyOn(Input, 'androidExportType', 'get').mockReturnValue('androidAppBundle'); jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ androidSymbolType }));
expect.objectContaining({ buildFile: `${targetPlatform}.aab` }), },
); );
});
test.each([Platform.types.Android])('appends apk for %s', async (targetPlatform) => {
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'androidExportType', 'get').mockReturnValue('androidStudioProject');
await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildFile: `${targetPlatform}` }),
);
});
it('returns the build method', async () => { it('returns the build method', async () => {
const mockValue = 'Namespace.ClassName.BuildMethod'; const mockValue = 'Namespace.ClassName.BuildMethod';

View File

@ -34,6 +34,7 @@ class BuildParameters {
public androidTargetSdkVersion!: string; public androidTargetSdkVersion!: string;
public androidSdkManagerParameters!: string; public androidSdkManagerParameters!: string;
public androidExportType!: string; public androidExportType!: string;
public androidSymbolType!: string;
public customParameters!: string; public customParameters!: string;
public sshAgent!: string; public sshAgent!: string;
@ -83,6 +84,20 @@ class BuildParameters {
const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode); const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode);
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion); const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion);
const androidSymbolExportType = Input.androidSymbolType;
if (Platform.isAndroid(Input.targetPlatform)) {
switch (androidSymbolExportType) {
case 'none':
case 'public':
case 'debugging':
break;
default:
throw new Error(
`Invalid androidSymbolType: ${Input.androidSymbolType}. Must be one of: none, public, debugging`,
);
}
}
// Todo - Don't use process.env directly, that's what the input model class is for. // Todo - Don't use process.env directly, that's what the input model class is for.
// --- // ---
let unitySerial = ''; let unitySerial = '';
@ -123,6 +138,7 @@ class BuildParameters {
androidTargetSdkVersion: Input.androidTargetSdkVersion, androidTargetSdkVersion: Input.androidTargetSdkVersion,
androidSdkManagerParameters, androidSdkManagerParameters,
androidExportType: Input.androidExportType, androidExportType: Input.androidExportType,
androidSymbolType: androidSymbolExportType,
customParameters: Input.customParameters, customParameters: Input.customParameters,
sshAgent: Input.sshAgent, sshAgent: Input.sshAgent,
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()), gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
@ -178,6 +194,10 @@ class BuildParameters {
return `${filename}.aab`; return `${filename}.aab`;
case `androidStudioProject`: case `androidStudioProject`:
return filename; return filename;
default:
throw new Error(
`Unknown Android Export Type: ${androidExportType}. Must be one of androidPackage for apk, androidAppBundle for aab, androidStudioProject for android project`,
);
} }
} }

View File

@ -51,6 +51,7 @@ class ImageEnvironmentFactory {
{ name: 'ANDROID_TARGET_SDK_VERSION', value: parameters.androidTargetSdkVersion }, { name: 'ANDROID_TARGET_SDK_VERSION', value: parameters.androidTargetSdkVersion },
{ name: 'ANDROID_SDK_MANAGER_PARAMETERS', value: parameters.androidSdkManagerParameters }, { name: 'ANDROID_SDK_MANAGER_PARAMETERS', value: parameters.androidSdkManagerParameters },
{ name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType }, { name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType },
{ name: 'ANDROID_SYMBOL_TYPE', value: parameters.androidSymbolType },
{ name: 'CUSTOM_PARAMETERS', value: parameters.customParameters }, { name: 'CUSTOM_PARAMETERS', value: parameters.customParameters },
{ name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo }, { name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo },
{ name: 'GITHUB_REF', value: process.env.GITHUB_REF }, { name: 'GITHUB_REF', value: process.env.GITHUB_REF },

View File

@ -172,9 +172,9 @@ describe('Input', () => {
${'androidPackage'} | ${'androidPackage'} ${'androidPackage'} | ${'androidPackage'}
${'androidAppBundle'} | ${'androidAppBundle'} ${'androidAppBundle'} | ${'androidAppBundle'}
${'androidStudioProject'} | ${'androidStudioProject'} ${'androidStudioProject'} | ${'androidStudioProject'}
`('returns $expected when $input is passed and androidAppBundle is not set', (exportType) => { `('returns $expected when $input is passed and androidAppBundle is not set', ({ input, expected }) => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue(exportType); const spy = jest.spyOn(core, 'getInput').mockReturnValue(input);
expect(Input.androidExportType).toStrictEqual(exportType); expect(Input.androidExportType).toStrictEqual(expected);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@ -184,16 +184,16 @@ describe('Input', () => {
${'androidPackage'} | ${'androidPackage'} ${'androidPackage'} | ${'androidPackage'}
${'androidAppBundle'} | ${'androidAppBundle'} ${'androidAppBundle'} | ${'androidAppBundle'}
${'androidStudioProject'} | ${'androidStudioProject'} ${'androidStudioProject'} | ${'androidStudioProject'}
`('returns $expected when $input is passed and overrides androidAppBundle if it is set', (exportType) => { `('returns $expected when $input is passed and overrides androidAppBundle if it is set', ({ input, expected }) => {
const spy = jest.spyOn(Input, 'getInput'); const spy = jest.spyOn(Input, 'getInput');
spy.mockImplementationOnce(() => { spy.mockImplementationOnce(() => {
return exportType; return input;
}); });
spy.mockImplementationOnce(() => { spy.mockImplementationOnce(() => {
return true; return true;
}); });
expect(Input.androidExportType).toStrictEqual(exportType); expect(Input.androidExportType).toStrictEqual(expected);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@ -220,6 +220,23 @@ describe('Input', () => {
); );
}); });
describe('androidSymbolType', () => {
it('returns the default value', () => {
expect(Input.androidSymbolType).toStrictEqual('none');
});
test.each`
input | expected
${'none'} | ${'none'}
${'public'} | ${'public'}
${'debugging'} | ${'debugging'}
`('returns $expected when $input is passed', ({ input, expected }) => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue(input);
expect(Input.androidExportType).toStrictEqual(expected);
expect(spy).toHaveBeenCalledTimes(1);
});
});
describe('androidKeystoreName', () => { describe('androidKeystoreName', () => {
it('returns the default value', () => { it('returns the default value', () => {
expect(Input.androidKeystoreName).toStrictEqual(''); expect(Input.androidKeystoreName).toStrictEqual('');

View File

@ -134,7 +134,7 @@ class Input {
} }
static get androidAppBundle() { static get androidAppBundle() {
core.warning('androidAppBundle is deprecated, please use androidExportType instead in the Unity-Build-Action'); core.warning('androidAppBundle is deprecated, please use androidExportType instead');
const input = Input.getInput('androidAppBundle') || false; const input = Input.getInput('androidAppBundle') || false;
return input === 'true'; return input === 'true';
@ -180,6 +180,10 @@ class Input {
return Input.getInput('androidTargetSdkVersion') || ''; return Input.getInput('androidTargetSdkVersion') || '';
} }
static get androidSymbolType() {
return Input.getInput('androidSymbolType') || 'none';
}
static get sshAgent() { static get sshAgent() {
return Input.getInput('sshAgent') || ''; return Input.getInput('sshAgent') || '';
} }

View File

@ -153,6 +153,7 @@ class SetupMac {
process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion; process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion;
process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters; process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters;
process.env.ANDROID_EXPORT_TYPE = buildParameters.androidExportType; process.env.ANDROID_EXPORT_TYPE = buildParameters.androidExportType;
process.env.ANDROID_SYMBOL_TYPE = buildParameters.androidSymbolType;
process.env.CUSTOM_PARAMETERS = buildParameters.customParameters; process.env.CUSTOM_PARAMETERS = buildParameters.customParameters;
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo; process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
} }