Skip to content

Commit

Permalink
Hotfix: Download before_script file from gitlab ref and freeze to v3.…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
GabLeRoux and coderabbitai[bot] authored Nov 25, 2024
1 parent a1ddf09 commit f0b6ce5
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions src/scripts/linux/prepare-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ resolve_unity_license() {
fi

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

Expand All @@ -54,6 +54,40 @@ resolve_unity_license() {
fi
}

download_and_prepare_before_script() {
local repo_url="$1"
local ref="$2"
local file_path="$3"
local output_path="$4"

# Validate input parameters
if [[ -z "$repo_url" || -z "$ref" || -z "$file_path" || -z "$output_path" ]]; then
printf 'Error: Missing required parameters\n' >&2
return 1
fi

# Construct the full URL
local full_url="$repo_url/-/raw/$ref/$file_path"

# Use curl to download the file
curl --silent --location \
--request GET \
--url "$full_url" \
--output "$output_path" \
--fail \
|| { printf 'Error: Failed to download script from %s\n' "$full_url" >&2; return 1; }

# Verify downloaded file
if [[ ! -s "$output_path" ]]; then
printf 'Error: Downloaded file is empty or missing\n' >&2
return 1
fi

# Make the script executable
chmod +x "$output_path"
return 0
}

# Check if serial or encoded license was provided.
# If the latter, extract the serial from the license.
if ! resolve_unity_license; then
Expand All @@ -62,14 +96,14 @@ if ! resolve_unity_license; then
exit 1
fi

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

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

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

# Run the test script.
# shellcheck source=/dev/null
source "$base_dir/before_script.sh"
source "$before_script"

0 comments on commit f0b6ce5

Please sign in to comment.