-
Notifications
You must be signed in to change notification settings - Fork 52
155 lines (133 loc) · 5.43 KB
/
update_dependencies.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
## 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'