diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 6dddc201b..376dc3a70 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -7,6 +7,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 2 - uses: subosito/flutter-action@v1 with: flutter-version: "2.2.1" @@ -18,6 +20,8 @@ jobs: done - name: Verify formatting run: flutter format --set-exit-if-changed packages + - name: Analyze the plugin's Dart code + run: tools/run_command.py analyze --run-on-changed-packages --base-sha $(git rev-parse HEAD^) clang: runs-on: ubuntu-latest steps: diff --git a/tools/commands/analyze_plugins.py b/tools/commands/analyze_plugins.py new file mode 100644 index 000000000..c8a9062d5 --- /dev/null +++ b/tools/commands/analyze_plugins.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import subprocess +import sys +import os +import commands.command_utils as command_utils + + +def parse_args(args): + parser = command_utils.get_options_parser( + plugins=True, exclude=True, run_on_changed_packages=True, base_sha=True, command='analyze') + return parser.parse_args(args) + + +def _run_analyze_plugins(plugin_dir): + completed_process = subprocess.run('flutter analyze --pub', shell=True, cwd=plugin_dir) + if completed_process.returncode == 0: + return True + else: + return False + + +def run_analyze_plugins(argv): + args = parse_args(argv) + packages_dir = command_utils.get_package_dir() + target_plugins, _ = command_utils.get_target_plugins( + packages_dir, plugins=args.plugins, exclude=args.exclude, run_on_changed_packages=args.run_on_changed_packages, + base_sha=args.base_sha) + results = [] + for plugin in target_plugins: + result = _run_analyze_plugins(os.path.join(packages_dir, plugin)) + results.append(result) + + if False not in results: + exit(0) + else: + exit(1) diff --git a/tools/commands/build_example.py b/tools/commands/build_example.py index 46a571b82..d91fe7175 100755 --- a/tools/commands/build_example.py +++ b/tools/commands/build_example.py @@ -12,9 +12,8 @@ def parse_args(args): return parser.parse_args(args) -def _build_examples(plugin): - name = os.path.basename(plugin) - example_dir = os.path.join(plugin, 'example') +def _build_examples(plugin_dir): + example_dir = os.path.join(plugin_dir, 'example') subprocess.run('flutter-tizen pub get', shell=True, cwd=example_dir) completed_process = subprocess.run('flutter-tizen build tpk --device-profile wearable -v', diff --git a/tools/run_command.py b/tools/run_command.py index c893268ca..640838cf2 100755 --- a/tools/run_command.py +++ b/tools/run_command.py @@ -6,6 +6,7 @@ from commands import integration_test from commands import build_example from commands import print_plugins +from commands import analyze_plugins # Check tidy @@ -28,11 +29,17 @@ def run_print_plugins(arv): print_plugins.run_print_plugins(arv) +# Analyze plugin packages +def run_analyze_plugins(arv): + analyze_plugins.run_analyze_plugins(arv) + + commands = {} commands['tidy'] = {'func': run_check_tidy, 'info': 'Check and update format for C++ files'} commands['test'] = {'func': run_integration_test, 'info': 'Run integration test'} commands['build'] = {'func': run_build_examples, 'info': 'Build examples of plugin'} commands['plugins'] = {'func': run_print_plugins, 'info': 'Print plugins list'} +commands['analyze'] = {'func': run_analyze_plugins, 'info': 'Analyze the plugin\'s Dart code'} def print_usage():