|
68 | 68 | "tools/",
|
69 | 69 | ]
|
70 | 70 |
|
| 71 | + |
| 72 | +def git_diff(pattern: str): |
| 73 | + return ( |
| 74 | + subprocess.run( |
| 75 | + f"git diff {pattern} --name-only", |
| 76 | + capture_output=True, |
| 77 | + shell=True, |
| 78 | + ) |
| 79 | + .stdout.decode("utf-8") |
| 80 | + .split("\n")[:-1] |
| 81 | + ) |
| 82 | + |
| 83 | + |
71 | 84 | if len(sys.argv) > 1:
|
72 | 85 | print("Using files list on commandline")
|
73 | 86 | changed_files = sys.argv[1:]
|
74 |
| - last_failed_jobs = {} |
| 87 | +elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"): |
| 88 | + print("Using files list by computing diff") |
| 89 | + changed_files = git_diff("$BASE_SHA...$HEAD_SHA") |
| 90 | + if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": |
| 91 | + changed_files = list(set(changed_files).intersection(git_diff("$HEAD_SHA~...$HEAD_SHA"))) |
75 | 92 | else:
|
76 |
| - c = os.environ["CHANGED_FILES"] |
77 |
| - if c == "": |
78 |
| - print("CHANGED_FILES is in environment, but value is empty") |
79 |
| - changed_files = [] |
80 |
| - else: |
81 |
| - print("Using files list in CHANGED_FILES") |
82 |
| - changed_files = json.loads(c.replace("\\", "")) |
| 93 | + print("Using files list in CHANGED_FILES") |
| 94 | + changed_files = json.loads(os.environ.get("CHANGED_FILES") or "[]") |
83 | 95 |
|
84 |
| - j = os.environ["LAST_FAILED_JOBS"] |
85 |
| - if j == "": |
86 |
| - print("LAST_FAILED_JOBS is in environment, but value is empty") |
87 |
| - last_failed_jobs = {} |
88 |
| - else: |
89 |
| - last_failed_jobs = json.loads(j) |
| 96 | +print("Using jobs list in LAST_FAILED_JOBS") |
| 97 | +last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}") |
| 98 | + |
| 99 | + |
| 100 | +def print_enclosed(title, content): |
| 101 | + print("::group::" + title) |
| 102 | + print(content) |
| 103 | + print("::endgroup::") |
| 104 | + |
| 105 | + |
| 106 | +print_enclosed("LOG: changed_files", changed_files) |
| 107 | +print_enclosed("LOG: last_failed_jobs", last_failed_jobs) |
90 | 108 |
|
91 | 109 |
|
92 | 110 | def set_output(name: str, value):
|
|
0 commit comments