simplify fetching changed files
This commit is contained in:
parent
da31232cdf
commit
03d4d63ab5
22
.github/workflows/build.yml
vendored
22
.github/workflows/build.yml
vendored
@ -27,9 +27,9 @@ jobs:
|
|||||||
boards-aarch: ${{ steps.set-matrix.outputs.boards-aarch }}
|
boards-aarch: ${{ steps.set-matrix.outputs.boards-aarch }}
|
||||||
steps:
|
steps:
|
||||||
- name: Dump GitHub context
|
- name: Dump GitHub context
|
||||||
|
run: echo "$GITHUB_CONTEXT"
|
||||||
env:
|
env:
|
||||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||||
run: echo "$GITHUB_CONTEXT"
|
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: false
|
submodules: false
|
||||||
@ -135,20 +135,26 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
EXCLUDE_COMMIT: ${{ github.event.after }}
|
EXCLUDE_COMMIT: ${{ github.event.after }}
|
||||||
run: python3 -u ci_changes_per_commit.py
|
run: python3 -u ci_changes_per_commit.py
|
||||||
|
- name: Deepen and convert depth to sha
|
||||||
|
id: deepen-and-convert-depth-to-sha
|
||||||
|
run: |
|
||||||
|
DEEPEN=$((DEPTH - $(git rev-list HEAD --count))) && if((DEEPEN > 0)); then git fetch --no-tags --recurse-submodules=no --deepen=$DEEPEN; fi
|
||||||
|
echo "commit=$(git rev-list $GITHUB_SHA --skip=$((DEPTH + 1)) --max-count=1)" >> $GITHUB_OUTPUT
|
||||||
|
env:
|
||||||
|
DEPTH: ${{ steps.get-last-commit-with-checks.outputs.commit_depth || github.event.pull_request.commits }}
|
||||||
- name: Get changes
|
- name: Get changes
|
||||||
id: get-changes
|
id: get-changes
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
uses: tj-actions/changed-files@v34
|
run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT
|
||||||
with:
|
env:
|
||||||
json: true
|
BASE_SHA: ${{ steps.deepen-and-convert-depth-to-sha.outputs.commit }}
|
||||||
sha: ${{ steps.get-last-commit-with-checks.outputs.commit && github.event.after }}
|
HEAD_SHA: ${{ github.event.after }}
|
||||||
base_sha: ${{ steps.get-last-commit-with-checks.outputs.commit }}
|
|
||||||
- name: Set matrix
|
- name: Set matrix
|
||||||
id: set-matrix
|
id: set-matrix
|
||||||
working-directory: tools
|
working-directory: tools
|
||||||
env:
|
env:
|
||||||
CHANGED_FILES: ${{ steps.get-changes.outputs.all_changed_and_modified_files }}
|
CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }}
|
||||||
LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.checkruns }}
|
LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }}
|
||||||
run: python3 -u ci_set_matrix.py
|
run: python3 -u ci_set_matrix.py
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ query ($owner: String!, $name: String!, $pullNumber: Int!, $commitsPerPage: Int!
|
|||||||
}
|
}
|
||||||
nodes {
|
nodes {
|
||||||
commit {
|
commit {
|
||||||
checkSuites(first: 3) {
|
checkSuites(first: 100) {
|
||||||
nodes {
|
nodes {
|
||||||
conclusion
|
conclusion
|
||||||
workflowRun {
|
workflowRun {
|
||||||
@ -141,26 +141,29 @@ def set_output(name, value):
|
|||||||
print(f"Would set GitHub actions output {name} to '{value}'")
|
print(f"Would set GitHub actions output {name} to '{value}'")
|
||||||
|
|
||||||
|
|
||||||
def get_commit_and_check_suite(query_commits):
|
def get_commit_depth_and_check_suite(query_commits):
|
||||||
commits = query_commits.fetch()["data"]["repository"]["pullRequest"]["commits"]
|
while True:
|
||||||
|
commits = query_commits.fetch()["data"]["repository"]["pullRequest"]["commits"]
|
||||||
|
|
||||||
if commits["totalCount"] > 0:
|
if commits["totalCount"] > 0:
|
||||||
for commit in reversed(commits["nodes"]):
|
nodes = commits["nodes"]
|
||||||
commit = commit["commit"]
|
nodes.reverse()
|
||||||
commit_sha = commit["oid"]
|
if nodes[0]["commit"]["oid"] == os.environ["EXCLUDE_COMMIT"]:
|
||||||
if commit_sha == os.environ["EXCLUDE_COMMIT"]:
|
nodes.pop(0)
|
||||||
continue
|
for index, commit in enumerate(nodes):
|
||||||
check_suites = commit["checkSuites"]
|
commit = commit["commit"]
|
||||||
if check_suites["totalCount"] > 0:
|
commit_sha = commit["oid"]
|
||||||
for check_suite in check_suites["nodes"]:
|
check_suites = commit["checkSuites"]
|
||||||
if check_suite["workflowRun"]["workflow"]["name"] == "Build CI":
|
if check_suites["totalCount"] > 0:
|
||||||
return [
|
for check_suite in check_suites["nodes"]:
|
||||||
commit_sha,
|
if check_suite["workflowRun"]["workflow"]["name"] == "Build CI":
|
||||||
check_suite["id"] if check_suite["conclusion"] != "SUCCESS" else None,
|
return [
|
||||||
]
|
{"sha": commit_sha, "depth": index + 1},
|
||||||
else:
|
check_suite["id"] if check_suite["conclusion"] != "SUCCESS" else None,
|
||||||
if query_commits.paginate(commits["pageInfo"], "beforeCommit"):
|
]
|
||||||
return get_commit_and_check_suite(query_commits)
|
else:
|
||||||
|
if not query_commits.paginate(commits["pageInfo"], "beforeCommit"):
|
||||||
|
break
|
||||||
|
|
||||||
return [None, None]
|
return [None, None]
|
||||||
|
|
||||||
@ -201,19 +204,24 @@ def get_bad_check_runs(query_check_runs):
|
|||||||
return bad_runs_by_matrix
|
return bad_runs_by_matrix
|
||||||
|
|
||||||
|
|
||||||
|
def set_commit(commit):
|
||||||
|
set_output("commit_sha", commit["sha"])
|
||||||
|
set_output("commit_depth", commit["depth"])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
query_commits = Query(QUERY_COMMITS, query_variables_commits, headers)
|
query_commits = Query(QUERY_COMMITS, query_variables_commits, headers)
|
||||||
query_commits.variables["owner"], query_commits.variables["name"] = os.environ["REPO"].split(
|
query_commits.variables["owner"], query_commits.variables["name"] = os.environ["REPO"].split(
|
||||||
"/"
|
"/"
|
||||||
)
|
)
|
||||||
|
|
||||||
commit, check_suite = get_commit_and_check_suite(query_commits)
|
commit, check_suite = get_commit_depth_and_check_suite(query_commits)
|
||||||
|
|
||||||
if check_suite is None:
|
if check_suite is None:
|
||||||
if commit is None:
|
if commit is None:
|
||||||
print("Abort: No check suite found")
|
print("Abort: No check suite found")
|
||||||
else:
|
else:
|
||||||
set_output("commit", commit)
|
set_commit(commit)
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
query_check_runs = Query(QUERY_CHECK_RUNS, query_variables_check_runs, headers)
|
query_check_runs = Query(QUERY_CHECK_RUNS, query_variables_check_runs, headers)
|
||||||
@ -225,7 +233,7 @@ def main():
|
|||||||
print("Abort: No check runs found")
|
print("Abort: No check runs found")
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
set_output("commit", commit)
|
set_commit(commit)
|
||||||
set_output("check_runs", json.dumps(check_runs))
|
set_output("check_runs", json.dumps(check_runs))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user