Repository navigation
160 lines (137 loc) · 6.58 KB
/
Copy pathdependency-update.yml
File metadata and controls
160 lines (137 loc) · 6.58 KB
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
156
157
158
159
160
name: Update @dashevo/evo-sdk Dependency and Package Version
on:
schedule:
- cron: '0 12 * * *' # Run daily at 1200 UTC
workflow_dispatch: # Allow manual trigger
permissions:
contents: write
pull-requests: write
jobs:
update-evo-sdk-package:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: .nvmrc
- name: Show Node/npm versions
run: |
node -v
npm -v
# Step 3: Check and update every package that uses @dashevo/evo-sdk
- name: Check and Update @dashevo/evo-sdk Dependencies
id: update_evo_sdk
run: |
set -euo pipefail
latest_version="$(npm show @dashevo/evo-sdk version)"
if ! npx -y semver "$latest_version" >/dev/null; then
echo "Invalid latest @dashevo/evo-sdk version returned by npm: $latest_version" >&2
exit 1
fi
echo "Latest @dashevo/evo-sdk version: $latest_version"
locked_version() {
local package_dir="$1"
local lockfile="$package_dir/package-lock.json"
if [ ! -f "$lockfile" ]; then
echo "Missing lockfile for SDK-consuming package: $lockfile" >&2
return 1
fi
local version
version="$(jq -r \
'.packages["node_modules/@dashevo/evo-sdk"].version // .dependencies["@dashevo/evo-sdk"].version // empty' \
"$lockfile")"
if [ -z "$version" ] || ! npx -y semver "$version" >/dev/null; then
echo "Missing or invalid @dashevo/evo-sdk version in $lockfile: ${version:-<missing>}" >&2
return 1
fi
echo "$version"
}
is_behind() {
local version="$1"
[ -n "$(npx -y semver "$latest_version" -r ">$version" || true)" ]
}
update_dependency_specifier() {
local package_file="$1"
local specifier="$2"
jq --arg version "$specifier" '
if .dependencies["@dashevo/evo-sdk"] then
.dependencies["@dashevo/evo-sdk"] = $version
elif .devDependencies["@dashevo/evo-sdk"] then
.devDependencies["@dashevo/evo-sdk"] = $version
else
error("package does not declare @dashevo/evo-sdk")
end
' "$package_file" > "$package_file.tmp"
mv "$package_file.tmp" "$package_file"
}
updated_packages=()
root_locked_version="$(locked_version .)"
echo "Root locked version: $root_locked_version"
if is_behind "$root_locked_version"; then
current_specifier="$(jq -r '.dependencies["@dashevo/evo-sdk"] // .devDependencies["@dashevo/evo-sdk"]' package.json)"
version_prefix="$(echo "$current_specifier" | grep -o '^[^0-9]*' || true)"
current_package_version="$(jq -r '.version' package.json)"
current_major_version="${current_package_version%%.*}"
latest_minor_patch="${latest_version#*.}"
new_package_version="$current_major_version.$latest_minor_patch"
if [ -z "$(npx -y semver "$new_package_version" -r ">$current_package_version" || true)" ]; then
echo "Refusing non-forward package version update: $current_package_version -> $new_package_version" >&2
exit 1
fi
update_dependency_specifier package.json "$version_prefix$latest_version"
jq --arg version "$new_package_version" '.version = $version' package.json > package.json.tmp
mv package.json.tmp package.json
npm install --package-lock-only --ignore-scripts
updated_packages+=("root")
echo "Updated root SDK to $latest_version and package version to $new_package_version"
fi
for package_file in example-apps/*/package.json; do
[ -f "$package_file" ] || continue
if ! jq -e '.dependencies["@dashevo/evo-sdk"]' "$package_file" >/dev/null; then
continue
fi
package_dir="$(dirname "$package_file")"
app_name="$(basename "$package_dir")"
app_locked_version="$(locked_version "$package_dir")"
echo "$app_name locked version: $app_locked_version"
if is_behind "$app_locked_version"; then
# Apps use exact pins because their lite pages embed this specifier in an import URL.
update_dependency_specifier "$package_file" "$latest_version"
for page in "$package_dir"/public/*-lite.html; do
[ -f "$page" ] || continue
sed -i -E "s|(https://esm\.sh/@dashevo/evo-sdk@)[^'\"]+|\1$latest_version|" "$page"
done
(cd "$package_dir" && npm install --package-lock-only --ignore-scripts)
updated_packages+=("$app_name")
echo "Updated $app_name SDK to $latest_version"
fi
done
if [ "${#updated_packages[@]}" -gt 0 ]; then
updated_list="$(printf ', %s' "${updated_packages[@]}")"
updated_list="${updated_list:2}"
echo "needs_update=true" >> "$GITHUB_ENV"
echo "updated_packages=$updated_list" >> "$GITHUB_ENV"
echo "target_sdk_version=$latest_version" >> "$GITHUB_ENV"
else
echo "All @dashevo/evo-sdk dependencies are up-to-date"
echo "needs_update=false" >> "$GITHUB_ENV"
fi
# Step 4: Create Pull Request
- name: Create Pull Request
if: env.needs_update == 'true'
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update-evo-sdk-to-${{ env.target_sdk_version }}
base: main
title: "chore: update @dashevo/evo-sdk across tutorials and examples"
body: |
This pull request updates `@dashevo/evo-sdk` to the latest stable version across the tutorials and example apps.
Updated packages: ${{ env.updated_packages }}
When the root dependency changes, the root package version is also synchronized with the SDK minor and patch version.
commit-message: "chore: update @dashevo/evo-sdk across tutorials and examples"
reviewers: "thephez"