From 500c54ec22072707e381b23461d827ae396591d1 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Mon, 13 Sep 2021 16:58:36 +0900 Subject: [PATCH 1/2] Add an action to analyze packages * Add 'analyze' command Signed-off-by: Boram Bae --- .github/workflows/format.yml | 4 ++++ tools/commands/analyze_plugins.py | 38 +++++++++++++++++++++++++++++++ tools/commands/build_example.py | 5 ++-- tools/run_command.py | 7 ++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tools/commands/analyze_plugins.py 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..6b65569d9 --- /dev/null +++ b/tools/commands/analyze_plugins.py @@ -0,0 +1,38 @@ +#!/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): + subprocess.run('flutter pub get', shell=True, cwd=plugin_dir) + completed_process = subprocess.run('flutter analyze', 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(): From ad0005a6824ff97ff6a0c1bf8a362e37b24b835d Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Tue, 14 Sep 2021 16:53:46 +0900 Subject: [PATCH 2/2] test --- tools/commands/analyze_plugins.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/commands/analyze_plugins.py b/tools/commands/analyze_plugins.py index 6b65569d9..c8a9062d5 100644 --- a/tools/commands/analyze_plugins.py +++ b/tools/commands/analyze_plugins.py @@ -13,8 +13,7 @@ def parse_args(args): def _run_analyze_plugins(plugin_dir): - subprocess.run('flutter pub get', shell=True, cwd=plugin_dir) - completed_process = subprocess.run('flutter analyze', shell=True, cwd=plugin_dir) + completed_process = subprocess.run('flutter analyze --pub', shell=True, cwd=plugin_dir) if completed_process.returncode == 0: return True else: