diff --git a/action.yml b/action.yml index 64effd18..68f93923 100644 --- a/action.yml +++ b/action.yml @@ -188,6 +188,8 @@ outputs: description: 'The Persistent Volume (PV) where the build artifacts have been stored by Kubernetes' buildVersion: description: 'The generated version used for the Unity build' + androidVersionCode: + description: 'The generated versionCode used for the Android Unity build' branding: icon: 'box' color: 'gray-dark' diff --git a/dist/index.js b/dist/index.js index 4ffd8876..ec837da4 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index fa19a7fc..cd41e3a6 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/dist/platforms/ubuntu/steps/build.sh b/dist/platforms/ubuntu/steps/build.sh index 2e7e3909..ba9a3ad9 100755 --- a/dist/platforms/ubuntu/steps/build.sh +++ b/dist/platforms/ubuntu/steps/build.sh @@ -63,17 +63,9 @@ else fi # -# Prepare Android keystore and SDK, if needed +# Prepare Android SDK, if needed # -if [[ "$BUILD_TARGET" == "Android" && -n "$ANDROID_KEYSTORE_NAME" && -n "$ANDROID_KEYSTORE_BASE64" ]]; then - echo "Creating Android keystore." - echo "$ANDROID_KEYSTORE_BASE64" | base64 --decode > "$UNITY_PROJECT_PATH/$ANDROID_KEYSTORE_NAME" - echo "Created Android keystore." -else - echo "Not creating Android keystore." -fi - if [[ "$BUILD_TARGET" == "Android" && -n "$ANDROID_SDK_MANAGER_PARAMETERS" ]]; then echo "Updating Android SDK with parameters: $ANDROID_SDK_MANAGER_PARAMETERS" export JAVA_HOME="$(awk -F'=' '/JAVA_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" diff --git a/src/index.ts b/src/index.ts index 1582d7c0..99654f20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,6 +32,7 @@ async function runMain() { // Set output await Output.setBuildVersion(buildParameters.buildVersion); + await Output.setAndroidVersionCode(buildParameters.androidVersionCode); } catch (error) { core.setFailed((error as Error).message); } diff --git a/src/model/output.test.ts b/src/model/output.test.ts index c4fcb114..c2bf2fef 100644 --- a/src/model/output.test.ts +++ b/src/model/output.test.ts @@ -7,3 +7,11 @@ describe('Output', () => { }); }); }); + +describe('Output', () => { + describe('setAndroidVersionCode', () => { + it('does not throw', async () => { + await expect(Output.setAndroidVersionCode('1000')).resolves.not.toThrow(); + }); + }); +}); diff --git a/src/model/output.ts b/src/model/output.ts index 1e482f6e..8b6896bc 100644 --- a/src/model/output.ts +++ b/src/model/output.ts @@ -4,6 +4,10 @@ class Output { static async setBuildVersion(buildVersion) { await core.setOutput('buildVersion', buildVersion); } + + static async setAndroidVersionCode(androidVersionCode) { + await core.setOutput('androidVersionCode', androidVersionCode); + } } export default Output; diff --git a/src/model/platform-setup.ts b/src/model/platform-setup.ts index ced5b753..f60072a3 100644 --- a/src/model/platform-setup.ts +++ b/src/model/platform-setup.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import * as core from '@actions/core'; import { BuildParameters } from '.'; -import { SetupMac, SetupWindows } from './platform-setup/'; +import { SetupMac, SetupWindows, SetupAndroid } from './platform-setup/'; import ValidateWindows from './platform-validation/validate-windows'; class PlatformSetup { @@ -33,6 +33,8 @@ class PlatformSetup { let servicesConfig = fs.readFileSync(servicesConfigPathTemplate).toString(); servicesConfig = servicesConfig.replace('%URL%', buildParameters.unityLicensingServer); fs.writeFileSync(servicesConfigPath, servicesConfig); + + SetupAndroid.setup(buildParameters); } } diff --git a/src/model/platform-setup/index.ts b/src/model/platform-setup/index.ts index cc2ab97b..6d68ab38 100644 --- a/src/model/platform-setup/index.ts +++ b/src/model/platform-setup/index.ts @@ -1,4 +1,5 @@ import SetupWindows from './setup-windows'; import SetupMac from './setup-mac'; +import SetupAndroid from './setup-android'; -export { SetupWindows, SetupMac }; +export { SetupWindows, SetupMac, SetupAndroid }; diff --git a/src/model/platform-setup/setup-android.ts b/src/model/platform-setup/setup-android.ts new file mode 100644 index 00000000..4a2d1668 --- /dev/null +++ b/src/model/platform-setup/setup-android.ts @@ -0,0 +1,21 @@ +import fs from 'fs'; +import path from 'path'; +import { BuildParameters } from '..'; + +class SetupAndroid { + public static async setup(buildParameters: BuildParameters) { + const { targetPlatform, androidKeystoreBase64, androidKeystoreName, projectPath } = buildParameters; + + if (targetPlatform === 'Android' && androidKeystoreBase64 !== '' && androidKeystoreName !== '') { + SetupAndroid.setupAndroidRun(androidKeystoreBase64, androidKeystoreName, projectPath); + } + } + + private static setupAndroidRun(androidKeystoreBase64: string, androidKeystoreName: string, projectPath: string) { + const decodedKeystore = Buffer.from(androidKeystoreBase64, 'base64').toString('binary'); + const githubWorkspace = process.env.GITHUB_WORKSPACE || ''; + fs.writeFileSync(path.join(githubWorkspace, projectPath, androidKeystoreName), decodedKeystore, 'binary'); + } +} + +export default SetupAndroid;