Skip to content

Commit

Permalink
feat: add buildProfile parameter
Browse files Browse the repository at this point in the history
add new `buildProfile` action param, which will be passed into
Unity as the `-activeBuildProfile ...` CLI param.

closes game-ci#674
  • Loading branch information
MichaelBuhler committed Jan 29, 2025
1 parent 83c8532 commit 21e3152
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 7 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
8 changes: 7 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.

46 changes: 45 additions & 1 deletion dist/platforms/mac/steps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -62,6 +79,25 @@ else
#
fi

#
# Assemble the build target or build profile CLI options
#
# The `-buildTarget` and `-activeBuildProfile` are mutually exclusive options.
#

if [ -z "$BUILD_PROFILE" ]; then
# User has not provided a build profile, `-buildTarget` is necessary.
#
BUILD_TARGET_OR_PROFILE=("-buildTarget" "$BUILD_TARGET")
#
else
# User has provided a build profile, `-buildTarget` is not necessary.
#
BUILD_TARGET_OR_PROFILE=("-activeBuildProfile" "$BUILD_PROFILE")
#
fi


#
# Prepare Android keystore and SDK, if needed
#
Expand Down Expand Up @@ -89,6 +125,14 @@ fi
# Pre-build debug information
#

echo ""
echo "###########################"
echo "# Build target/prof #"
echo "###########################"
echo ""

echo "${BUILD_TARGET_OR_PROFILE[0]} \"${BUILD_TARGET_OR_PROFILE[1]}\""

echo ""
echo "###########################"
echo "# Custom parameters #"
Expand Down Expand Up @@ -136,7 +180,7 @@ echo ""
-password "$UNITY_PASSWORD" \
-customBuildName "$BUILD_NAME" \
-projectPath "$UNITY_PROJECT_PATH" \
-buildTarget "$BUILD_TARGET" \
"${BUILD_TARGET_OR_PROFILE[@]}" \
-customBuildTarget "$BUILD_TARGET" \
-customBuildPath "$CUSTOM_BUILD_PATH" \
-executeMethod "$BUILD_METHOD" \
Expand Down
44 changes: 43 additions & 1 deletion dist/platforms/ubuntu/steps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -62,10 +78,36 @@ else
#
fi

#
# Assemble the build target or build profile CLI options
#
# The `-buildTarget` and `-activeBuildProfile` are mutually exclusive options.
#

if [ -z "$BUILD_PROFILE" ]; then
# User has not provided a build profile, `-buildTarget` is necessary.
#
BUILD_TARGET_OR_PROFILE=("-buildTarget" "$BUILD_TARGET")
#
else
# User has provided a build profile, `-buildTarget` is not necessary.
#
BUILD_TARGET_OR_PROFILE=("-activeBuildProfile" "$BUILD_PROFILE")
#
fi

#
# Pre-build debug information
#

echo ""
echo "###########################"
echo "# Build target/prof #"
echo "###########################"
echo ""

echo "${BUILD_TARGET_OR_PROFILE[0]} \"${BUILD_TARGET_OR_PROFILE[1]}\""

echo ""
echo "###########################"
echo "# Custom parameters #"
Expand Down Expand Up @@ -109,7 +151,7 @@ unity-editor \
$( [ "${MANUAL_EXIT}" == "true" ] || echo "-quit" ) \
-customBuildName "$BUILD_NAME" \
-projectPath "$UNITY_PROJECT_PATH" \
-buildTarget "$BUILD_TARGET" \
"${BUILD_TARGET_OR_PROFILE[@]}" \
-customBuildTarget "$BUILD_TARGET" \
-customBuildPath "$CUSTOM_BUILD_PATH" \
-executeMethod "$BUILD_METHOD" \
Expand Down
50 changes: 48 additions & 2 deletions dist/platforms/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -86,10 +105,38 @@ else {
Write-Output "Not creating Android keystore."
}

#
# Assemble the build target or build profile CLI options
#
# The `-buildTarget` and `-activeBuildProfile` are mutually exclusive options.
#

if ($Env:$BUILD_PROFILE) {
# User has provided a build profile, `-buildTarget` is not necessary.
#
$buildtargetOrProfile = @("-activeBuildProfile", "`"$Env:BUILD_PROFILE`"")
#
}
else
{
# User has not provided a build profile, `-buildTarget` is necessary.
#
$buildtargetOrProfile = @("-buildTarget", "`"$Env:BUILD_TARGET`"")
#
}

#
# Pre-build debug information
#

Write-Output ""
Write-Output "###########################"
Write-Output "# Build target/prof #"
Write-Output "###########################"
Write-Output ""

Write-Output "$('"')$($buildtargetOrProfile)$('"')"

Write-Output ""
Write-Output "###########################"
Write-Output "# Custom parameters #"
Expand Down Expand Up @@ -140,7 +187,6 @@ $unityArgs = @(
"-customBuildName", "`"$Env:BUILD_NAME`"",
"-projectPath", "`"$Env:UNITY_PROJECT_PATH`"",
"-executeMethod", "`"$Env:BUILD_METHOD`"",
"-buildTarget", "`"$Env:BUILD_TARGET`"",
"-customBuildTarget", "`"$Env:BUILD_TARGET`"",
"-customBuildPath", "`"$Env:CUSTOM_BUILD_PATH`"",
"-buildVersion", "`"$Env:VERSION`"",
Expand All @@ -152,7 +198,7 @@ $unityArgs = @(
"-androidExportType", "`"$Env:ANDROID_EXPORT_TYPE`"",
"-androidSymbolType", "`"$Env:ANDROID_SYMBOL_TYPE`"",
"-logfile", "-"
) + $customParametersArray
) + $buildtargetOrProfile + $customParametersArray

# Remove null items as that will fail the Start-Process call
$unityArgs = $unityArgs | Where-Object { $_ -ne $null }
Expand Down
6 changes: 6 additions & 0 deletions src/model/build-parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/model/build-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/model/image-environment-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
13 changes: 13 additions & 0 deletions src/model/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/model/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') ?? '';
}
Expand Down
1 change: 1 addition & 0 deletions src/model/platform-setup/setup-mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 21e3152

Please sign in to comment.