From 00f08702d8ac9e792a9a8796a23cbb93f88ce454 Mon Sep 17 00:00:00 2001 From: ltrubbiani Date: Wed, 8 Jan 2025 13:53:20 +0100 Subject: [PATCH 1/2] feat: add http single file download and branch support for git --- core-builder-tool/builder-tool.sh | 37 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/core-builder-tool/builder-tool.sh b/core-builder-tool/builder-tool.sh index 9a075a10..be0ed54b 100755 --- a/core-builder-tool/builder-tool.sh +++ b/core-builder-tool/builder-tool.sh @@ -186,6 +186,18 @@ if [ -f "$source_dir/context-refs.txt" ]; then password=$GIT_PASSWORD token=$GIT_TOKEN + # Extract branch if specified as a fragment (#branch) + branch="${rebuilt_url##*#}" + repo="${rebuilt_url%#*}" + + # Check if a branch is specified + if [[ "$repo" != "$rebuilt_url" ]]; then + echo "Branch specified: $branch" + else + branch="" # No branch specified + repo="$rebuilt_url" + fi + # Construct Git clone URL based on available authentication credentials if [ -n "$token" ]; then if [[ $token == github_pat_* || $token == glpat* ]]; then @@ -195,11 +207,18 @@ if [ -f "$source_dir/context-refs.txt" ]; then username="$token" password="x-oauth-basic" fi - git clone "https://$username:$password@$rebuilt_url" "$tmp_dir" + clone_url="https://$username:$password@$repo" elif [ -n "$username" ] && [ -n "$password" ]; then - git clone "https://$username:$password@$rebuilt_url" "$tmp_dir" + clone_url="https://$username:$password@$repo" + else + clone_url="https://$repo" + fi + + # Clone repository with or without branch + if [ -n "$branch" ]; then + git clone --branch "$branch" "$clone_url" "$tmp_dir" else - git clone "https://$rebuilt_url" "$tmp_dir" + git clone "$clone_url" "$tmp_dir" fi # copy temp in destination_dir @@ -210,7 +229,7 @@ if [ -f "$source_dir/context-refs.txt" ]; then echo "========= Files in shared dir =========" ls -l "$destination_dir" - # remove temp + # Remove temp echo "========= Removing $tmp_dir =========" rm -rf "$tmp_dir" @@ -225,11 +244,19 @@ if [ -f "$source_dir/context-refs.txt" ]; then unzip "$destination_dir/$destination" -d "$destination_dir" ;; "zip+http" | "zip+https") # for now accept only zip file - check if file is a zip. unpack zip + echo "Protocol: $protocol" + # strip zip+ + stripped_source="${source#zip+}" + echo "Downloading $stripped_source" + echo "to $destination_dir/$destination" + curl -o "$destination_dir/$destination" -L "$stripped_source" + unzip "$destination_dir/$destination" -d "$destination_dir" + ;; + "http") echo "Protocol: $protocol" echo "Downloading $source" echo "to $destination_dir/$destination" curl -o "$destination_dir/$destination" -L "$source" - unzip "$destination_dir/$destination" -d "$destination_dir" ;; "s3") # for now accept a folder/path mc alias set $minio $S3_ENDPOINT_URL $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY From 5fca46ef42ab85890a3fcd2248e311d3df715258 Mon Sep 17 00:00:00 2001 From: ltrubbiani Date: Mon, 13 Jan 2025 11:02:11 +0100 Subject: [PATCH 2/2] fix: add https --- core-builder-tool/builder-tool.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-builder-tool/builder-tool.sh b/core-builder-tool/builder-tool.sh index be0ed54b..c1b2178e 100755 --- a/core-builder-tool/builder-tool.sh +++ b/core-builder-tool/builder-tool.sh @@ -252,7 +252,7 @@ if [ -f "$source_dir/context-refs.txt" ]; then curl -o "$destination_dir/$destination" -L "$stripped_source" unzip "$destination_dir/$destination" -d "$destination_dir" ;; - "http") + "http" | "https") echo "Protocol: $protocol" echo "Downloading $source" echo "to $destination_dir/$destination"