Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/actions/flutter-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ runs:
# NB! Keep up-to-date with the flutter version used for development
flutter-version: "3.29.2"
channel: "stable"
cache: true

- name: Prepare build directory
shell: bash
Expand Down
120 changes: 101 additions & 19 deletions .github/scripts/roll_sdk_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,55 @@

# Script to roll SDK packages in all Flutter/Dart projects
# Designed to handle git-based dependencies and work with the GitHub CI workflow
#
# Usage:
# UPGRADE_ALL_PACKAGES=false TARGET_BRANCH=dev .github/scripts/roll_sdk_packages.sh
#
# Parameters:
# UPGRADE_ALL_PACKAGES: Set to "true" to upgrade all packages, "false" to only upgrade SDK packages
# TARGET_BRANCH: The target branch for PR creation
#
# For more details, see `docs/SDK_DEPENDENCY_MANAGEMENT.md`

# Exit on error, but with proper cleanup
set -e

# Error handling and cleanup function
cleanup() {
local exit_code=$?

# Only perform cleanup if there was an error
if [ $exit_code -ne 0 ] && [ $exit_code -ne 100 ]; then
echo "ERROR: Script failed with exit code $exit_code"
# Clean up any temporary files
find "$REPO_ROOT" -name "*.bak" -type f -delete
fi

exit $exit_code
}

# Set up trap to catch errors
trap cleanup EXIT

# Log function for better reporting
log_info() {
echo "INFO: $1"
}

log_warning() {
echo "WARNING: $1" >&2
}

log_error() {
echo "ERROR: $1" >&2
}

# Validate Flutter is available
if ! command -v flutter &> /dev/null; then
log_error "Flutter command not found. Please ensure Flutter is installed and in your PATH."
exit 1
fi

# Configuration
# Set to "true" to upgrade all packages, "false" to only upgrade SDK packages
UPGRADE_ALL_PACKAGES=${UPGRADE_ALL_PACKAGES:-false}
Expand All @@ -16,6 +62,10 @@ CURRENT_DATE=$(date '+%Y-%m-%d')
REPO_ROOT=$(pwd)
CHANGES_FILE="$REPO_ROOT/SDK_CHANGELOG.md"

# List of external SDK packages to be updated (from KomodoPlatform/komodo-defi-sdk-flutter.git)
# Local packages like 'komodo_ui_kit' and 'komodo_persistence_layer' are not included
# as they're part of this repository, not the external SDK

# SDK packages to check
SDK_PACKAGES=(
"komodo_cex_market_data"
Expand Down Expand Up @@ -117,7 +167,18 @@ for PUBSPEC in $PUBSPEC_FILES; do
PROJECT_DIR=$(dirname "$PUBSPEC")
PROJECT_NAME=$(basename "$PROJECT_DIR")

echo "Processing $PROJECT_NAME ($PROJECT_DIR)"
# Special handling for the root project
if [ "$PROJECT_DIR" = "$REPO_ROOT" ]; then
PROJECT_NAME="Root Project (komodo-wallet)"
echo "Processing ROOT PROJECT ($PROJECT_DIR)"
else
echo "Processing $PROJECT_NAME ($PROJECT_DIR)"
fi

# Debug: Print information about processing the project
echo "Debug info for $PROJECT_NAME:"
echo " - Project path: $PROJECT_DIR"
echo " - Full pubspec path: $PUBSPEC"

cd "$PROJECT_DIR"

Expand All @@ -126,9 +187,19 @@ for PUBSPEC in $PUBSPEC_FILES; do
SDK_PACKAGES_FOUND=()

for PACKAGE in "${SDK_PACKAGES[@]}"; do
if grep -q -E "^\s+$PACKAGE:" "$PUBSPEC"; then
CONTAINS_SDK_PACKAGE=true
SDK_PACKAGES_FOUND+=("$PACKAGE")
# More robust pattern matching that allows for comments and other formatting
if grep -q "^[[:space:]]*$PACKAGE:" "$PUBSPEC"; then
# Additional check: detect if it's a git-based package from the KomodoPlatform repo
if grep -A 10 "$PACKAGE:" "$PUBSPEC" | grep -q "github.com/KomodoPlatform/komodo-defi-sdk-flutter"; then
echo "Found SDK package $PACKAGE (git-based) in $PROJECT_NAME"
CONTAINS_SDK_PACKAGE=true
SDK_PACKAGES_FOUND+=("$PACKAGE")
else
echo "Package $PACKAGE found but may not be from the SDK repository"
# Still include it, but log for clarity
CONTAINS_SDK_PACKAGE=true
SDK_PACKAGES_FOUND+=("$PACKAGE")
fi
fi
done

Expand All @@ -150,7 +221,7 @@ for PUBSPEC in $PUBSPEC_FILES; do
# Get the current git refs/versions for SDK packages before update
SDK_PACKAGE_REFS_BEFORE=()
for PACKAGE in "${SDK_PACKAGES_FOUND[@]}"; do
if grep -q "$PACKAGE:" "$PUBSPEC"; then
if grep -q "^[[:space:]]*$PACKAGE:" "$PUBSPEC"; then
# Get the git reference line or version line
if grep -q -A 10 "$PACKAGE:" "$PUBSPEC" | grep -q "git:"; then
REF_LINE=$(grep -A 10 "$PACKAGE:" "$PUBSPEC" | grep -m 1 "ref:")
Expand All @@ -173,15 +244,24 @@ for PUBSPEC in $PUBSPEC_FILES; do

# Perform the update - based on configuration
if [ "$UPGRADE_ALL_PACKAGES" = "true" ]; then
echo "Running flutter pub upgrade --major-versions in $PROJECT_NAME (all packages)"
flutter pub upgrade --major-versions
log_info "Running flutter pub upgrade --major-versions in $PROJECT_NAME (all packages)"
if ! flutter pub upgrade --major-versions; then
log_error "Failed to upgrade all packages in $PROJECT_NAME"
cd "$REPO_ROOT"
continue
fi
else
echo "Running flutter pub upgrade for SDK packages only in $PROJECT_NAME"
# Upgrade only the SDK packages
for PACKAGE in "${SDK_PACKAGES_FOUND[@]}"; do
echo "Upgrading $PACKAGE"
flutter pub upgrade "$PACKAGE"
done
log_info "Running flutter pub upgrade for SDK packages only in $PROJECT_NAME"
# Upgrade all SDK packages at once
if [ ${#SDK_PACKAGES_FOUND[@]} -gt 0 ]; then
log_info "Upgrading packages: ${SDK_PACKAGES_FOUND[*]}"
if ! flutter pub upgrade --unlock-transitive ${SDK_PACKAGES_FOUND[@]}; then
log_warning "Failed to upgrade packages in $PROJECT_NAME"
PACKAGE_UPDATE_FAILED=true
fi
else
log_info "No SDK packages found to upgrade in $PROJECT_NAME"
fi
fi

# Check if the pubspec.lock was modified
Expand Down Expand Up @@ -253,20 +333,22 @@ fi
if [ -n "${GITHUB_OUTPUT}" ]; then
if [ "$ROLLS_MADE" = true ]; then
echo "updates_found=true" >> $GITHUB_OUTPUT
echo "Rolls found and applied!"
log_info "Rolls found and applied!"
exit 0
else
echo "updates_found=false" >> $GITHUB_OUTPUT
echo "No rolls needed."
exit 1
log_info "No rolls needed."
# Exit with special code 100 to indicate no changes needed (not a failure)
exit 100
fi
else
# When running outside of GitHub Actions
if [ "$ROLLS_MADE" = true ]; then
echo "Rolls found and applied! See $CHANGES_FILE for details."
log_info "Rolls found and applied! See $CHANGES_FILE for details."
exit 0
else
echo "No rolls needed."
exit 1
log_info "No rolls needed."
# Exit with special code 100 to indicate no changes needed (not a failure)
exit 100
fi
fi
64 changes: 52 additions & 12 deletions .github/workflows/roll-sdk-packages.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# filepath: /Users/charl/Code/UTXO/komodo-wallet/.github/workflows/roll-sdk-packages.yml
name: Roll SDK Packages

# This workflow automates updating SDK package dependencies from the external komodo-defi-sdk-flutter repository
# It creates or updates a pull request with the necessary changes to pubspec.yaml and pubspec.lock files
# For more information on how this works or how to run the script manually, see:
# https://github.com/KomodoPlatform/komodo-wallet/blob/dev/docs/SDK_DEPENDENCY_MANAGEMENT.md

on:
schedule:
# Run once a day at midnight
- cron: "0 0 * * *"
push:
branches:
- dev
pull_request:
branches:
- dev
# Allow manual trigger
workflow_dispatch:
inputs:
Expand All @@ -33,7 +36,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -44,7 +47,6 @@ jobs:
# NB! Keep up-to-date with the flutter version used for development
flutter-version: "3.29.2"
channel: "stable"
cache: true

- name: Determine configuration
id: config
Expand Down Expand Up @@ -77,11 +79,21 @@ jobs:
- name: Run roll script
id: roll_packages
run: |
UPGRADE_ALL_PACKAGES=${{ env.UPGRADE_ALL }} TARGET_BRANCH=${{ env.TARGET_BRANCH }} .github/scripts/roll_sdk_packages.sh || echo "No rolls needed"
# Run the script and capture exit code
UPGRADE_ALL_PACKAGES=${{ env.UPGRADE_ALL }} TARGET_BRANCH=${{ env.TARGET_BRANCH }} .github/scripts/roll_sdk_packages.sh || EXIT_CODE=$?

# Different handling based on exit code
if [ -f "SDK_CHANGELOG.md" ]; then
echo "ROLLS_FOUND=true" >> $GITHUB_ENV
echo "SDK packages were successfully rolled"
else
echo "ROLLS_FOUND=false" >> $GITHUB_ENV

if [ -n "${EXIT_CODE}" ] && [ ${EXIT_CODE} -ne 100 ]; then
echo "::warning::SDK package roll script failed with exit code ${EXIT_CODE}"
else
echo "No SDK package updates were needed"
fi
fi

- name: Setup Git identity
Expand All @@ -90,13 +102,35 @@ jobs:
git config --global user.name "GitHub Action Bot"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Install GitHub CLI
if: env.ROLLS_FOUND == 'true'
run: |
if ! command -v gh &> /dev/null; then
echo "Installing GitHub CLI..."
# GitHub CLI should already be installed on GitHub Actions runners
# This is a fallback mechanism
gh --version || {
echo "GitHub CLI not found, installing..."
type -p curl >/dev/null || sudo apt-get install curl -y
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt-get update \
&& sudo apt-get install gh -y
}
fi
# Verify GitHub CLI is available
gh --version

- name: Create PR Branch
if: env.ROLLS_FOUND == 'true'
run: |
# Check if the branch already exists
if git ls-remote --heads origin ${{ env.PR_BRANCH_NAME }} | grep -q ${{ env.PR_BRANCH_NAME }}; then
# If it exists, delete it (force update)
git push origin --delete ${{ env.PR_BRANCH_NAME }}
git push origin --delete ${{ env.PR_BRANCH_NAME }} || {
echo "::warning::Failed to delete existing branch ${{ env.PR_BRANCH_NAME }} - it may be protected"
}
fi

# Create new branch
Expand All @@ -109,20 +143,23 @@ jobs:
git status

git commit -m "chore: roll SDK packages targeting ${{ env.TARGET_BRANCH }}"
git push --set-upstream origin "${{ env.PR_BRANCH_NAME }}"
git push --set-upstream origin "${{ env.PR_BRANCH_NAME }}" || {
echo "::error::Failed to push branch to origin - check credentials and branch protection settings"
exit 1
}

- name: Create Pull Request
if: env.ROLLS_FOUND == 'true'
run: |
# Check if a PR from this branch to target branch already exists
EXISTING_PR=$(gh pr list --head "${{ env.PR_BRANCH_NAME }}" --base "${{ env.TARGET_BRANCH }}" --json number --jq '.[0].number')
EXISTING_PR=$(gh pr list --head "${{ env.PR_BRANCH_NAME }}" --base "${{ env.TARGET_BRANCH }}" --json number --jq '.[0].number' || echo "")

if [ -n "$EXISTING_PR" ]; then
echo "Updating existing PR #$EXISTING_PR with new changes"
# Update the PR body with the latest SDK roll changes
gh pr edit "$EXISTING_PR" --body-file SDK_CHANGELOG.md
gh pr edit "$EXISTING_PR" --body-file SDK_CHANGELOG.md || echo "::warning::Failed to update PR body"
# Add a comment to notify about the update
gh pr comment "$EXISTING_PR" --body "Updated SDK roll with new changes on $(date '+%Y-%m-%d %H:%M:%S')"
gh pr comment "$EXISTING_PR" --body "Updated SDK roll with new changes on $(date '+%Y-%m-%d %H:%M:%S')" || echo "::warning::Failed to add comment to PR"
else
# Create the pull request using gh CLI
gh pr create \
Expand All @@ -131,7 +168,10 @@ jobs:
--base "${{ env.TARGET_BRANCH }}" \
--head "${{ env.PR_BRANCH_NAME }}" \
--label "dependencies" \
--label "automated"
--label "automated" || {
echo "::error::Failed to create Pull Request - check GitHub token permissions"
exit 1
}
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Current production version is available here: https://app.komodoplatform.com
- [Localization](docs/LOCALIZATION.md)
- [Unit testing](docs/UNIT_TESTING.md)
- [Integration testing](docs/INTEGRATION_TESTING.md)
- [SDK Dependency Management](docs/SDK_DEPENDENCY_MANAGEMENT.md)
- [Gitflow and branching strategy](docs/GITFLOW_BRANCHING.md)
- [Issue: create and maintain](docs/ISSUE.md) ...in progress
- [Contribution guide](docs/CONTRIBUTION_GUIDE.md)
Expand Down
Loading
Loading