From 38be959d72c24f37ec44a7bd8525efe8de421df0 Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Tue, 4 Feb 2025 13:03:31 -0800 Subject: [PATCH 1/4] modify go vendor cache script --- toolkit/scripts/build_go_vendor_cache.sh | 115 +++++++++++++++++++---- 1 file changed, 99 insertions(+), 16 deletions(-) diff --git a/toolkit/scripts/build_go_vendor_cache.sh b/toolkit/scripts/build_go_vendor_cache.sh index 7275859bc74..795a9b601d6 100755 --- a/toolkit/scripts/build_go_vendor_cache.sh +++ b/toolkit/scripts/build_go_vendor_cache.sh @@ -2,8 +2,92 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +# Quit on failure set -e +PKG_VERSION="" +SRC_TARBALL="" +OUT_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# parameters: +# +# --srcTarball : src tarball file +# this file contains the 'initial' source code of the component +# and should be replaced with the new/modified src code +# --outFolder : folder where to copy the new tarball(s) +# --pkgVersion : package version +# --vendorVersion : vendor version +# +PARAMS="" +while (( "$#" )); do + case "$1" in + --srcTarball) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + SRC_TARBALL=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + --outFolder) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + OUT_FOLDER=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + --pkgVersion) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + PKG_VERSION=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + --vendorVersion) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + VENDOR_VERSION=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + -*|--*=) # unsupported flags + echo "Error: Unsupported flag $1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done + +if [ -z "$SRC_TARBALL" ]; then + echo "--srcTarball parameter cannot be empty" + exit 1 +fi + +if [ -z "$PKG_VERSION" ]; then + echo "--pkgVersion parameter cannot be empty" + exit 1 +fi + +if [ -z "$VENDOR_VERSION" ]; then + echo "--vendorVersion parameter cannot be empty" + exit 1 +fi + +echo "--srcTarball -> $SRC_TARBALL" +echo "--outFolder -> $OUT_FOLDER" +echo "--pkgVersion -> $PKG_VERSION" +echo "--vendorVersion -> $VENDOR_VERSION" + temp_dir=$(mktemp -d) echo "Working in temporary directory '$temp_dir'." function clean-up { @@ -12,7 +96,7 @@ function clean-up { } trap clean-up EXIT -tarball_name=$1 +tarball_name=$(basename "$SRC_TARBALL") cache_name=${tarball_name%.*} if [[ "$cache_name" =~ \.tar$ ]] @@ -20,18 +104,12 @@ then cache_name=${cache_name%.*} fi -cache_tarball_name="$cache_name-vendor.tar.gz" - -if [[ $# -ge 2 ]] -then - directory_name=$2 -else - directory_name=$cache_name -fi +cache_tarball_name="$cache_name-$PKG_VERSION-govendor-v$VENDOR_VERSION.tar.gz" +directory_name="$cache_name" if [[ -f "$tarball_name" ]] then - cp "$tarball_name" "$temp_dir" + cp "$SRC_TARBALL" "$temp_dir" else echo "Tarball '$tarball_name' doesn't exist. Will attempt to download from blobstorage." if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$tarball_name" -O "$temp_dir/$tarball_name" @@ -43,19 +121,24 @@ else fi pushd "$temp_dir" &> /dev/null - echo "Extracting $tarball_name." - tar -xf "$tarball_name" + echo "Extracting $SRC_TARBALL." + + tar -xf "$SRC_TARBALL" pushd "$directory_name" &> /dev/null - echo "Fetching dependencies to a temporary cache." + echo "Fetching dependencies to a temporary cache in $directory_name." go mod vendor echo "Compressing the cache." - tar --sort=name --mtime="2021-04-26 00:00Z" --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime -cf "$cache_tarball_name" vendor + tar --sort=name \ + --mtime="2021-04-26 00:00Z" \ + --owner=0 --group=0 --numeric-owner \ + --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \ + -czf "$cache_tarball_name" vendor popd &> /dev/null popd &> /dev/null -mv "$temp_dir/$directory_name/$cache_tarball_name" . +mv "$temp_dir/$directory_name/$cache_tarball_name" "$OUT_FOLDER" echo "Done:" -sha256sum "$cache_tarball_name" +sha256sum "$OUT_FOLDER"/"$cache_tarball_name" From ba5203233664ccf520ae500ba6b2730ec98f776a Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Tue, 4 Feb 2025 13:22:25 -0800 Subject: [PATCH 2/4] search for directory --- toolkit/scripts/build_go_vendor_cache.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/toolkit/scripts/build_go_vendor_cache.sh b/toolkit/scripts/build_go_vendor_cache.sh index 795a9b601d6..e375604ba9c 100755 --- a/toolkit/scripts/build_go_vendor_cache.sh +++ b/toolkit/scripts/build_go_vendor_cache.sh @@ -105,7 +105,6 @@ then fi cache_tarball_name="$cache_name-$PKG_VERSION-govendor-v$VENDOR_VERSION.tar.gz" -directory_name="$cache_name" if [[ -f "$tarball_name" ]] then @@ -124,7 +123,12 @@ pushd "$temp_dir" &> /dev/null echo "Extracting $SRC_TARBALL." tar -xf "$SRC_TARBALL" - + + directory_name=($(ls -d */)) + + # assume there is only one directory in the tarball + directory_name=${directory_name[0]%//} + pushd "$directory_name" &> /dev/null echo "Fetching dependencies to a temporary cache in $directory_name." go mod vendor From 884b47ec9f050b738ce0ae5e532c05551056eba2 Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Tue, 4 Feb 2025 13:54:18 -0800 Subject: [PATCH 3/4] using the tarball name --- toolkit/scripts/build_go_vendor_cache.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/scripts/build_go_vendor_cache.sh b/toolkit/scripts/build_go_vendor_cache.sh index e375604ba9c..50bbfab6e01 100755 --- a/toolkit/scripts/build_go_vendor_cache.sh +++ b/toolkit/scripts/build_go_vendor_cache.sh @@ -122,7 +122,7 @@ fi pushd "$temp_dir" &> /dev/null echo "Extracting $SRC_TARBALL." - tar -xf "$SRC_TARBALL" + tar -xf "$tarball_name" directory_name=($(ls -d */)) From 73b40ea80f0c6c1dd3fe7e87ccdc631f410369ad Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Tue, 4 Feb 2025 13:54:37 -0800 Subject: [PATCH 4/4] updating message --- toolkit/scripts/build_go_vendor_cache.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/scripts/build_go_vendor_cache.sh b/toolkit/scripts/build_go_vendor_cache.sh index 50bbfab6e01..3e6c006fb82 100755 --- a/toolkit/scripts/build_go_vendor_cache.sh +++ b/toolkit/scripts/build_go_vendor_cache.sh @@ -120,7 +120,7 @@ else fi pushd "$temp_dir" &> /dev/null - echo "Extracting $SRC_TARBALL." + echo "Extracting $tarball_name." tar -xf "$tarball_name"