22
33# Script to roll SDK packages in all Flutter/Dart projects
44# Designed to handle git-based dependencies and work with the GitHub CI workflow
5+ #
6+ # Usage:
7+ # UPGRADE_ALL_PACKAGES=false TARGET_BRANCH=dev .github/scripts/roll_sdk_packages.sh
8+ #
9+ # Parameters:
10+ # UPGRADE_ALL_PACKAGES: Set to "true" to upgrade all packages, "false" to only upgrade SDK packages
11+ # TARGET_BRANCH: The target branch for PR creation
12+ #
13+ # For more details, see `docs/SDK_DEPENDENCY_MANAGEMENT.md`
514
15+ # Exit on error, but with proper cleanup
616set -e
717
18+ # Error handling and cleanup function
19+ cleanup () {
20+ local exit_code=$?
21+
22+ # Only perform cleanup if there was an error
23+ if [ $exit_code -ne 0 ] && [ $exit_code -ne 100 ]; then
24+ echo " ERROR: Script failed with exit code $exit_code "
25+ # Clean up any temporary files
26+ find " $REPO_ROOT " -name " *.bak" -type f -delete
27+ fi
28+
29+ exit $exit_code
30+ }
31+
32+ # Set up trap to catch errors
33+ trap cleanup EXIT
34+
35+ # Log function for better reporting
36+ log_info () {
37+ echo " INFO: $1 "
38+ }
39+
40+ log_warning () {
41+ echo " WARNING: $1 " >&2
42+ }
43+
44+ log_error () {
45+ echo " ERROR: $1 " >&2
46+ }
47+
48+ # Validate Flutter is available
49+ if ! command -v flutter & > /dev/null; then
50+ log_error " Flutter command not found. Please ensure Flutter is installed and in your PATH."
51+ exit 1
52+ fi
53+
854# Configuration
955# Set to "true" to upgrade all packages, "false" to only upgrade SDK packages
1056UPGRADE_ALL_PACKAGES=${UPGRADE_ALL_PACKAGES:- false}
@@ -16,6 +62,10 @@ CURRENT_DATE=$(date '+%Y-%m-%d')
1662REPO_ROOT=$( pwd)
1763CHANGES_FILE=" $REPO_ROOT /SDK_CHANGELOG.md"
1864
65+ # List of external SDK packages to be updated (from KomodoPlatform/komodo-defi-sdk-flutter.git)
66+ # Local packages like 'komodo_ui_kit' and 'komodo_persistence_layer' are not included
67+ # as they're part of this repository, not the external SDK
68+
1969# SDK packages to check
2070SDK_PACKAGES=(
2171 " komodo_cex_market_data"
@@ -117,7 +167,18 @@ for PUBSPEC in $PUBSPEC_FILES; do
117167 PROJECT_DIR=$( dirname " $PUBSPEC " )
118168 PROJECT_NAME=$( basename " $PROJECT_DIR " )
119169
120- echo " Processing $PROJECT_NAME ($PROJECT_DIR )"
170+ # Special handling for the root project
171+ if [ " $PROJECT_DIR " = " $REPO_ROOT " ]; then
172+ PROJECT_NAME=" Root Project (komodo-wallet)"
173+ echo " Processing ROOT PROJECT ($PROJECT_DIR )"
174+ else
175+ echo " Processing $PROJECT_NAME ($PROJECT_DIR )"
176+ fi
177+
178+ # Debug: Print information about processing the project
179+ echo " Debug info for $PROJECT_NAME :"
180+ echo " - Project path: $PROJECT_DIR "
181+ echo " - Full pubspec path: $PUBSPEC "
121182
122183 cd " $PROJECT_DIR "
123184
@@ -126,9 +187,19 @@ for PUBSPEC in $PUBSPEC_FILES; do
126187 SDK_PACKAGES_FOUND=()
127188
128189 for PACKAGE in " ${SDK_PACKAGES[@]} " ; do
129- if grep -q -E " ^\s+$PACKAGE :" " $PUBSPEC " ; then
130- CONTAINS_SDK_PACKAGE=true
131- SDK_PACKAGES_FOUND+=(" $PACKAGE " )
190+ # More robust pattern matching that allows for comments and other formatting
191+ if grep -q " ^[[:space:]]*$PACKAGE :" " $PUBSPEC " ; then
192+ # Additional check: detect if it's a git-based package from the KomodoPlatform repo
193+ if grep -A 10 " $PACKAGE :" " $PUBSPEC " | grep -q " github.com/KomodoPlatform/komodo-defi-sdk-flutter" ; then
194+ echo " Found SDK package $PACKAGE (git-based) in $PROJECT_NAME "
195+ CONTAINS_SDK_PACKAGE=true
196+ SDK_PACKAGES_FOUND+=(" $PACKAGE " )
197+ else
198+ echo " Package $PACKAGE found but may not be from the SDK repository"
199+ # Still include it, but log for clarity
200+ CONTAINS_SDK_PACKAGE=true
201+ SDK_PACKAGES_FOUND+=(" $PACKAGE " )
202+ fi
132203 fi
133204 done
134205
@@ -150,7 +221,7 @@ for PUBSPEC in $PUBSPEC_FILES; do
150221 # Get the current git refs/versions for SDK packages before update
151222 SDK_PACKAGE_REFS_BEFORE=()
152223 for PACKAGE in " ${SDK_PACKAGES_FOUND[@]} " ; do
153- if grep -q " $PACKAGE :" " $PUBSPEC " ; then
224+ if grep -q " ^[[:space:]]* $PACKAGE :" " $PUBSPEC " ; then
154225 # Get the git reference line or version line
155226 if grep -q -A 10 " $PACKAGE :" " $PUBSPEC " | grep -q " git:" ; then
156227 REF_LINE=$( grep -A 10 " $PACKAGE :" " $PUBSPEC " | grep -m 1 " ref:" )
@@ -173,15 +244,24 @@ for PUBSPEC in $PUBSPEC_FILES; do
173244
174245 # Perform the update - based on configuration
175246 if [ " $UPGRADE_ALL_PACKAGES " = " true" ]; then
176- echo " Running flutter pub upgrade --major-versions in $PROJECT_NAME (all packages)"
177- flutter pub upgrade --major-versions
247+ log_info " Running flutter pub upgrade --major-versions in $PROJECT_NAME (all packages)"
248+ if ! flutter pub upgrade --major-versions; then
249+ log_error " Failed to upgrade all packages in $PROJECT_NAME "
250+ cd " $REPO_ROOT "
251+ continue
252+ fi
178253 else
179- echo " Running flutter pub upgrade for SDK packages only in $PROJECT_NAME "
180- # Upgrade only the SDK packages
181- for PACKAGE in " ${SDK_PACKAGES_FOUND[@]} " ; do
182- echo " Upgrading $PACKAGE "
183- flutter pub upgrade " $PACKAGE "
184- done
254+ log_info " Running flutter pub upgrade for SDK packages only in $PROJECT_NAME "
255+ # Upgrade all SDK packages at once
256+ if [ ${# SDK_PACKAGES_FOUND[@]} -gt 0 ]; then
257+ log_info " Upgrading packages: ${SDK_PACKAGES_FOUND[*]} "
258+ if ! flutter pub upgrade --unlock-transitive ${SDK_PACKAGES_FOUND[@]} ; then
259+ log_warning " Failed to upgrade packages in $PROJECT_NAME "
260+ PACKAGE_UPDATE_FAILED=true
261+ fi
262+ else
263+ log_info " No SDK packages found to upgrade in $PROJECT_NAME "
264+ fi
185265 fi
186266
187267 # Check if the pubspec.lock was modified
253333if [ -n " ${GITHUB_OUTPUT} " ]; then
254334 if [ " $ROLLS_MADE " = true ]; then
255335 echo " updates_found=true" >> $GITHUB_OUTPUT
256- echo " Rolls found and applied!"
336+ log_info " Rolls found and applied!"
257337 exit 0
258338 else
259339 echo " updates_found=false" >> $GITHUB_OUTPUT
260- echo " No rolls needed."
261- exit 1
340+ log_info " No rolls needed."
341+ # Exit with special code 100 to indicate no changes needed (not a failure)
342+ exit 100
262343 fi
263344else
264345 # When running outside of GitHub Actions
265346 if [ " $ROLLS_MADE " = true ]; then
266- echo " Rolls found and applied! See $CHANGES_FILE for details."
347+ log_info " Rolls found and applied! See $CHANGES_FILE for details."
267348 exit 0
268349 else
269- echo " No rolls needed."
270- exit 1
350+ log_info " No rolls needed."
351+ # Exit with special code 100 to indicate no changes needed (not a failure)
352+ exit 100
271353 fi
272354fi
0 commit comments