Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQube QA GitHub jobs #8668

Merged
merged 11 commits into from
Dec 30, 2021
Prev Previous commit
Next Next commit
Return json as ci_detect_changed_modules output.
  • Loading branch information
htrueman committed Dec 30, 2021
commit f7aa14996585fa773d3d399ca568ebef9c6e8036
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
import json
import os
import sys
from typing import Dict, List
Expand Down Expand Up @@ -80,8 +81,9 @@ def build_static_checkers_reports(modules: list) -> int:


def main() -> int:
print("Changed modules: ", sys.argv[1:])
return build_static_checkers_reports(sys.argv[1:])
changed_python_module_paths = [module["dir"] for module in json.loads(sys.argv[1]) if module["lang"] == "py"]
print("Changed python modules: ", changed_python_module_paths)
return build_static_checkers_reports(changed_python_module_paths)


if __name__ == "__main__":
Expand Down
21 changes: 13 additions & 8 deletions tools/ci_static_check_reports/ci_detect_changed_modules/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
import json
import os
import sys
from typing import List, Set
from typing import Dict, List, Set

# Filenames used to detect whether the dir is a module
LANGUAGE_MODULE_ID_FILE = {
Expand All @@ -12,29 +13,33 @@
}


def find_base_path(path: str, modules: Set[str], lookup_file: str = None) -> None:
def find_base_path(path: str, modules: List[Dict[str, str]], unique_modules: Set[str], file_ext: str = "", lookup_file: str = None) -> None:
filename, file_extension = os.path.splitext(path)
lookup_file = lookup_file or LANGUAGE_MODULE_ID_FILE.get(file_extension)

dir_path = os.path.dirname(filename)
if dir_path and os.path.exists(dir_path):
is_module_root = lookup_file in os.listdir(dir_path)
if is_module_root:
modules.add(dir_path)
if dir_path not in unique_modules:
modules.append({"dir": dir_path, "lang": file_ext[1:]})
unique_modules.add(dir_path)
else:
find_base_path(dir_path, modules, lookup_file=lookup_file)
find_base_path(dir_path, modules, unique_modules, file_ext=file_extension, lookup_file=lookup_file)


def list_changed_modules(changed_files: List[str]) -> Set[str]:
modules: set = set()
def list_changed_modules(changed_files: List[str]) -> List[Dict[str, str]]:
modules: List[Dict[str, str]] = []
unique_modules: set = set()
for file_path in changed_files:
find_base_path(file_path, modules)
_, file_extension = os.path.splitext(file_path)
find_base_path(file_path, modules, file_ext=file_extension, unique_modules=unique_modules)
return modules


def main() -> int:
changed_modules = list_changed_modules(sys.argv[1:])
print(" ".join(changed_modules))
print(json.dumps(changed_modules))
return 0


Expand Down