Skip to content

Manual update of @playkit-js dependencies #190

Manual update of @playkit-js dependencies

Manual update of @playkit-js dependencies #190

## Update Kaltura-player dependencies
name: Manual update of @playkit-js dependencies
on:
workflow_dispatch:
inputs:
UPDATE-playkit-js:
description: 'playkit-js'
required: true
default: true
type: boolean
VERSION-playkit-js:
description: 'playkit-js version'
required: true
default: latest
UPDATE-playkit-js-ui:
description: 'playkit-js-ui'
required: true
default: true
type: boolean
VERSION-playkit-js-ui:
description: 'playkit-js-ui version'
required: true
default: latest
UPDATE-playkit-js-providers:
description: 'playkit-js-providers'
required: true
default: true
type: boolean
VERSION-playkit-js-providers:
description: 'js-providers version'
required: true
default: latest
UPDATE-playkit-js-dash:
description: 'playkit-js-dash'
required: true
default: true
type: boolean
VERSION-playkit-js-dash:
description: 'playkit-js-dash version'
required: true
default: latest
UPDATE-playkit-js-hls:
description: 'playkit-js-hls'
required: true
default: true
type: boolean
VERSION-playkit-js-hls:
description: 'playkit-js-hls version'
required: true
default: latest
jobs:
check_and_update_dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.PLAYER_GITHUB_BOT_TOKEN }}
- name: Setup Git
run: |
git config --global user.email ${{ secrets.PLAYER_BOT_EMAIL }}
git config --global user.name ${{ secrets.PLAYER_BOT_USER }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16.x'
- name: Check updates Kaltura dependencies (branch - ${{ github.ref_name }})
run: |
# Define dependencies
kalturaDependencies=(
'{"name": "playkit-js", "package": "@playkit-js/playkit-js"}'
'{"name": "playkit-js-dash", "package": "@playkit-js/playkit-js-dash"}'
'{"name": "playkit-js-hls", "package": "@playkit-js/playkit-js-hls"}'
'{"name": "playkit-js-providers", "package": "@playkit-js/playkit-js-providers"}'
'{"name": "playkit-js-ui", "package": "@playkit-js/playkit-js-ui"}'
)
# 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
# Save script inputs to local variable
local inputsJson="${{ toJson(github.event.inputs) }}"
local dependencyKey="UPDATE-$dependencyName"
local versionKey="VERSION-$dependencyName"
local checkedValue=$(echo $inputsJson | sed -n "s/.*$dependencyKey:\([^,}]*\).*/\1/p")
local versionValue=$(echo $inputsJson | sed -n "s/.*$versionKey:\([^,}]*\).*/\1/p")
# Trim leading and trailing spaces from checkedValue and versionValue
checkedValue=$(echo $checkedValue | xargs)
versionValue=$(echo $versionValue | xargs)
# 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
else
echo "Update of depencency $dependencyName skiped (checkbox unchecked)"
fi
else
echo "No $packageName dependency found in package.json"
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
if: env.COMMIT_REQUIRED == 'true'
uses: peter-evans/create-pull-request@v5
with:
title: 'chore: upgrade kaltura-player dependencies'
delete-branch: true
branch: 'upgrade-npm-dependencies-automated'
commit-message: 'chore: upgrade kaltura-player dependencies'