mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
feat: add buildProfile
parameter
add new `buildProfile` action param, which will be passed into Unity as the `-activeBuildProfile ...` CLI param. closes https://github.com/game-ci/unity-builder/issues/674
This commit is contained in:
parent
3ae9ec8536
commit
5eccc32436
@ -18,7 +18,11 @@ inputs:
|
||||
projectPath:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Relative path to the project to be built.'
|
||||
description: 'Path to the project to be built, relative to the repository root.'
|
||||
buildProfile:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Path to the build profile to activate, relative to the project root.'
|
||||
buildName:
|
||||
required: false
|
||||
default: ''
|
||||
|
@ -6,6 +6,9 @@ using UnityBuilderAction.Reporting;
|
||||
using UnityBuilderAction.Versioning;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
using UnityEditor.Build.Profile;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityBuilderAction
|
||||
@ -17,47 +20,9 @@ namespace UnityBuilderAction
|
||||
// Gather values from args
|
||||
var options = ArgumentsParser.GetValidatedOptions();
|
||||
|
||||
// Gather values from project
|
||||
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();
|
||||
|
||||
// Get all buildOptions from options
|
||||
BuildOptions buildOptions = BuildOptions.None;
|
||||
foreach (string buildOptionString in Enum.GetNames(typeof(BuildOptions))) {
|
||||
if (options.ContainsKey(buildOptionString)) {
|
||||
BuildOptions buildOptionEnum = (BuildOptions) Enum.Parse(typeof(BuildOptions), buildOptionString);
|
||||
buildOptions |= buildOptionEnum;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
// Determine subtarget
|
||||
StandaloneBuildSubtarget buildSubtarget;
|
||||
if (!options.TryGetValue("standaloneBuildSubtarget", out var subtargetValue) || !Enum.TryParse(subtargetValue, out buildSubtarget)) {
|
||||
buildSubtarget = default;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define BuildPlayer Options
|
||||
var buildPlayerOptions = new BuildPlayerOptions {
|
||||
scenes = scenes,
|
||||
locationPathName = options["customBuildPath"],
|
||||
target = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
|
||||
options = buildOptions,
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
subtarget = (int) buildSubtarget
|
||||
#endif
|
||||
};
|
||||
|
||||
// Set version for this build
|
||||
VersionApplicator.SetVersion(options["buildVersion"]);
|
||||
|
||||
// Apply Android settings
|
||||
if (buildPlayerOptions.target == BuildTarget.Android)
|
||||
{
|
||||
VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);
|
||||
AndroidSettings.Apply(options);
|
||||
}
|
||||
|
||||
|
||||
// Execute default AddressableAsset content build, if the package is installed.
|
||||
// Version defines would be the best solution here, but Unity 2018 doesn't support that,
|
||||
// so we fall back to using reflection instead.
|
||||
@ -78,6 +43,72 @@ namespace UnityBuilderAction
|
||||
}
|
||||
}
|
||||
|
||||
// Get all buildOptions from options
|
||||
BuildOptions buildOptions = BuildOptions.None;
|
||||
foreach (string buildOptionString in Enum.GetNames(typeof(BuildOptions))) {
|
||||
if (options.ContainsKey(buildOptionString)) {
|
||||
BuildOptions buildOptionEnum = (BuildOptions) Enum.Parse(typeof(BuildOptions), buildOptionString);
|
||||
buildOptions |= buildOptionEnum;
|
||||
}
|
||||
}
|
||||
|
||||
// Depending on whether the build is using a build profile, `buildPlayerOptions` will an instance
|
||||
// of either `UnityEditor.BuildPlayerOptions` or `UnityEditor.BuildPlayerWithProfileOptions`
|
||||
dynamic buildPlayerOptions;
|
||||
|
||||
if (options["customBuildProfile"] != "") {
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
// Load build profile from Assets folder
|
||||
BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(options["customBuildProfile"]);
|
||||
|
||||
// Set it as active
|
||||
BuildProfile.SetActiveBuildProfile(buildProfile);
|
||||
|
||||
// Define BuildPlayerWithProfileOptions
|
||||
buildPlayerOptions = new BuildPlayerWithProfileOptions {
|
||||
buildProfile = buildProfile,
|
||||
locationPathName = options["customBuildPath"],
|
||||
options = buildOptions,
|
||||
};
|
||||
#else
|
||||
throw new Exception("Build profiles are not supported by this version of Unity (" + Application.unityVersion +")");
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
// Gather values from project
|
||||
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
// Determine subtarget
|
||||
StandaloneBuildSubtarget buildSubtarget;
|
||||
if (!options.TryGetValue("standaloneBuildSubtarget", out var subtargetValue) || !Enum.TryParse(subtargetValue, out buildSubtarget)) {
|
||||
buildSubtarget = default;
|
||||
}
|
||||
#endif
|
||||
|
||||
BuildTarget buildTarget = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]);
|
||||
|
||||
// Define BuildPlayerOptions
|
||||
buildPlayerOptions = new BuildPlayerOptions {
|
||||
scenes = scenes,
|
||||
locationPathName = options["customBuildPath"],
|
||||
target = buildTarget,
|
||||
options = buildOptions,
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
subtarget = (int) buildSubtarget
|
||||
#endif
|
||||
};
|
||||
|
||||
// Apply Android settings
|
||||
if (buildTarget == BuildTarget.Android) {
|
||||
VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);
|
||||
AndroidSettings.Apply(options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Perform build
|
||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
||||
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
18
dist/platforms/mac/steps/build.sh
vendored
18
dist/platforms/mac/steps/build.sh
vendored
@ -19,6 +19,23 @@ echo "Using build name \"$BUILD_NAME\"."
|
||||
|
||||
echo "Using build target \"$BUILD_TARGET\"."
|
||||
|
||||
#
|
||||
# Display the build profile
|
||||
#
|
||||
|
||||
if [ -z "$BUILD_PROFILE" ]; then
|
||||
# User has not provided a build profile
|
||||
#
|
||||
echo "Doing a default \"$BUILD_TARGET\" platform build."
|
||||
#
|
||||
else
|
||||
# User has provided a path to a build profile `.asset` file
|
||||
#
|
||||
echo "Using build profile \"$BUILD_PROFILE\" relative to \"$UNITY_PROJECT_PATH\"."
|
||||
#
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Display build path and file
|
||||
#
|
||||
@ -139,6 +156,7 @@ echo ""
|
||||
-buildTarget "$BUILD_TARGET" \
|
||||
-customBuildTarget "$BUILD_TARGET" \
|
||||
-customBuildPath "$CUSTOM_BUILD_PATH" \
|
||||
-customBuildProfile "$BUILD_PROFILE" \
|
||||
-executeMethod "$BUILD_METHOD" \
|
||||
-buildVersion "$VERSION" \
|
||||
-androidVersionCode "$ANDROID_VERSION_CODE" \
|
||||
|
17
dist/platforms/ubuntu/steps/build.sh
vendored
17
dist/platforms/ubuntu/steps/build.sh
vendored
@ -19,6 +19,22 @@ echo "Using build name \"$BUILD_NAME\"."
|
||||
|
||||
echo "Using build target \"$BUILD_TARGET\"."
|
||||
|
||||
#
|
||||
# Display the build profile
|
||||
#
|
||||
|
||||
if [ -z "$BUILD_PROFILE" ]; then
|
||||
# User has not provided a build profile
|
||||
#
|
||||
echo "Doing a default \"$BUILD_TARGET\" platform build."
|
||||
#
|
||||
else
|
||||
# User has provided a path to a build profile `.asset` file
|
||||
#
|
||||
echo "Using build profile \"$BUILD_PROFILE\" relative to \"$UNITY_PROJECT_PATH\"."
|
||||
#
|
||||
fi
|
||||
|
||||
#
|
||||
# Display build path and file
|
||||
#
|
||||
@ -112,6 +128,7 @@ unity-editor \
|
||||
-buildTarget "$BUILD_TARGET" \
|
||||
-customBuildTarget "$BUILD_TARGET" \
|
||||
-customBuildPath "$CUSTOM_BUILD_PATH" \
|
||||
-customBuildProfile "$BUILD_PROFILE" \
|
||||
-executeMethod "$BUILD_METHOD" \
|
||||
-buildVersion "$VERSION" \
|
||||
-androidVersionCode "$ANDROID_VERSION_CODE" \
|
||||
|
20
dist/platforms/windows/build.ps1
vendored
20
dist/platforms/windows/build.ps1
vendored
@ -16,6 +16,25 @@ Write-Output "$('Using build name "')$($Env:BUILD_NAME)$('".')"
|
||||
|
||||
Write-Output "$('Using build target "')$($Env:BUILD_TARGET)$('".')"
|
||||
|
||||
#
|
||||
# Display the build profile
|
||||
#
|
||||
|
||||
if ($Env:BUILD_PROFILE)
|
||||
{
|
||||
# User has provided a path to a build profile `.asset` file
|
||||
#
|
||||
Write-Output "$('Using build profile "')$($Env:BUILD_PROFILE)$('" relative to "')$($Env:UNITY_PROJECT_PATH)$('".')"
|
||||
#
|
||||
}
|
||||
else
|
||||
{
|
||||
# User has not provided a build profile
|
||||
#
|
||||
Write-Output "$('Doing a default "')$($Env:BUILD_TARGET)$('" platform build.')"
|
||||
#
|
||||
}
|
||||
|
||||
#
|
||||
# Display build path and file
|
||||
#
|
||||
@ -143,6 +162,7 @@ $unityArgs = @(
|
||||
"-buildTarget", "`"$Env:BUILD_TARGET`"",
|
||||
"-customBuildTarget", "`"$Env:BUILD_TARGET`"",
|
||||
"-customBuildPath", "`"$Env:CUSTOM_BUILD_PATH`"",
|
||||
"-customBuildProfile", "`"$Env:BUILD_PROFILE`"",
|
||||
"-buildVersion", "`"$Env:VERSION`"",
|
||||
"-androidVersionCode", "`"$Env:ANDROID_VERSION_CODE`"",
|
||||
"-androidKeystorePass", "`"$Env:ANDROID_KEYSTORE_PASS`"",
|
||||
|
@ -71,6 +71,12 @@ describe('BuildParameters', () => {
|
||||
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ projectPath: mockValue }));
|
||||
});
|
||||
|
||||
it('returns the build profile', async () => {
|
||||
const mockValue = 'path/to/build_profile.asset';
|
||||
jest.spyOn(Input, 'buildProfile', 'get').mockReturnValue(mockValue);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildProfile: mockValue }));
|
||||
});
|
||||
|
||||
it('returns the build name', async () => {
|
||||
const mockValue = 'someBuildName';
|
||||
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(mockValue);
|
||||
|
@ -26,6 +26,7 @@ class BuildParameters {
|
||||
public runnerTempPath!: string;
|
||||
public targetPlatform!: string;
|
||||
public projectPath!: string;
|
||||
public buildProfile!: string;
|
||||
public buildName!: string;
|
||||
public buildPath!: string;
|
||||
public buildFile!: string;
|
||||
@ -152,6 +153,7 @@ class BuildParameters {
|
||||
runnerTempPath: Input.runnerTempPath,
|
||||
targetPlatform: Input.targetPlatform,
|
||||
projectPath: Input.projectPath,
|
||||
buildProfile: Input.buildProfile,
|
||||
buildName: Input.buildName,
|
||||
buildPath: `${Input.buildsPath}/${Input.targetPlatform}`,
|
||||
buildFile,
|
||||
|
@ -36,6 +36,7 @@ class ImageEnvironmentFactory {
|
||||
value: process.env.USYM_UPLOAD_AUTH_TOKEN,
|
||||
},
|
||||
{ name: 'PROJECT_PATH', value: parameters.projectPath },
|
||||
{ name: 'BUILD_PROFILE', value: parameters.buildProfile },
|
||||
{ name: 'BUILD_TARGET', value: parameters.targetPlatform },
|
||||
{ name: 'BUILD_NAME', value: parameters.buildName },
|
||||
{ name: 'BUILD_PATH', value: parameters.buildPath },
|
||||
|
@ -59,6 +59,19 @@ describe('Input', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildProfile', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.buildProfile).toStrictEqual('');
|
||||
});
|
||||
|
||||
it('takes input from the users workflow', () => {
|
||||
const mockValue = 'path/to/build_profile.asset';
|
||||
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
|
||||
expect(Input.buildProfile).toStrictEqual(mockValue);
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildName', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.buildName).toStrictEqual(Input.targetPlatform);
|
||||
|
@ -107,6 +107,10 @@ class Input {
|
||||
return rawProjectPath.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
static get buildProfile(): string {
|
||||
return Input.getInput('buildProfile') ?? '';
|
||||
}
|
||||
|
||||
static get runnerTempPath(): string {
|
||||
return Input.getInput('RUNNER_TEMP') ?? '';
|
||||
}
|
||||
|
@ -170,6 +170,7 @@ class SetupMac {
|
||||
process.env.UNITY_LICENSING_SERVER = buildParameters.unityLicensingServer;
|
||||
process.env.SKIP_ACTIVATION = buildParameters.skipActivation;
|
||||
process.env.PROJECT_PATH = buildParameters.projectPath;
|
||||
process.env.BUILD_PROFILE = buildParameters.buildProfile;
|
||||
process.env.BUILD_TARGET = buildParameters.targetPlatform;
|
||||
process.env.BUILD_NAME = buildParameters.buildName;
|
||||
process.env.BUILD_PATH = buildParameters.buildPath;
|
||||
|
Loading…
Reference in New Issue
Block a user