Skip to content

Commit a6400fb

Browse files
committed
use intersection of changes per commit and merge ref
1 parent b6a7613 commit a6400fb

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,11 @@ jobs:
8080
run: git cat-file -e $SHA && echo "BASE_SHA=$SHA" >> $GITHUB_ENV || true
8181
env:
8282
SHA: ${{ github.event.before }}
83-
- name: Get changes
84-
id: get-changes
85-
if: env.BASE_SHA && env.HEAD_SHA
86-
run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT
8783
- name: Set matrix
8884
id: set-matrix
8985
run: python3 -u ci_set_matrix.py
9086
working-directory: tools
9187
env:
92-
CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }}
9388
LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }}
9489

9590
tests:

tools/ci_set_matrix.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,43 @@
6868
"tools/",
6969
]
7070

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+
7184
if len(sys.argv) > 1:
7285
print("Using files list on commandline")
7386
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")))
7592
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 "[]")
8395

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)
90108

91109

92110
def set_output(name: str, value):

0 commit comments

Comments
 (0)