From 9f81330c73437d0d0ddead3cb2a9bd850aa7c72a Mon Sep 17 00:00:00 2001 From: Cameron Beneteau Date: Mon, 2 Dec 2024 06:16:10 -0500 Subject: [PATCH] Refactor python script and update workflow --- .github/workflows/test-self-hosted.yml | 5 +++++ scripts/actions/modified_projects.py | 28 +++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-self-hosted.yml b/.github/workflows/test-self-hosted.yml index eaae8fb9a..149c19014 100644 --- a/.github/workflows/test-self-hosted.yml +++ b/.github/workflows/test-self-hosted.yml @@ -2,6 +2,11 @@ name: Test Self-Hosted Runner on: push: + pull_request: + types: + - opened + - reopened + - synchronize workflow_dispatch: jobs: diff --git a/scripts/actions/modified_projects.py b/scripts/actions/modified_projects.py index 590e78e68..903118f5d 100644 --- a/scripts/actions/modified_projects.py +++ b/scripts/actions/modified_projects.py @@ -6,20 +6,30 @@ import subprocess import sys -def get_modified_projects(projects_dir, base_branch): +def get_all_projects(projects_dir): + all_projects = set() + + for root, dirs, _ in os.walk(projects_dir): + if "platforms" in dirs: + project_path = os.path.relpath(root, projects_dir) + all_projects.add(project_path) + + return list(all_projects) + +def get_modified_projects(projects_dir, projects, base_branch): modified_files = subprocess.check_output( ["git", "diff", "--name-only", base_branch, '--', projects_dir], universal_newlines=True ).splitlines() - print(f"Modified files: {modified_files}") modified_projects = set() for modified_file in modified_files: - project_name = os.path.relpath(os.path.dirname(modified_file), projects_dir) - modified_projects.add(project_name) + for project in projects: + if project in modified_file: + modified_projects.add(project) + break modified_projects = list(modified_projects) - print(f"Modified projects: {modified_projects}") return modified_projects def get_project_platforms(projects_dir, project_dir): @@ -36,7 +46,7 @@ def filter_platforms(platforms, remove_list): if __name__ == "__main__": if len(sys.argv) < 2: - print("Usage: python modified_projects.py ") + print("Usage: python modified_projects.py ") sys.exit(1) projects_dir = "firmware/projects" @@ -46,8 +56,12 @@ def filter_platforms(platforms, remove_list): print(f"Error: {projects_dir} is not a directory") sys.exit(1) - modified_projects = get_modified_projects(projects_dir, base_branch) + projects = get_all_projects(projects_dir) + print(f"Projects: {projects}") + + modified_projects = get_modified_projects(projects_dir, projects, base_branch) modified_projects = filter_projects(modified_projects, ["debug"]) + print(f"Modified projects: {modified_projects}") matrix = [] for project in modified_projects: