From 19bb3292f80bd2ebc0f54cbae86d6e11ff2d3086 Mon Sep 17 00:00:00 2001 From: Francois Date: Mon, 23 Sep 2024 16:47:23 +0200 Subject: [PATCH 1/4] Fix defi sdk example build Support projects that require npm (komodo-wallet) and newer projects that don't (no package.json present) --- packages/komodo_defi_framework/app_build/build_config.json | 2 +- .../lib/src/operations/kdf_operations_wasm.dart | 7 ++++--- packages/komodo_defi_framework/pubspec.yaml | 2 +- .../lib/src/steps/fetch_defi_api_build_step.dart | 7 +++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/komodo_defi_framework/app_build/build_config.json b/packages/komodo_defi_framework/app_build/build_config.json index 6c0b058..2cd7dbe 100644 --- a/packages/komodo_defi_framework/app_build/build_config.json +++ b/packages/komodo_defi_framework/app_build/build_config.json @@ -68,7 +68,7 @@ }, "coins": { "update_commit_on_build": true, - "bundled_coins_repo_commit": "8bd87b2f42bfd2857e0554deb077849504d23182", + "bundled_coins_repo_commit": "83794c99944ae451d7898a8db78898be7a63de8a", "coins_repo_api_url": "https://api.github.com/repos/KomodoPlatform/coins", "coins_repo_content_url": "https://komodoplatform.github.io/coins", "coins_repo_branch": "master", diff --git a/packages/komodo_defi_framework/lib/src/operations/kdf_operations_wasm.dart b/packages/komodo_defi_framework/lib/src/operations/kdf_operations_wasm.dart index f170764..166ca39 100644 --- a/packages/komodo_defi_framework/lib/src/operations/kdf_operations_wasm.dart +++ b/packages/komodo_defi_framework/lib/src/operations/kdf_operations_wasm.dart @@ -237,9 +237,10 @@ class KdfOperationsWasm implements IKdfOperations { Future _injectLibrary() async { try { - _kdfModule = - (await js_interop.importModule('./$_kdfJsBootstrapperPath').toDart) - .getProperty('kdf'.toJS); + _kdfModule = (await js_interop + .importModule('./$_kdfJsBootstrapperPath'.toJS) + .toDart) + .getProperty('kdf'.toJS); final debugProperties = Map.fromIterable( [ diff --git a/packages/komodo_defi_framework/pubspec.yaml b/packages/komodo_defi_framework/pubspec.yaml index 7e4120e..7de142c 100644 --- a/packages/komodo_defi_framework/pubspec.yaml +++ b/packages/komodo_defi_framework/pubspec.yaml @@ -65,7 +65,7 @@ flutter: fileName: web/kdf_plugin_web.dart assets: - - assets/config/coins.json + - assets/config/ - path: assets/.transformer_invoker transformers: diff --git a/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart b/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart index 8b85a92..d9593e3 100644 --- a/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart +++ b/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart @@ -320,6 +320,13 @@ class FetchDefiApiStep extends BuildStep { } Future _updateWebPackages() async { + // First check for a `package.json` file in the root of the project + final packageJsonFile = File(path.join(artifactOutputPath, 'package.json')); + if (!packageJsonFile.existsSync()) { + _log.info('No package.json file found in $artifactOutputPath'); + return; + } + _log ..info('Updating Web platform...') ..fine('Running npm install in $artifactOutputPath'); From e296b1b3427bed01eb22d08ab2ba2aadc52a99a1 Mon Sep 17 00:00:00 2001 From: Francois Date: Mon, 23 Sep 2024 16:56:12 +0200 Subject: [PATCH 2/4] Overwrite existing files when extracting zips --- .../lib/src/steps/fetch_defi_api_build_step.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart b/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart index d9593e3..19e44cc 100644 --- a/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart +++ b/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_defi_api_build_step.dart @@ -485,9 +485,11 @@ class FetchDefiApiStep extends BuildStep { try { // Determine the platform to use the appropriate extraction command if (Platform.isMacOS || Platform.isLinux) { - // For macOS and Linux, use the `unzip` command - final result = - await Process.run('unzip', [zipFilePath, '-d', destinationFolder]); + // For macOS and Linux, use the `unzip` command with overwrite option + final result = await Process.run( + 'unzip', + ['-o', zipFilePath, '-d', destinationFolder], + ); if (result.exitCode != 0) { throw Exception('Error extracting zip file: ${result.stderr}'); } From 526e17d5cc98a0280f40f339db0c710acf7be1a2 Mon Sep 17 00:00:00 2001 From: Francois Date: Mon, 23 Sep 2024 17:09:34 +0200 Subject: [PATCH 3/4] Add code validation and unit test workflows for PRs --- .github/actions/generate-assets/action.yml | 40 +++++++++++++++ .github/workflows/unit-tests-on-pr.yml | 51 +++++++++++++++++++ .../workflows/validate-code-guidelines.yml | 39 ++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 .github/actions/generate-assets/action.yml create mode 100644 .github/workflows/unit-tests-on-pr.yml create mode 100644 .github/workflows/validate-code-guidelines.yml diff --git a/.github/actions/generate-assets/action.yml b/.github/actions/generate-assets/action.yml new file mode 100644 index 0000000..cc9ce1a --- /dev/null +++ b/.github/actions/generate-assets/action.yml @@ -0,0 +1,40 @@ +name: "Generates assets" +description: "Runs the flutter build command to transform and generate assets for the deployment build" + +inputs: + GITHUB_TOKEN: + description: "The GitHub API public readonly token" + required: false +runs: + using: "composite" + steps: + - name: Fetch packages and generate assets + shell: bash + env: + GITHUB_API_PUBLIC_READONLY_TOKEN: ${{ inputs.GITHUB_TOKEN }} + run: | + echo "Running \`flutter build\` to generate assets for the deployment build" + + if [ -n "$GITHUB_API_PUBLIC_READONLY_TOKEN" ]; then + echo "GITHUB_TOKEN provided, running flutter build with token" + else + echo "GITHUB_TOKEN not provided or empty, running flutter build without token" + unset GITHUB_API_PUBLIC_READONLY_TOKEN + fi + + flutter pub get > /dev/null 2>&1 + flutter build web --release > /dev/null 2>&1 || true + rm -rf build/* + + # Run flutter build and capture its output and exit status + flutter pub get > /dev/null 2>&1 + output=$(flutter build web --release) + exit_status=$? + + # Check if the exit status is non-zero (indicating an error) + if [ $exit_status -ne 0 ]; then + echo "Flutter build exited with status $exit_status. Output:" + echo "$output" + exit $exit_status + fi + echo "Done fetching packages and generating assets" diff --git a/.github/workflows/unit-tests-on-pr.yml b/.github/workflows/unit-tests-on-pr.yml new file mode 100644 index 0000000..a0c31de --- /dev/null +++ b/.github/workflows/unit-tests-on-pr.yml @@ -0,0 +1,51 @@ +# Runs unit tests on PRs to ensure the app is working as expected +name: Run unit tests for packages on PR +run-name: ${{ github.actor }} is running unit tests on PR 🚀 + +on: + pull_request: + types: [opened, synchronize, reopened] + paths: + - "packages/**" + +jobs: + unit_tests_: + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Setup GH Actions + uses: actions/checkout@v4 + + - name: Get stable flutter + uses: subosito/flutter-action@v2 + with: + channel: "stable" + + - name: Fetch packages and generate assets + uses: ./.github/actions/generate-assets + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Test unit_test (unix) + id: unit_tests + continue-on-error: false + timeout-minutes: 15 + run: | + cd packages + for package in */; do + echo "Running tests for $package" + cd "$package" + if [ -d "test" ]; then + flutter clean + rm -rf build/* + rm -rf web/src/mm2/* + rm -rf web/src/kdfi/* + rm -rf web/dist/* + + flutter test + else + echo "No test directory found in $package" + fi + cd .. + done diff --git a/.github/workflows/validate-code-guidelines.yml b/.github/workflows/validate-code-guidelines.yml new file mode 100644 index 0000000..fd9cf81 --- /dev/null +++ b/.github/workflows/validate-code-guidelines.yml @@ -0,0 +1,39 @@ +# Rule for running static analysis and code formatting checks on all PRs +# Runs static analysis and code formatting checks on all PRs to ensure the codebase is clean and consistent +name: Validate Packages Code Guidelines +run-name: ${{ github.actor }} is validating code guidelines 🚀 + +on: + pull_request: + branches: + - "*" + paths: + - "packages/**" + +jobs: + validate_packages_code_guidelines: + runs-on: macos-latest + + steps: + - name: Setup GH Actions + uses: actions/checkout@v4 + + - name: Get stable flutter + uses: subosito/flutter-action@v2 + with: + channel: "stable" + + - name: Fetch packages and generate assets + uses: ./.github/actions/generate-assets + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Validate dart code + run: | + cd packages + for package in */; do + echo "Analyzing package: $package" + cd "$package" + flutter analyze + cd .. + done From 79dc5c1fea798663f11489ba65d71e8b8929c9f6 Mon Sep 17 00:00:00 2001 From: Francois Date: Mon, 23 Sep 2024 17:19:48 +0200 Subject: [PATCH 4/4] Revert "Add code validation and unit test workflows for PRs" This reverts commit 526e17d5cc98a0280f40f339db0c710acf7be1a2. --- .github/actions/generate-assets/action.yml | 40 --------------- .github/workflows/unit-tests-on-pr.yml | 51 ------------------- .../workflows/validate-code-guidelines.yml | 39 -------------- 3 files changed, 130 deletions(-) delete mode 100644 .github/actions/generate-assets/action.yml delete mode 100644 .github/workflows/unit-tests-on-pr.yml delete mode 100644 .github/workflows/validate-code-guidelines.yml diff --git a/.github/actions/generate-assets/action.yml b/.github/actions/generate-assets/action.yml deleted file mode 100644 index cc9ce1a..0000000 --- a/.github/actions/generate-assets/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: "Generates assets" -description: "Runs the flutter build command to transform and generate assets for the deployment build" - -inputs: - GITHUB_TOKEN: - description: "The GitHub API public readonly token" - required: false -runs: - using: "composite" - steps: - - name: Fetch packages and generate assets - shell: bash - env: - GITHUB_API_PUBLIC_READONLY_TOKEN: ${{ inputs.GITHUB_TOKEN }} - run: | - echo "Running \`flutter build\` to generate assets for the deployment build" - - if [ -n "$GITHUB_API_PUBLIC_READONLY_TOKEN" ]; then - echo "GITHUB_TOKEN provided, running flutter build with token" - else - echo "GITHUB_TOKEN not provided or empty, running flutter build without token" - unset GITHUB_API_PUBLIC_READONLY_TOKEN - fi - - flutter pub get > /dev/null 2>&1 - flutter build web --release > /dev/null 2>&1 || true - rm -rf build/* - - # Run flutter build and capture its output and exit status - flutter pub get > /dev/null 2>&1 - output=$(flutter build web --release) - exit_status=$? - - # Check if the exit status is non-zero (indicating an error) - if [ $exit_status -ne 0 ]; then - echo "Flutter build exited with status $exit_status. Output:" - echo "$output" - exit $exit_status - fi - echo "Done fetching packages and generating assets" diff --git a/.github/workflows/unit-tests-on-pr.yml b/.github/workflows/unit-tests-on-pr.yml deleted file mode 100644 index a0c31de..0000000 --- a/.github/workflows/unit-tests-on-pr.yml +++ /dev/null @@ -1,51 +0,0 @@ -# Runs unit tests on PRs to ensure the app is working as expected -name: Run unit tests for packages on PR -run-name: ${{ github.actor }} is running unit tests on PR 🚀 - -on: - pull_request: - types: [opened, synchronize, reopened] - paths: - - "packages/**" - -jobs: - unit_tests_: - runs-on: ubuntu-latest - timeout-minutes: 15 - - steps: - - name: Setup GH Actions - uses: actions/checkout@v4 - - - name: Get stable flutter - uses: subosito/flutter-action@v2 - with: - channel: "stable" - - - name: Fetch packages and generate assets - uses: ./.github/actions/generate-assets - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Test unit_test (unix) - id: unit_tests - continue-on-error: false - timeout-minutes: 15 - run: | - cd packages - for package in */; do - echo "Running tests for $package" - cd "$package" - if [ -d "test" ]; then - flutter clean - rm -rf build/* - rm -rf web/src/mm2/* - rm -rf web/src/kdfi/* - rm -rf web/dist/* - - flutter test - else - echo "No test directory found in $package" - fi - cd .. - done diff --git a/.github/workflows/validate-code-guidelines.yml b/.github/workflows/validate-code-guidelines.yml deleted file mode 100644 index fd9cf81..0000000 --- a/.github/workflows/validate-code-guidelines.yml +++ /dev/null @@ -1,39 +0,0 @@ -# Rule for running static analysis and code formatting checks on all PRs -# Runs static analysis and code formatting checks on all PRs to ensure the codebase is clean and consistent -name: Validate Packages Code Guidelines -run-name: ${{ github.actor }} is validating code guidelines 🚀 - -on: - pull_request: - branches: - - "*" - paths: - - "packages/**" - -jobs: - validate_packages_code_guidelines: - runs-on: macos-latest - - steps: - - name: Setup GH Actions - uses: actions/checkout@v4 - - - name: Get stable flutter - uses: subosito/flutter-action@v2 - with: - channel: "stable" - - - name: Fetch packages and generate assets - uses: ./.github/actions/generate-assets - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Validate dart code - run: | - cd packages - for package in */; do - echo "Analyzing package: $package" - cd "$package" - flutter analyze - cd .. - done