use intersection of changes per commit and merge ref

This commit is contained in:
MicroDev 2023-03-11 00:14:36 +05:30
parent b6a7613350
commit a6400fb08a
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
2 changed files with 32 additions and 19 deletions

View File

@ -80,16 +80,11 @@ jobs:
run: git cat-file -e $SHA && echo "BASE_SHA=$SHA" >> $GITHUB_ENV || true
env:
SHA: ${{ github.event.before }}
- name: Get changes
id: get-changes
if: env.BASE_SHA && env.HEAD_SHA
run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT
- name: Set matrix
id: set-matrix
run: python3 -u ci_set_matrix.py
working-directory: tools
env:
CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }}
LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }}
tests:

View File

@ -68,25 +68,43 @@ PATTERN_WINDOWS = [
"tools/",
]
def git_diff(pattern: str):
return (
subprocess.run(
f"git diff {pattern} --name-only",
capture_output=True,
shell=True,
)
.stdout.decode("utf-8")
.split("\n")[:-1]
)
if len(sys.argv) > 1:
print("Using files list on commandline")
changed_files = sys.argv[1:]
last_failed_jobs = {}
elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"):
print("Using files list by computing diff")
changed_files = git_diff("$BASE_SHA...$HEAD_SHA")
if os.environ.get("GITHUB_EVENT_NAME") == "pull_request":
changed_files = list(set(changed_files).intersection(git_diff("$HEAD_SHA~...$HEAD_SHA")))
else:
c = os.environ["CHANGED_FILES"]
if c == "":
print("CHANGED_FILES is in environment, but value is empty")
changed_files = []
else:
print("Using files list in CHANGED_FILES")
changed_files = json.loads(c.replace("\\", ""))
print("Using files list in CHANGED_FILES")
changed_files = json.loads(os.environ.get("CHANGED_FILES") or "[]")
j = os.environ["LAST_FAILED_JOBS"]
if j == "":
print("LAST_FAILED_JOBS is in environment, but value is empty")
last_failed_jobs = {}
else:
last_failed_jobs = json.loads(j)
print("Using jobs list in LAST_FAILED_JOBS")
last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}")
def print_enclosed(title, content):
print("::group::" + title)
print(content)
print("::endgroup::")
print_enclosed("LOG: changed_files", changed_files)
print_enclosed("LOG: last_failed_jobs", last_failed_jobs)
def set_output(name: str, value):