From 2a8752c24ad98c57c10e79f8db7a08f481a82d01 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 14:25:56 -0700 Subject: [PATCH 01/11] feat: define the new params in the command an job --- src/commands/build.yml | 16 ++++++++++++++++ src/jobs/build.yml | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/commands/build.yml b/src/commands/build.yml index 92d7b20..3afccff 100644 --- a/src/commands/build.yml +++ b/src/commands/build.yml @@ -51,6 +51,20 @@ parameters: type: string default: "10m" description: Elapsed time the command can run without output. + build-method: + type: string + default: "" + description: | + The method used as argument for the Unity CLI "executeMethod" parameter. + It must be a valid path to a static method and the class exist in the Assets/Editor directory. + If left empty, the default build method will be used. + custom-parameters: + type: string + default: "" + description: | + Additional arguments for the Unity CLI. + Use it to pass arguments defined on your custom "build-method" or Unity's build options. + The parameters must be separated by a space and must be in the format "-key value" or "-key" for booleans. steps: - run: @@ -61,6 +75,8 @@ steps: PARAM_BUILD_TARGET: << parameters.build-target >> PARAM_PROJECT_PATH: << parameters.project-path >> PARAM_COMPRESS: << parameters.compress >> + PARAM_BUILD_METHOD: << parameters.build-method >> + PARAM_CUSTOM_PARAMETERS: << parameters.custom-parameters >> SCRIPT_BUILD_WINDOWS: << include(scripts/windows/build.sh) >> SCRIPT_BUILD_LINUX: << include(scripts/linux/build.sh) >> SCRIPT_BUILD_MACOS: << include(scripts/macos/build.sh) >> diff --git a/src/jobs/build.yml b/src/jobs/build.yml index 7d5c516..6b2d03a 100755 --- a/src/jobs/build.yml +++ b/src/jobs/build.yml @@ -73,6 +73,20 @@ parameters: type: string default: "20m" description: Elapsed time the command can run without output. + build-method: + type: string + default: "" + description: | + The method used as argument for the Unity CLI "executeMethod" parameter. + It must be a valid path to a static method and the class exist in the Assets/Editor directory. + If left empty, the default build method will be used. + custom-parameters: + type: string + default: "" + description: | + Additional arguments for the Unity CLI. + Use it to pass arguments defined on your custom "build-method" or Unity's build options. + The parameters must be separated by a space and must be in the format "-key value" or "-key" for booleans. executor: << parameters.executor >> @@ -93,6 +107,8 @@ steps: store-artifacts: <> compress: <> no_output_timeout: << parameters.no_output_timeout>> + build-method: <> + custom-parameters: <> - when: condition: <> steps: From 4c9e33a8090639029f2f5e8ddad354b81cffd694 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 14:33:02 -0700 Subject: [PATCH 02/11] feat: add check for `build-method` in the build entry point. --- src/commands/build.yml | 3 ++- src/jobs/build.yml | 3 ++- src/scripts/build.sh | 9 ++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/commands/build.yml b/src/commands/build.yml index 3afccff..b6d2532 100644 --- a/src/commands/build.yml +++ b/src/commands/build.yml @@ -64,7 +64,8 @@ parameters: description: | Additional arguments for the Unity CLI. Use it to pass arguments defined on your custom "build-method" or Unity's build options. - The parameters must be separated by a space and must be in the format "-key value" or "-key" for booleans. + The parameters must be separated by a comma and must be in the format "-key value" or "-key" for booleans. + Example: "-customArg1 WebGL, -EnableHeadlessMode, -customArg2 build/webgl". steps: - run: diff --git a/src/jobs/build.yml b/src/jobs/build.yml index 6b2d03a..028ed8a 100755 --- a/src/jobs/build.yml +++ b/src/jobs/build.yml @@ -86,7 +86,8 @@ parameters: description: | Additional arguments for the Unity CLI. Use it to pass arguments defined on your custom "build-method" or Unity's build options. - The parameters must be separated by a space and must be in the format "-key value" or "-key" for booleans. + The parameters must be separated by a comma and must be in the format "-key value" or "-key" for booleans. + Example: "-customArg1 WebGL, -EnableHeadlessMode, -customArg2 build/webgl". executor: << parameters.executor >> diff --git a/src/scripts/build.sh b/src/scripts/build.sh index d44b919..3507d94 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -9,9 +9,12 @@ eval "$SCRIPT_UTILS" # Detect host OS. detect-os -# Copy builder to project directory. -mkdir -p "$unity_project_full_path/Assets/Editor/" -printf '%s\n' "$DEPENDENCY_UNITY_BUILDER" > "$unity_project_full_path/Assets/Editor/BuildCommand.cs" +# Copy builder to project directory if a custom isn't specified. +if [ -z "$PARAM_BUILD_METHOD" ]; then + printf '%s\n' "The \"build-method\" parameter is empty. Falling back to the default build script." + mkdir -p "$unity_project_full_path/Assets/Editor/" + printf '%s\n' "$DEPENDENCY_UNITY_BUILDER" > "$unity_project_full_path/Assets/Editor/BuildCommand.cs" +fi # If "build_name" is blank, use the build target. if [ -z "$PARAM_BUILD_NAME" ]; then PARAM_BUILD_NAME="$PARAM_BUILD_TARGET"; fi From 891c24a5eabd7caa768a43fa8e3f58c8f70be160 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 16:43:47 -0700 Subject: [PATCH 03/11] feat: add var expansion and make array available for scripts --- src/scripts/build.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/scripts/build.sh b/src/scripts/build.sh index 3507d94..0a6d2f8 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -16,6 +16,20 @@ if [ -z "$PARAM_BUILD_METHOD" ]; then printf '%s\n' "$DEPENDENCY_UNITY_BUILDER" > "$unity_project_full_path/Assets/Editor/BuildCommand.cs" fi +# Expand parameters and save them in an array. +custom_parameters=() +if [ -n "$PARAM_CUSTOM_PARAMETERS" ]; then + old_IFS=$IFS + IFS=',' + + while read params; do + param="$(eval echo $params)" + custom_parameters+=("$param") + done <<< "$PARAM_CUSTOM_PARAMETERS" + + IFS=$old_IFS +fi + # If "build_name" is blank, use the build target. if [ -z "$PARAM_BUILD_NAME" ]; then PARAM_BUILD_NAME="$PARAM_BUILD_TARGET"; fi From 8c05c2919b9afe86253e7c148e073692b5c4fd12 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 16:59:43 -0700 Subject: [PATCH 04/11] feat: add support for custom build method in macOS and Windows --- src/scripts/build.sh | 3 +++ src/scripts/macos/build.sh | 5 +++-- src/scripts/windows/build.sh | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/scripts/build.sh b/src/scripts/build.sh index 0a6d2f8..274e494 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -14,6 +14,9 @@ if [ -z "$PARAM_BUILD_METHOD" ]; then printf '%s\n' "The \"build-method\" parameter is empty. Falling back to the default build script." mkdir -p "$unity_project_full_path/Assets/Editor/" printf '%s\n' "$DEPENDENCY_UNITY_BUILDER" > "$unity_project_full_path/Assets/Editor/BuildCommand.cs" + build_method="BuildCommand.PerformBuild" +else + build_method="$PARAM_BUILD_METHOD" fi # Expand parameters and save them in an array. diff --git a/src/scripts/macos/build.sh b/src/scripts/macos/build.sh index 828dd2b..b7e2b38 100644 --- a/src/scripts/macos/build.sh +++ b/src/scripts/macos/build.sh @@ -16,9 +16,10 @@ set -x -buildTarget "$PARAM_BUILD_TARGET" \ -customBuildTarget "$PARAM_BUILD_TARGET" \ -customBuildPath "$build_path/$PARAM_BUILD_NAME" \ - -executeMethod "BuildCommand.PerformBuild" \ + -executeMethod "$build_method" \ -buildVersion "1.0.0" \ - -logfile /dev/stdout + -logfile /dev/stdout \ + "${custom_parameters[@]}" set +x if [ "$PARAM_COMPRESS" -eq 1 ]; then diff --git a/src/scripts/windows/build.sh b/src/scripts/windows/build.sh index 74e1bb0..685248c 100644 --- a/src/scripts/windows/build.sh +++ b/src/scripts/windows/build.sh @@ -22,11 +22,13 @@ docker exec "$CONTAINER_NAME" powershell mkdir C:/build # Add the build target and build name in the environment variables. docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_NAME','$PARAM_BUILD_NAME', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_TARGET','$PARAM_BUILD_TARGET', [System.EnvironmentVariableTarget]::Machine)" +docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_METHOD','$build_method', [System.EnvironmentVariableTarget]::Machine)" +docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','${custom_parameters[@]}', [System.EnvironmentVariableTarget]::Machine)" # Build the project # Versioning of the project needs work. This is how it's done in the GHA: # https://github.com/game-ci/unity-builder/blob/main/src/model/versioning.ts -docker exec "$CONTAINER_NAME" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -batchmode -quit -nographics -projectPath $Env:PROJECT_PATH -buildTarget $Env:BUILD_TARGET -customBuildTarget $Env:BUILD_TARGET -customBuildName $Env:BUILD_NAME -customBuildPath "C:/build/" -executeMethod BuildCommand.PerformBuild -logfile | Out-Host' +docker exec "$CONTAINER_NAME" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -batchmode -quit -nographics -projectPath $Env:PROJECT_PATH -buildTarget $Env:BUILD_TARGET -customBuildTarget $Env:BUILD_TARGET -customBuildName $Env:BUILD_NAME -customBuildPath "C:/build/" -executeMethod $Env:BUILD_METHOD $Env:CUSTOM_PARAMS -logfile | Out-Host' # Compress the build folder. docker exec "$CONTAINER_NAME" powershell 'tar -czf "C:/$Env:BUILD_NAME-$Env:BUILD_TARGET.tar.gz" -C "C:/build" .' From 28a19fc1327ae7c27afc822c33a8c6f8c27daea0 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 17:06:19 -0700 Subject: [PATCH 05/11] fix: shellcheck errors --- src/scripts/build.sh | 7 ++++--- src/scripts/macos/build.sh | 2 +- src/scripts/windows/build.sh | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/scripts/build.sh b/src/scripts/build.sh index 274e494..7bec4aa 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2034 readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}" readonly unity_project_full_path="$base_dir/$PARAM_PROJECT_PATH" @@ -25,9 +26,9 @@ if [ -n "$PARAM_CUSTOM_PARAMETERS" ]; then old_IFS=$IFS IFS=',' - while read params; do - param="$(eval echo $params)" - custom_parameters+=("$param") + while read -r param; do + expanded_param="$(eval echo "$param")" + custom_parameters+=("$expanded_param") done <<< "$PARAM_CUSTOM_PARAMETERS" IFS=$old_IFS diff --git a/src/scripts/macos/build.sh b/src/scripts/macos/build.sh index b7e2b38..39fa5cf 100644 --- a/src/scripts/macos/build.sh +++ b/src/scripts/macos/build.sh @@ -19,7 +19,7 @@ set -x -executeMethod "$build_method" \ -buildVersion "1.0.0" \ -logfile /dev/stdout \ - "${custom_parameters[@]}" + "${custom_parameters[*]}" set +x if [ "$PARAM_COMPRESS" -eq 1 ]; then diff --git a/src/scripts/windows/build.sh b/src/scripts/windows/build.sh index 685248c..ab47aa3 100644 --- a/src/scripts/windows/build.sh +++ b/src/scripts/windows/build.sh @@ -23,7 +23,7 @@ docker exec "$CONTAINER_NAME" powershell mkdir C:/build docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_NAME','$PARAM_BUILD_NAME', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_TARGET','$PARAM_BUILD_TARGET', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_METHOD','$build_method', [System.EnvironmentVariableTarget]::Machine)" -docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','${custom_parameters[@]}', [System.EnvironmentVariableTarget]::Machine)" +docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','${custom_parameters[*]}', [System.EnvironmentVariableTarget]::Machine)" # Build the project # Versioning of the project needs work. This is how it's done in the GHA: From eaa99b7f78b75fb00f57e51e3565ebdd7893bad9 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 17:49:16 -0700 Subject: [PATCH 06/11] test: add tests for custom params in `mac` and `windows` --- .circleci/test-deploy.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index c10fca6..3702e04 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -281,6 +281,39 @@ workflows: filters: *filters context: orb-testing-unity pre-steps: *mono + - unity/build: + name: "build-with-custom-params-windows" + step-name: "Build with custom parameters in Windows" + unity-license-var-name: "UNITY_ENCODED_LICENSE_2021" + unity-username-var-name: "UNITY_USERNAME" + unity-password-var-name: "UNITY_PASSWORD" + executor: + name: "unity/windows-2019" + size: "large" + editor_version: "2021.3.2f1" + target_platform: "windows-il2cpp" + project-path: "Unity2D-Demo-Game-CI-CD/src" + build-target: StandaloneWindows64 + custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 cucumber -DetailedBuildReport" + filters: *filters + context: orb-testing-unity + pre-steps: *mono + - unity/build: + name: "build-with-custom-params-osx" + step-name: "Build with custom parameters in macOS" + unity-license-var-name: "UNITY_ENCODED_LICENSE_2021" + unity-username-var-name: "UNITY_USERNAME" + unity-password-var-name: "UNITY_PASSWORD" + executor: + name: "unity/macos" + editor_version: "2021.3.1f1" + resource_class: "large" + project-path: "Unity2D-Demo-Game-CI-CD/src" + build-target: StandaloneOSX + custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 cucumber -DetailedBuildReport" + filters: *filters + context: orb-testing-unity + pre-steps: *il2cpp - orb-tools/pack: filters: *filters @@ -304,6 +337,8 @@ workflows: - build-ios - build-tvOS - build-without-artifacts + - build-with-custom-params-windows + - build-with-custom-params-osx context: orb-publishing filters: branches: From 42981f84bd3e3f156cabf779e1567de03a69c7bc Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 18:07:01 -0700 Subject: [PATCH 07/11] test: fix list of parameters --- .circleci/test-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 3702e04..bd36c85 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -294,7 +294,7 @@ workflows: target_platform: "windows-il2cpp" project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneWindows64 - custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 cucumber -DetailedBuildReport" + custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 cucumber, -DetailedBuildReport" filters: *filters context: orb-testing-unity pre-steps: *mono @@ -310,7 +310,7 @@ workflows: resource_class: "large" project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneOSX - custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 cucumber -DetailedBuildReport" + custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 cucumber, -DetailedBuildReport" filters: *filters context: orb-testing-unity pre-steps: *il2cpp From 9072ebb050e220a080144beff613df66a6dc6dfa Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 18:20:38 -0700 Subject: [PATCH 08/11] test: add tests for `build-method` --- .circleci/test-deploy.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index bd36c85..9796ce7 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -32,6 +32,18 @@ pre-steps: # Move the demo project to the project folder mv ../Unity2D-Demo-Game-CI-CD ./Unity2D-Demo-Game-CI-CD + custom-build-method: &custom-build-method + - run: + name: "Clone the demo project" + command: | + # Clone the demo project with custom build method + git clone --branch custom-build-method --single-branch https://github.com/EricRibeiro/Unity2D-Demo-Game-CI-CD.git ../Unity2D-Demo-Game-CI-CD + + # Clone the Unity orb + git clone https://github.com/game-ci/unity-orb.git . + + # Move the demo project to the project folder + mv ../Unity2D-Demo-Game-CI-CD ./Unity2D-Demo-Game-CI-CD workflows: test-build: @@ -282,8 +294,8 @@ workflows: context: orb-testing-unity pre-steps: *mono - unity/build: - name: "build-with-custom-params-windows" - step-name: "Build with custom parameters in Windows" + name: "build-with-custom-method-windows" + step-name: "Build with custom method in Windows" unity-license-var-name: "UNITY_ENCODED_LICENSE_2021" unity-username-var-name: "UNITY_USERNAME" unity-password-var-name: "UNITY_PASSWORD" @@ -294,13 +306,14 @@ workflows: target_platform: "windows-il2cpp" project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneWindows64 + build-method: "MyCustomBuildCommand.MyCustomBuildMethod" custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 cucumber, -DetailedBuildReport" filters: *filters context: orb-testing-unity - pre-steps: *mono + pre-steps: *custom-build-method - unity/build: - name: "build-with-custom-params-osx" - step-name: "Build with custom parameters in macOS" + name: "build-with-custom-method-osx" + step-name: "Build with custom method in macOS" unity-license-var-name: "UNITY_ENCODED_LICENSE_2021" unity-username-var-name: "UNITY_USERNAME" unity-password-var-name: "UNITY_PASSWORD" @@ -310,10 +323,11 @@ workflows: resource_class: "large" project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneOSX + build-method: "MyCustomBuildCommand.MyCustomBuildMethod" custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 cucumber, -DetailedBuildReport" filters: *filters context: orb-testing-unity - pre-steps: *il2cpp + pre-steps: *custom-build-method - orb-tools/pack: filters: *filters From a07942919b21d2951528a2c6f1d2635bd2a4dd53 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Tue, 20 Sep 2022 18:39:32 -0700 Subject: [PATCH 09/11] test: add environment variable in custom params --- .circleci/test-deploy.yml | 8 ++++---- src/scripts/build.sh | 10 ++-------- src/scripts/macos/build.sh | 5 ++--- src/scripts/windows/build.sh | 7 ++++++- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 9796ce7..00c46c1 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -307,7 +307,7 @@ workflows: project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneWindows64 build-method: "MyCustomBuildCommand.MyCustomBuildMethod" - custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 cucumber, -DetailedBuildReport" + custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 $CIRCLE_WORKFLOW_ID, -DetailedBuildReport" filters: *filters context: orb-testing-unity pre-steps: *custom-build-method @@ -324,7 +324,7 @@ workflows: project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneOSX build-method: "MyCustomBuildCommand.MyCustomBuildMethod" - custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 cucumber, -DetailedBuildReport" + custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 $CIRCLE_WORKFLOW_ID, -DetailedBuildReport" filters: *filters context: orb-testing-unity pre-steps: *custom-build-method @@ -351,8 +351,8 @@ workflows: - build-ios - build-tvOS - build-without-artifacts - - build-with-custom-params-windows - - build-with-custom-params-osx + - build-with-custom-method-windows + - build-with-custom-method-osx context: orb-publishing filters: branches: diff --git a/src/scripts/build.sh b/src/scripts/build.sh index 7bec4aa..d354fe9 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -11,27 +11,21 @@ eval "$SCRIPT_UTILS" detect-os # Copy builder to project directory if a custom isn't specified. +build_method="$PARAM_BUILD_METHOD" if [ -z "$PARAM_BUILD_METHOD" ]; then printf '%s\n' "The \"build-method\" parameter is empty. Falling back to the default build script." mkdir -p "$unity_project_full_path/Assets/Editor/" printf '%s\n' "$DEPENDENCY_UNITY_BUILDER" > "$unity_project_full_path/Assets/Editor/BuildCommand.cs" build_method="BuildCommand.PerformBuild" -else - build_method="$PARAM_BUILD_METHOD" fi # Expand parameters and save them in an array. custom_parameters=() if [ -n "$PARAM_CUSTOM_PARAMETERS" ]; then - old_IFS=$IFS - IFS=',' - - while read -r param; do + while read -r -d ',' param; do expanded_param="$(eval echo "$param")" custom_parameters+=("$expanded_param") done <<< "$PARAM_CUSTOM_PARAMETERS" - - IFS=$old_IFS fi # If "build_name" is blank, use the build target. diff --git a/src/scripts/macos/build.sh b/src/scripts/macos/build.sh index 39fa5cf..6bbbd3d 100644 --- a/src/scripts/macos/build.sh +++ b/src/scripts/macos/build.sh @@ -1,9 +1,8 @@ #!/bin/false # shellcheck shell=bash -# shellcheck disable=SC2154 +# shellcheck disable=SC2048,SC2154,SC2086 readonly build_path="$unity_project_full_path/Builds/$PARAM_BUILD_TARGET" - mkdir -p "$build_path" set -x @@ -19,7 +18,7 @@ set -x -executeMethod "$build_method" \ -buildVersion "1.0.0" \ -logfile /dev/stdout \ - "${custom_parameters[*]}" + ${custom_parameters[*]} set +x if [ "$PARAM_COMPRESS" -eq 1 ]; then diff --git a/src/scripts/windows/build.sh b/src/scripts/windows/build.sh index ab47aa3..d01e4a8 100644 --- a/src/scripts/windows/build.sh +++ b/src/scripts/windows/build.sh @@ -19,16 +19,21 @@ trap trap_exit EXIT # Create the build folder docker exec "$CONTAINER_NAME" powershell mkdir C:/build +# Parse array to string +custom_params="${custom_parameters[*]}" + # Add the build target and build name in the environment variables. docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_NAME','$PARAM_BUILD_NAME', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_TARGET','$PARAM_BUILD_TARGET', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_METHOD','$build_method', [System.EnvironmentVariableTarget]::Machine)" -docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','${custom_parameters[*]}', [System.EnvironmentVariableTarget]::Machine)" +docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','$custom_params', [System.EnvironmentVariableTarget]::Machine)" # Build the project # Versioning of the project needs work. This is how it's done in the GHA: # https://github.com/game-ci/unity-builder/blob/main/src/model/versioning.ts +set -x docker exec "$CONTAINER_NAME" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -batchmode -quit -nographics -projectPath $Env:PROJECT_PATH -buildTarget $Env:BUILD_TARGET -customBuildTarget $Env:BUILD_TARGET -customBuildName $Env:BUILD_NAME -customBuildPath "C:/build/" -executeMethod $Env:BUILD_METHOD $Env:CUSTOM_PARAMS -logfile | Out-Host' +set +x # Compress the build folder. docker exec "$CONTAINER_NAME" powershell 'tar -czf "C:/$Env:BUILD_NAME-$Env:BUILD_TARGET.tar.gz" -C "C:/build" .' From 44662ad39e2c3e7f5e07c3960efaf8897e2eca62 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Wed, 21 Sep 2022 10:46:39 -0700 Subject: [PATCH 10/11] refactor: change separator from comma to space --- .circleci/test-deploy.yml | 4 ++-- src/commands/build.yml | 6 +++--- src/jobs/build.yml | 6 +++--- src/scripts/build.sh | 10 ++-------- src/scripts/macos/build.sh | 2 +- src/scripts/windows/build.sh | 9 +++------ 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 00c46c1..c213b9d 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -307,7 +307,7 @@ workflows: project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneWindows64 build-method: "MyCustomBuildCommand.MyCustomBuildMethod" - custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 $CIRCLE_WORKFLOW_ID, -DetailedBuildReport" + custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 $CIRCLE_WORKFLOW_ID -DetailedBuildReport" filters: *filters context: orb-testing-unity pre-steps: *custom-build-method @@ -324,7 +324,7 @@ workflows: project-path: "Unity2D-Demo-Game-CI-CD/src" build-target: StandaloneOSX build-method: "MyCustomBuildCommand.MyCustomBuildMethod" - custom-parameters: "-customParam1 potato, -customParam2 tomato, -customParam3 $CIRCLE_WORKFLOW_ID, -DetailedBuildReport" + custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 $CIRCLE_WORKFLOW_ID -DetailedBuildReport" filters: *filters context: orb-testing-unity pre-steps: *custom-build-method diff --git a/src/commands/build.yml b/src/commands/build.yml index b6d2532..041e98c 100644 --- a/src/commands/build.yml +++ b/src/commands/build.yml @@ -63,9 +63,9 @@ parameters: default: "" description: | Additional arguments for the Unity CLI. - Use it to pass arguments defined on your custom "build-method" or Unity's build options. - The parameters must be separated by a comma and must be in the format "-key value" or "-key" for booleans. - Example: "-customArg1 WebGL, -EnableHeadlessMode, -customArg2 build/webgl". + Use it to pass arguments defined on your custom "build-method" or Unity's build options. Environment variables are supported. + The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans. + Example: "-customArg1 WebGL -EnableHeadlessMode -customArg2 $CIRCLE_WORKFLOW_ID". steps: - run: diff --git a/src/jobs/build.yml b/src/jobs/build.yml index 028ed8a..9e3d49d 100755 --- a/src/jobs/build.yml +++ b/src/jobs/build.yml @@ -85,9 +85,9 @@ parameters: default: "" description: | Additional arguments for the Unity CLI. - Use it to pass arguments defined on your custom "build-method" or Unity's build options. - The parameters must be separated by a comma and must be in the format "-key value" or "-key" for booleans. - Example: "-customArg1 WebGL, -EnableHeadlessMode, -customArg2 build/webgl". + Use it to pass arguments defined on your custom "build-method" or Unity's build options. Environment variables are supported. + The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans. + Example: "-customArg1 WebGL -EnableHeadlessMode -customArg2 $CIRCLE_WORKFLOW_ID". executor: << parameters.executor >> diff --git a/src/scripts/build.sh b/src/scripts/build.sh index d354fe9..89e2327 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -19,14 +19,8 @@ if [ -z "$PARAM_BUILD_METHOD" ]; then build_method="BuildCommand.PerformBuild" fi -# Expand parameters and save them in an array. -custom_parameters=() -if [ -n "$PARAM_CUSTOM_PARAMETERS" ]; then - while read -r -d ',' param; do - expanded_param="$(eval echo "$param")" - custom_parameters+=("$expanded_param") - done <<< "$PARAM_CUSTOM_PARAMETERS" -fi +# Expand custom parameters, if any. +custom_parameters="$(eval echo "$PARAM_CUSTOM_PARAMETERS")" # If "build_name" is blank, use the build target. if [ -z "$PARAM_BUILD_NAME" ]; then PARAM_BUILD_NAME="$PARAM_BUILD_TARGET"; fi diff --git a/src/scripts/macos/build.sh b/src/scripts/macos/build.sh index 6bbbd3d..3501d39 100644 --- a/src/scripts/macos/build.sh +++ b/src/scripts/macos/build.sh @@ -18,7 +18,7 @@ set -x -executeMethod "$build_method" \ -buildVersion "1.0.0" \ -logfile /dev/stdout \ - ${custom_parameters[*]} + $custom_parameters # Needs to be unquoted. Otherwise it will be treated as a single parameter. set +x if [ "$PARAM_COMPRESS" -eq 1 ]; then diff --git a/src/scripts/windows/build.sh b/src/scripts/windows/build.sh index d01e4a8..f799c8f 100644 --- a/src/scripts/windows/build.sh +++ b/src/scripts/windows/build.sh @@ -19,24 +19,21 @@ trap trap_exit EXIT # Create the build folder docker exec "$CONTAINER_NAME" powershell mkdir C:/build -# Parse array to string -custom_params="${custom_parameters[*]}" - # Add the build target and build name in the environment variables. docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_NAME','$PARAM_BUILD_NAME', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_TARGET','$PARAM_BUILD_TARGET', [System.EnvironmentVariableTarget]::Machine)" docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_METHOD','$build_method', [System.EnvironmentVariableTarget]::Machine)" -docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','$custom_params', [System.EnvironmentVariableTarget]::Machine)" +docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','$custom_parameters', [System.EnvironmentVariableTarget]::Machine)" # Build the project # Versioning of the project needs work. This is how it's done in the GHA: # https://github.com/game-ci/unity-builder/blob/main/src/model/versioning.ts set -x -docker exec "$CONTAINER_NAME" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -batchmode -quit -nographics -projectPath $Env:PROJECT_PATH -buildTarget $Env:BUILD_TARGET -customBuildTarget $Env:BUILD_TARGET -customBuildName $Env:BUILD_NAME -customBuildPath "C:/build/" -executeMethod $Env:BUILD_METHOD $Env:CUSTOM_PARAMS -logfile | Out-Host' +docker exec "$CONTAINER_NAME" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -batchmode -quit -nographics -projectPath $Env:PROJECT_PATH -buildTarget $Env:BUILD_TARGET -customBuildTarget $Env:BUILD_TARGET -customBuildName $Env:BUILD_NAME -customBuildPath "C:/build/" -executeMethod $Env:BUILD_METHOD $Env:CUSTOM_PARAMS.split() -logfile | Out-Host' set +x # Compress the build folder. docker exec "$CONTAINER_NAME" powershell 'tar -czf "C:/$Env:BUILD_NAME-$Env:BUILD_TARGET.tar.gz" -C "C:/build" .' # Copy the build directory to the host. -docker cp "$CONTAINER_NAME":"$PARAM_BUILD_NAME"-"$PARAM_BUILD_TARGET".tar.gz "$base_dir"/"$PARAM_BUILD_TARGET".tar.gz +docker cp "$CONTAINER_NAME":"$PARAM_BUILD_NAME"-"$PARAM_BUILD_TARGET".tar.gz "$base_dir"/"$PARAM_BUILD_TARGET".tar.gz \ No newline at end of file From c08d1b847c7725a5571aba96efb82e1a66c34797 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Thu, 22 Sep 2022 15:06:23 -0700 Subject: [PATCH 11/11] chore: add newline at the end of the file --- src/scripts/windows/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/windows/build.sh b/src/scripts/windows/build.sh index f799c8f..fc2428d 100644 --- a/src/scripts/windows/build.sh +++ b/src/scripts/windows/build.sh @@ -36,4 +36,4 @@ set +x docker exec "$CONTAINER_NAME" powershell 'tar -czf "C:/$Env:BUILD_NAME-$Env:BUILD_TARGET.tar.gz" -C "C:/build" .' # Copy the build directory to the host. -docker cp "$CONTAINER_NAME":"$PARAM_BUILD_NAME"-"$PARAM_BUILD_TARGET".tar.gz "$base_dir"/"$PARAM_BUILD_TARGET".tar.gz \ No newline at end of file +docker cp "$CONTAINER_NAME":"$PARAM_BUILD_NAME"-"$PARAM_BUILD_TARGET".tar.gz "$base_dir"/"$PARAM_BUILD_TARGET".tar.gz