Skip to content

Commit a9489e1

Browse files
authored
feat: decouple Linux's build command from GitLab and introduce new 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
1 parent b737a31 commit a9489e1

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

.circleci/test-deploy.yml

+20
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,25 @@ workflows:
328328
filters: *filters
329329
context: orb-testing-unity
330330
pre-steps: *custom-build-method
331+
- unity/build:
332+
name: "build-with-custom-method-linux"
333+
step-name: "Build with custom method in Linux"
334+
unity-license-var-name: "UNITY_ENCODED_LICENSE_2021"
335+
unity-username-var-name: "UNITY_USERNAME"
336+
unity-password-var-name: "UNITY_PASSWORD"
337+
executor:
338+
name: "unity/ubuntu"
339+
target_platform: "linux-il2cpp"
340+
editor_version: "2021.3.1f1"
341+
resource_class: "large"
342+
project-path: "Unity2D-Demo-Game-CI-CD/src"
343+
build-target: StandaloneLinux64
344+
build-method: "MyCustomBuildCommand.MyCustomBuildMethod"
345+
custom-parameters: "-customParam1 potato -customParam2 tomato -customParam3 $CIRCLE_WORKFLOW_ID -DetailedBuildReport"
346+
compress: true
347+
filters: *filters
348+
context: orb-testing-unity
349+
pre-steps: *custom-build-method
331350

332351
- orb-tools/pack:
333352
filters: *filters
@@ -353,6 +372,7 @@ workflows:
353372
- build-without-artifacts
354373
- build-with-custom-method-windows
355374
- build-with-custom-method-osx
375+
- build-with-custom-method-linux
356376
context: orb-publishing
357377
filters:
358378
branches:

src/scripts/linux/build.sh

+26-46
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,28 @@
11
#!/bin/false
22
# shellcheck shell=bash
3-
# shellcheck disable=SC2154
4-
5-
trap_build_script_exit() {
6-
exit_status="$?"
7-
8-
# The build script has a "set -x" on it. This will disable it for the rest of the run.
9-
set +x
10-
11-
if [ "$exit_status" -ne 0 ]; then
12-
printf '%s\n' 'The script did not complete successfully.'
13-
printf '%s\n' "The exit code was $exit_status"
14-
exit "$exit_status"
15-
fi
16-
17-
if [ "$PARAM_COMPRESS" -eq 1 ]; then
18-
printf '%s\n' 'Compressing build artifacts...'
19-
20-
# Compress artifacts to store them in the artifacts bucket.
21-
tar -czf "$base_dir/$PARAM_BUILD_TARGET.tar.gz" -C "$unity_project_full_path/Builds/$PARAM_BUILD_TARGET" .
22-
fi
23-
}
24-
25-
# Download build script.
26-
curl --silent --location \
27-
--request GET \
28-
--url "https://gitlab.com/game-ci/unity3d-gitlab-ci-example/-/raw/main/ci/build.sh" \
29-
--header 'Accept: application/vnd.github.v3+json' \
30-
--output "$base_dir/build.sh"
31-
32-
chmod +x "$base_dir/build.sh"
33-
34-
# Name variables as required by the "build.sh" script.
35-
readonly BUILD_NAME="$PARAM_BUILD_NAME"
36-
readonly BUILD_TARGET="$PARAM_BUILD_TARGET"
37-
readonly UNITY_DIR="$unity_project_full_path"
38-
39-
export BUILD_NAME
40-
export BUILD_TARGET
41-
export UNITY_DIR
42-
43-
# Trap "build.sh" exit otherwise it won't be possible to zip the artifacts.
44-
trap trap_build_script_exit EXIT
45-
46-
# Run the build script.
47-
# shellcheck source=/dev/null
48-
source "$base_dir/build.sh"
3+
# shellcheck disable=SC2048,SC2154,SC2086
4+
5+
readonly build_path="$unity_project_full_path/Builds/$PARAM_BUILD_TARGET/"
6+
mkdir -p "$build_path"
7+
8+
set -x
9+
${UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
10+
-projectPath "$unity_project_full_path" \
11+
-quit \
12+
-batchmode \
13+
-nographics \
14+
-buildTarget "$PARAM_BUILD_TARGET" \
15+
-customBuildTarget "$PARAM_BUILD_TARGET" \
16+
-customBuildName "$PARAM_BUILD_NAME" \
17+
-customBuildPath "$build_path" \
18+
-executeMethod "$build_method" \
19+
-logFile /dev/stdout \
20+
$custom_parameters # Needs to be unquoted. Otherwise it will be treated as a single parameter.
21+
set +x
22+
23+
if [ "$PARAM_COMPRESS" -eq 1 ]; then
24+
printf '%s\n' 'Compressing build artifacts...'
25+
26+
# Compress artifacts to store them in the artifacts bucket.
27+
tar -czf "$base_dir/$PARAM_BUILD_TARGET.tar.gz" -C "$build_path" .
28+
fi

0 commit comments

Comments
 (0)