From 1569faa33622710e06567a9e66e7cef35a02ba43 Mon Sep 17 00:00:00 2001 From: jesperancinha Date: Sun, 15 Sep 2024 20:38:01 +0200 Subject: [PATCH] updates plugins one --- pluginUpdatesOne.sh | 78 ++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/pluginUpdatesOne.sh b/pluginUpdatesOne.sh index ed86cf3..41d2de6 100755 --- a/pluginUpdatesOne.sh +++ b/pluginUpdatesOne.sh @@ -26,37 +26,65 @@ pluginsReplaceArr[${pluginsArr[6]}]=${pluginsArr[6]} pluginsReplaceArr[${pluginsArr[7]}]="github/codeql-action/init github/codeql-action/autobuild github/codeql-action/analyze" pluginsReplaceArr[${pluginsArr[8]}]=${pluginsArr[8]} -for plugin in "${pluginsArr[@]}"; do +if [ "$#" -eq 8 ]; then + declare -A versions + versions[${pluginsArr[0]}]=$1 + versions[${pluginsArr[1]}]=$2 + versions[${pluginsArr[2]}]=$3 + versions[${pluginsArr[3]}]=$4 + versions[${pluginsArr[4]}]=$5 + versions[${pluginsArr[5]}]=$6 + versions[${pluginsArr[6]}]=$7 + versions[${pluginsArr[7]}]=$8 + versions[${pluginsArr[8]}]=$9 + for plugin in "${pluginsArr[@]}"; do + tag=$(echo $plugin | awk -F"$separator" '{print $1}') + name=$(echo $plugin | awk -F"$separator" '{print substr($0, index($0,$2))}') + echo "$tag"/"$name" + pluginSegments=${pluginsReplaceArr[$plugin]} + for pluginSement in $pluginSegments; do + tag=$(echo "$pluginSement" | awk -F"$separator" '{print $1}') + name=$(echo "$pluginSement" | awk -F"$separator" '{print substr($0, index($0,$2))}') + name=${name//\//\\/} + echo "$tag"/"$name" + version=${versions[${plugin}]} + arr["$tag\/$name@v[0-9\.]*"]="$tag\/$name@$version" + echo "Will replace $tag\/$name@v[0-9]* with $tag\/$name@$version" + done + done +else + for plugin in "${pluginsArr[@]}"; do + tag=$(echo $plugin | awk -F"$separator" '{print $1}') + name=$(echo $plugin | awk -F"$separator" '{print substr($0, index($0,$2))}') + echo "$tag"/"$name" - tag=$(echo $plugin | awk -F"$separator" '{print $1}') - name=$(echo $plugin | awk -F"$separator" '{print substr($0, index($0,$2))}') - echo "$tag"/"$name" - versionUrl="https://api.github.com/repos/"$tag"/"$name"/tags" - echo "Performing GET request to $versionUrl" - sleep 1 - result=$(curl -s $versionUrl) - echo "$result" + versionUrl="https://api.github.com/repos/"$tag"/"$name"/tags" + echo "Performing GET request to $versionUrl" + sleep 1 + result=$(curl -s $versionUrl) + echo "$result" - pluginSegments=${pluginsReplaceArr[$plugin]} - for pluginSement in $pluginSegments; do - tag=$(echo "$pluginSement" | awk -F"$separator" '{print $1}') - name=$(echo "$pluginSement" | awk -F"$separator" '{print substr($0, index($0,$2))}') - name=${name//\//\\/} - echo "$tag"/"$name" + pluginSegments=${pluginsReplaceArr[$plugin]} + for pluginSement in $pluginSegments; do + tag=$(echo "$pluginSement" | awk -F"$separator" '{print $1}') + name=$(echo "$pluginSement" | awk -F"$separator" '{print substr($0, index($0,$2))}') + name=${name//\//\\/} + echo "$tag"/"$name" - version=$(echo "$result" | jq -r '.[0].name' | cut -d '.' -f1) - if [[ -n $version ]]; then - if [[ $version == v* ]]; then - arr["$tag\/$name@v[0-9\.]*"]="$tag\/$name@$version" - echo "Will replace $tag\/$name@v[0-9]* with $tag\/$name@$version" + version=$(echo "$result" | jq -r '.[0].name' | cut -d '.' -f1) + if [[ -n $version ]]; then + if [[ $version == v* ]]; then + arr["$tag\/$name@v[0-9\.]*"]="$tag\/$name@$version" + echo "Will replace $tag\/$name@v[0-9]* with $tag\/$name@$version" + else + echo "Version $version of $name is not verified, the update will not continue" + fi else - echo "Version $version of $name is not verified, the update will not continue" + echo "ERROR! Failed to get $plugin version!" fi - else - echo "ERROR! Failed to get $plugin version!" - fi + done done -done +fi echo -e "GitHub Workflow Updates" for key in "${!arr[@]}"; do