Skip to content

Commit

Permalink
feat: decouple Linux's build command from GitLab and introduce new …
Browse files Browse the repository at this point in the history
…features (#37)

* feat: decouple `build` from GitLab and add custom `executeMethod`

* fix: artifacts compression

* fix: add forward slash at the end of build path

* refactor: add new line at the end of the file
  • Loading branch information
EricRibeiro authored Sep 23, 2022
1 parent b737a31 commit a9489e1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
20 changes: 20 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,25 @@ workflows:
filters: *filters
context: orb-testing-unity
pre-steps: *custom-build-method
- unity/build:
name: "build-with-custom-method-linux"
step-name: "Build with custom method in Linux"
unity-license-var-name: "UNITY_ENCODED_LICENSE_2021"
unity-username-var-name: "UNITY_USERNAME"
unity-password-var-name: "UNITY_PASSWORD"
executor:
name: "unity/ubuntu"
target_platform: "linux-il2cpp"
editor_version: "2021.3.1f1"
resource_class: "large"
project-path: "Unity2D-Demo-Game-CI-CD/src"
build-target: StandaloneLinux64
build-method: "MyCustomBuildCommand.MyCustomBuildMethod"
custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 $CIRCLE_WORKFLOW_ID -DetailedBuildReport"
compress: true
filters: *filters
context: orb-testing-unity
pre-steps: *custom-build-method

- orb-tools/pack:
filters: *filters
Expand All @@ -353,6 +372,7 @@ workflows:
- build-without-artifacts
- build-with-custom-method-windows
- build-with-custom-method-osx
- build-with-custom-method-linux
context: orb-publishing
filters:
branches:
Expand Down
72 changes: 26 additions & 46 deletions src/scripts/linux/build.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,28 @@
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154

trap_build_script_exit() {
exit_status="$?"

# The build script has a "set -x" on it. This will disable it for the rest of the run.
set +x

if [ "$exit_status" -ne 0 ]; then
printf '%s\n' 'The script did not complete successfully.'
printf '%s\n' "The exit code was $exit_status"
exit "$exit_status"
fi

if [ "$PARAM_COMPRESS" -eq 1 ]; then
printf '%s\n' 'Compressing build artifacts...'

# Compress artifacts to store them in the artifacts bucket.
tar -czf "$base_dir/$PARAM_BUILD_TARGET.tar.gz" -C "$unity_project_full_path/Builds/$PARAM_BUILD_TARGET" .
fi
}

# Download build script.
curl --silent --location \
--request GET \
--url "https://gitlab.com/game-ci/unity3d-gitlab-ci-example/-/raw/main/ci/build.sh" \
--header 'Accept: application/vnd.github.v3+json' \
--output "$base_dir/build.sh"

chmod +x "$base_dir/build.sh"

# Name variables as required by the "build.sh" script.
readonly BUILD_NAME="$PARAM_BUILD_NAME"
readonly BUILD_TARGET="$PARAM_BUILD_TARGET"
readonly UNITY_DIR="$unity_project_full_path"

export BUILD_NAME
export BUILD_TARGET
export UNITY_DIR

# Trap "build.sh" exit otherwise it won't be possible to zip the artifacts.
trap trap_build_script_exit EXIT

# Run the build script.
# shellcheck source=/dev/null
source "$base_dir/build.sh"
# shellcheck disable=SC2048,SC2154,SC2086

readonly build_path="$unity_project_full_path/Builds/$PARAM_BUILD_TARGET/"
mkdir -p "$build_path"

set -x
${UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
-projectPath "$unity_project_full_path" \
-quit \
-batchmode \
-nographics \
-buildTarget "$PARAM_BUILD_TARGET" \
-customBuildTarget "$PARAM_BUILD_TARGET" \
-customBuildName "$PARAM_BUILD_NAME" \
-customBuildPath "$build_path" \
-executeMethod "$build_method" \
-logFile /dev/stdout \
$custom_parameters # Needs to be unquoted. Otherwise it will be treated as a single parameter.
set +x

if [ "$PARAM_COMPRESS" -eq 1 ]; then
printf '%s\n' 'Compressing build artifacts...'

# Compress artifacts to store them in the artifacts bucket.
tar -czf "$base_dir/$PARAM_BUILD_TARGET.tar.gz" -C "$build_path" .
fi

0 comments on commit a9489e1

Please sign in to comment.