Skip to content

Commit

Permalink
simplify script
Browse files Browse the repository at this point in the history
  • Loading branch information
semarche-kaltura committed Dec 11, 2023
1 parent 8b5c058 commit 33ba685
Showing 1 changed file with 35 additions and 50 deletions.
85 changes: 35 additions & 50 deletions .github/workflows/update_dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33ba685

Please sign in to comment.