Skip to content

Commit f0b6ce5

Browse files
Hotfix: Download before_script file from gitlab ref and freeze to v3.0.1 (#82)
* Download and prepare before_script file from gitlab ref * Update ref to "7fc1c95" in prepare-env.sh to get retry logic * Update src/scripts/linux/prepare-env.sh Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update reference to version v3.0.1 closes #85 --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a1ddf09 commit f0b6ce5

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/scripts/linux/prepare-env.sh

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ resolve_unity_license() {
4242
fi
4343

4444
else
45-
printf '%s\n' "If you own a Personal Unity License File (.ulf), please provide it as a base64 encoded string."
45+
printf '%s\n' "If you own a Personal Unity License File (.ulf), please provide it as a base64 encoded string."
4646
printf '%s\n' "If you own a Plus or Pro Unity license, please provide your username, password and serial."
4747
printf '%s\n' "See the docs for more details: https://game.ci/docs/circleci/activation"
4848

@@ -54,6 +54,40 @@ resolve_unity_license() {
5454
fi
5555
}
5656

57+
download_and_prepare_before_script() {
58+
local repo_url="$1"
59+
local ref="$2"
60+
local file_path="$3"
61+
local output_path="$4"
62+
63+
# Validate input parameters
64+
if [[ -z "$repo_url" || -z "$ref" || -z "$file_path" || -z "$output_path" ]]; then
65+
printf 'Error: Missing required parameters\n' >&2
66+
return 1
67+
fi
68+
69+
# Construct the full URL
70+
local full_url="$repo_url/-/raw/$ref/$file_path"
71+
72+
# Use curl to download the file
73+
curl --silent --location \
74+
--request GET \
75+
--url "$full_url" \
76+
--output "$output_path" \
77+
--fail \
78+
|| { printf 'Error: Failed to download script from %s\n' "$full_url" >&2; return 1; }
79+
80+
# Verify downloaded file
81+
if [[ ! -s "$output_path" ]]; then
82+
printf 'Error: Downloaded file is empty or missing\n' >&2
83+
return 1
84+
fi
85+
86+
# Make the script executable
87+
chmod +x "$output_path"
88+
return 0
89+
}
90+
5791
# Check if serial or encoded license was provided.
5892
# If the latter, extract the serial from the license.
5993
if ! resolve_unity_license; then
@@ -62,14 +96,14 @@ if ! resolve_unity_license; then
6296
exit 1
6397
fi
6498

65-
# Download before_script.sh from GameCI.
66-
curl --silent --location \
67-
--request GET \
68-
--url "https://gitlab.com/game-ci/unity3d-gitlab-ci-example/-/raw/main/ci/before_script.sh" \
69-
--header 'Accept: application/vnd.github.v3+json' \
70-
--output "$base_dir/before_script.sh"
99+
# Define variables
100+
repo_url="https://gitlab.com/game-ci/unity3d-gitlab-ci-example"
101+
ref="173a67e" # v3.0.1
102+
file_path="ci/before_script.sh"
103+
before_script="$base_dir/before_script.sh"
71104

72-
chmod +x "$base_dir/before_script.sh"
105+
# Download and prepare the before_script file
106+
download_and_prepare_before_script "$repo_url" "$ref" "$file_path" "$before_script"
73107

74108
# Nomenclature required by the script.
75109
readonly UNITY_LICENSE="$unity_license"
@@ -78,4 +112,4 @@ export UNITY_LICENSE
78112

79113
# Run the test script.
80114
# shellcheck source=/dev/null
81-
source "$base_dir/before_script.sh"
115+
source "$before_script"

0 commit comments

Comments
 (0)