From 33ba6855c1e3513bda1e440cc298d6abf4fff842 Mon Sep 17 00:00:00 2001 From: Serhii Marchenko Date: Mon, 11 Dec 2023 13:48:58 +0200 Subject: [PATCH] simplify script --- .github/workflows/update_dependencies.yaml | 85 +++++++++------------- 1 file changed, 35 insertions(+), 50 deletions(-) diff --git a/.github/workflows/update_dependencies.yaml b/.github/workflows/update_dependencies.yaml index a85119867..c126a49e8 100644 --- a/.github/workflows/update_dependencies.yaml +++ b/.github/workflows/update_dependencies.yaml @@ -86,61 +86,46 @@ jobs: ) # Check and update a dependency - checkAndUpdateDependency() { - local dependencyName="$1" - local packageName="$2" - local currentVersion=$(jq -r ".dependencies.\"$packageName\"" package.json) - - # Check if the dependency exists in package.json - if [[ "$currentVersion" != "null" ]]; then - # Construct the input keys dynamically - local checkedKey="UPDATE-$dependencyName" - local versionKey="VERSION-$dependencyName" - - # Save input values to local variables - local checkedValue="${{ github.event.inputs[checkedKey] }}" - local versionValue="${{ github.event.inputs[versionKey] }}" - - echo ">> checked $checkedValue" - echo ">> version $versionValue" - - # Check if the dependency checked in script inputs - if [[ $checkedValue == "true" ]]; then - - # Check and set version for update - local latestVersion - if [[ $versionValue == "null" ]]; then - echo "Input versino value is 'null'. Skipping update for $dependencyName" - elif [[ $versionValue == "latest" ]]; then - # Get the latest version of the package using npm - latestVersion=$(npm view "$packageName" version) - else - # Get version from script inputs - latestVersion=$versionValue - fi - - # Update the package.json file only if the version has changed - if [[ "$currentVersion" != "$latestVersion" ]]; then - echo "Update $packageName from $currentVersion to version $latestVersion" - yarn add $packageName@$latestVersion --silent - echo "COMMIT_REQUIRED=true" >> $GITHUB_ENV - else - echo "Dependency $packageName already has same version: $latestVersion" - fi + for dependency in "${kalturaDependencies[@]}"; do + dependencyName=$(echo "$dependency" | jq -r ".name") + packageName=$(echo "$dependency" | jq -r ".package") + + local checkedKey="UPDATE-$dependencyName" + local versionKey="VERSION-$dependencyName" + local checkedValue="${{ github.event.inputs[checkedKey] }}" + local versionValue="${{ github.event.inputs[versionKey] }}" + + echo ">> checked $checkedValue" + echo ">> version $versionValue" + + # Check if the dependency checked in script inputs + if [[ $checkedValue == "true" ]]; then + + # Check and set version for update + local latestVersion + if [[ $versionValue == "null" ]]; then + echo "Input version value is 'null'. Skipping update for $dependencyName" + elif [[ $versionValue == "latest" ]]; then + # Get the latest version of the package using npm + latestVersion=$(npm view "$packageName" version) else - echo "Update of depencency $dependencyName skiped (checkbox unchecked)" + # Get version from script inputs + latestVersion=$versionValue fi - + + # Update the package.json file only if the version has changed + if [[ "$(jq -r ".dependencies.\"$packageName\"" package.json)" != "$latestVersion" ]]; then + echo "Update $packageName from $(jq -r ".dependencies.\"$packageName\"" package.json) to version $latestVersion" + yarn add $packageName@$latestVersion --silent + echo "COMMIT_REQUIRED=true" >> $GITHUB_ENV + else + echo "Dependency $packageName already has the same version: $latestVersion" + fi + else - echo "No $packageName dependency found in package.json" + echo "Update of dependency $dependencyName skipped (checkbox unchecked)" fi - } - - for dependency in "${kalturaDependencies[@]}"; do - dependencyName=$(echo "$dependency" | jq -r ".name") - packageName=$(echo "$dependency" | jq -r ".package") - checkAndUpdateDependency "$dependencyName" "$packageName" done - name: Commit changes